Package org.apache.bookkeeper.client
Class ZoneawareEnsemblePlacementPolicyImpl
java.lang.Object
org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
org.apache.bookkeeper.client.ZoneawareEnsemblePlacementPolicyImpl
- All Implemented Interfaces:
EnsemblePlacementPolicy,ITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Direct Known Subclasses:
ZoneawareEnsemblePlacementPolicy
Simple zoneaware ensemble placement policy.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classZone and UpgradeDomain pair of a node.Nested classes/interfaces inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
TopologyAwareEnsemblePlacementPolicy.DefaultResolver, TopologyAwareEnsemblePlacementPolicy.DNSResolverDecorator, TopologyAwareEnsemblePlacementPolicy.EnsembleForReplacementWithNoConstraints, TopologyAwareEnsemblePlacementPolicy.RRTopologyAwareCoverageEnsemble, TopologyAwareEnsemblePlacementPolicy.TruePredicateNested classes/interfaces inherited from interface org.apache.bookkeeper.client.EnsemblePlacementPolicy
EnsemblePlacementPolicy.PlacementPolicyAdherence, EnsemblePlacementPolicy.PlacementResult<T>Nested classes/interfaces inherited from interface org.apache.bookkeeper.client.ITopologyAwareEnsemblePlacementPolicy
ITopologyAwareEnsemblePlacementPolicy.Ensemble<T extends Node>, ITopologyAwareEnsemblePlacementPolicy.Predicate<T extends Node> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected booleanprotected Counter(package private) static final org.slf4j.Loggerprotected intprotected intprotected BookieNodeprotected Stringprotected booleanprotected intprotected intprotected StatsLoggerprotected io.netty.util.HashedWheelTimerstatic final StringFields inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
bookieAddressResolver, bookieInfoMap, bookiesJoinedCounter, bookiesLeftCounter, dnsResolver, historyBookies, isWeighted, knownBookies, readOnlyBookies, REPP_DNS_RESOLVER_CLASS, rwLock, topology, weightedSelection -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDefaultFaultDomainBookies(Set<BookieId> excludeBookies) booleanareAckedBookiesAdheringToPlacementPolicy(Set<BookieId> ackedBookies, int writeQuorumSize, int ackQuorumSize) Returns true if the bookies that have acknowledged a write adhere to the minimum fault domains as defined in the placement policy in use.initialize(ClientConfiguration conf, Optional<DNSToSwitchMapping> optionalDnsResolver, io.netty.util.HashedWheelTimer timer, FeatureProvider featureProvider, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver) Initialize the policy.isEnsembleAdheringToPlacementPolicy(List<BookieId> ensembleList, int writeQuorumSize, int ackQuorumSize) returns AdherenceLevel if the Ensemble is strictly/softly/fails adhering to placement policy, like in the case of RackawareEnsemblePlacementPolicy, bookies in the writeset are from 'minNumRacksPerWriteQuorum' number of racks.newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, Set<BookieId> excludeBookies) Choose numBookies bookies for ensemble.newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Set<BookieId> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> parentEnsemble, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> parentPredicate) Create an ensemble with parent ensemble.voidregisterSlowBookie(BookieId bookieSocketAddress, long entryId) Register a bookie as slow so that it is tried after available and read-only bookies.reorderReadLACSequence(List<BookieId> ensemble, BookiesHealthInfo bookiesHealthInfo, DistributionSchedule.WriteSet writeSet) Reorder the read last add confirmed sequence of a given write quorum writeSet.reorderReadSequence(List<BookieId> ensemble, BookiesHealthInfo bookiesHealthInfo, DistributionSchedule.WriteSet writeSet) Reorder the read sequence of a given write quorum writeSet.replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, List<BookieId> currentEnsemble, BookieId bookieToReplace, Set<BookieId> excludeBookies) Choose a new bookie to replace bookieToReplace.selectFromNetworkLocation(String networkLoc, Set<String> excludeRacks, Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom) Select a node from networkLoc rack excluding excludeBookies.selectFromNetworkLocation(String networkLoc, Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom) Select a node from a given network location.selectFromNetworkLocation(Set<String> excludeRacks, Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom) Select a node from cluster excluding excludeBookies and bookie nodes of excludeRacks.voidUninitialize the policy.withDefaultFaultDomain(String defaultFaultDomain) Methods inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
convertBookiesToNodes, convertBookieToNode, createBookieNode, createDummyLocalBookieNode, differBetweenBookies, getDefaultRack, getNetworkLocations, handleBookiesThatJoined, handleBookiesThatLeft, onBookieRackChange, onClusterChanged, resolveNetworkLocation, shuffleWithMask, updateBookieInfoMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.bookkeeper.client.EnsemblePlacementPolicy
getStickyReadBookieIndex, replaceToAdherePlacementPolicy
-
Field Details
-
LOG
static final org.slf4j.Logger LOG -
UNKNOWN_ZONE
- See Also:
-
unresolvedNodeLocation
-
statsLogger
-
slowBookies
-
myNode
-
myZone
-
reorderReadsRandom
protected boolean reorderReadsRandom -
stabilizePeriodSeconds
protected int stabilizePeriodSeconds -
reorderThresholdPendingRequests
protected int reorderThresholdPendingRequests -
maxWeightMultiple
protected int maxWeightMultiple -
minNumZonesPerWriteQuorum
protected int minNumZonesPerWriteQuorum -
desiredNumZonesPerWriteQuorum
protected int desiredNumZonesPerWriteQuorum -
enforceStrictZoneawarePlacement
protected boolean enforceStrictZoneawarePlacement -
timer
protected io.netty.util.HashedWheelTimer timer -
address2NodePlacement
protected final ConcurrentMap<BookieId,ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation> address2NodePlacement -
failedToResolveNetworkLocationCounter
-
numWritableBookiesInDefaultFaultDomain
-
-
Constructor Details
-
ZoneawareEnsemblePlacementPolicyImpl
ZoneawareEnsemblePlacementPolicyImpl()
-
-
Method Details
-
getZoneAwareNodeLocation
protected ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation getZoneAwareNodeLocation(BookieId addr) -
getZoneAwareNodeLocation
protected ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation getZoneAwareNodeLocation(BookieNode node) -
initialize
public EnsemblePlacementPolicy initialize(ClientConfiguration conf, Optional<DNSToSwitchMapping> optionalDnsResolver, io.netty.util.HashedWheelTimer timer, FeatureProvider featureProvider, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver) Description copied from interface:EnsemblePlacementPolicyInitialize the policy.- Parameters:
conf- client configurationoptionalDnsResolver- dns resolvertimer- timerfeatureProvider- feature providerstatsLogger- stats logger
-
withDefaultFaultDomain
-
getDefaultFaultDomain
-
newEnsemble
public EnsemblePlacementPolicy.PlacementResult<List<BookieId>> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Set<BookieId> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> parentEnsemble, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> parentPredicate) throws BKException.BKNotEnoughBookiesException Description copied from interface:ITopologyAwareEnsemblePlacementPolicyCreate an ensemble with parent ensemble.- Parameters:
ensembleSize- ensemble sizewriteQuorumSize- write quorum sizeackQuorumSize- ack quorum sizeexcludeBookies- exclude bookiesparentEnsemble- parent ensemble- Returns:
- list of bookies forming the ensemble
- Throws:
BKException.BKNotEnoughBookiesException
-
selectFromNetworkLocation
public BookieNode selectFromNetworkLocation(String networkLoc, Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom) throws BKException.BKNotEnoughBookiesException Description copied from interface:ITopologyAwareEnsemblePlacementPolicySelect a node from a given network location.- Parameters:
networkLoc- network locationexcludeBookies- exclude bookies setpredicate- predicate to applyensemble- ensemblefallbackToRandom- fallbackToRandom- Returns:
- the selected bookie.
- Throws:
BKException.BKNotEnoughBookiesException
-
selectFromNetworkLocation
public BookieNode selectFromNetworkLocation(Set<String> excludeRacks, Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom) throws BKException.BKNotEnoughBookiesException Description copied from interface:ITopologyAwareEnsemblePlacementPolicySelect a node from cluster excluding excludeBookies and bookie nodes of excludeRacks. If there isn't a BookieNode excluding those racks and nodes, then if fallbackToRandom is set to true then pick a random node from cluster just excluding excludeBookies.- Returns:
- Throws:
BKException.BKNotEnoughBookiesException
-
selectFromNetworkLocation
public BookieNode selectFromNetworkLocation(String networkLoc, Set<String> excludeRacks, Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom) throws BKException.BKNotEnoughBookiesException Description copied from interface:ITopologyAwareEnsemblePlacementPolicySelect a node from networkLoc rack excluding excludeBookies. If there isn't any node in 'networkLoc', then it will try to get a node from cluster excluding excludeRacks and excludeBookies. If fallbackToRandom is set to true then it will get a random bookie from cluster excluding excludeBookies if it couldn't find a bookie- Returns:
- Throws:
BKException.BKNotEnoughBookiesException
-
uninitalize
public void uninitalize()Description copied from interface:EnsemblePlacementPolicyUninitialize the policy. -
newEnsemble
public EnsemblePlacementPolicy.PlacementResult<List<BookieId>> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, Set<BookieId> excludeBookies) throws BKException.BKNotEnoughBookiesExceptionDescription copied from interface:EnsemblePlacementPolicyChoose numBookies bookies for ensemble. If the count is more than the number of available nodes,BKException.BKNotEnoughBookiesExceptionis thrown.The implementation should respect to the replace settings. The size of the returned bookie list should be equal to the provide
ensembleSize.customMetadatais the same user defined data that user provides whenBookKeeper.createLedger(int, int, int, BookKeeper.DigestType, byte[], Map).If 'enforceMinNumRacksPerWriteQuorum' config is enabled then the bookies belonging to default faultzone (rack) will be excluded while selecting bookies.
- Parameters:
ensembleSize- Ensemble SizewriteQuorumSize- Write Quorum SizeackQuorumSize- the value of ackQuorumSize (added since 4.5)customMetadata- the value of customMetadata. it is the same user defined metadata that user provides inBookKeeper.createLedger(int, int, int, BookKeeper.DigestType, byte[])excludeBookies- Bookies that should not be considered as targets.- Returns:
- a placement result containing list of bookie addresses for the ensemble.
- Throws:
BKException.BKNotEnoughBookiesException- if not enough bookies available.
-
replaceBookie
public EnsemblePlacementPolicy.PlacementResult<BookieId> replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, List<BookieId> currentEnsemble, BookieId bookieToReplace, Set<BookieId> excludeBookies) throws BKException.BKNotEnoughBookiesExceptionDescription copied from interface:EnsemblePlacementPolicyChoose a new bookie to replace bookieToReplace. If no bookie available in the cluster,BKException.BKNotEnoughBookiesExceptionis thrown.If 'enforceMinNumRacksPerWriteQuorum' config is enabled then the bookies belonging to default faultzone (rack) will be excluded while selecting bookies.
- Parameters:
ensembleSize- the value of ensembleSizewriteQuorumSize- the value of writeQuorumSizeackQuorumSize- the value of ackQuorumSize (added since 4.5)customMetadata- the value of customMetadata. it is the same user defined metadata that user provides inBookKeeper.createLedger(int, int, int, BookKeeper.DigestType, byte[])currentEnsemble- the value of currentEnsemblebookieToReplace- bookie to replaceexcludeBookies- bookies that should not be considered as candidate.- Returns:
- a placement result containing the new bookie address.
- Throws:
BKException.BKNotEnoughBookiesException
-
addDefaultFaultDomainBookies
-
registerSlowBookie
Description copied from interface:EnsemblePlacementPolicyRegister a bookie as slow so that it is tried after available and read-only bookies.- Parameters:
bookieSocketAddress- Address of bookie hostentryId- Entry ID that caused a speculative timeout on the bookie.
-
reorderReadSequence
public DistributionSchedule.WriteSet reorderReadSequence(List<BookieId> ensemble, BookiesHealthInfo bookiesHealthInfo, DistributionSchedule.WriteSet writeSet) Description copied from interface:EnsemblePlacementPolicyReorder the read sequence of a given write quorum writeSet.- Specified by:
reorderReadSequencein interfaceEnsemblePlacementPolicy- Overrides:
reorderReadSequencein classTopologyAwareEnsemblePlacementPolicy- Parameters:
ensemble- Ensemble to read entries.bookiesHealthInfo- Health info for bookieswriteSet- Write quorum to read entries. This will be modified, rather than allocating a new WriteSet.- Returns:
- The read sequence. This will be the same object as the passed in writeSet.
-
reorderReadLACSequence
public DistributionSchedule.WriteSet reorderReadLACSequence(List<BookieId> ensemble, BookiesHealthInfo bookiesHealthInfo, DistributionSchedule.WriteSet writeSet) Description copied from interface:EnsemblePlacementPolicyReorder the read last add confirmed sequence of a given write quorum writeSet.- Specified by:
reorderReadLACSequencein interfaceEnsemblePlacementPolicy- Overrides:
reorderReadLACSequencein classTopologyAwareEnsemblePlacementPolicy- Parameters:
ensemble- Ensemble to read entries.bookiesHealthInfo- Health info for bookieswriteSet- Write quorum to read entries. This will be modified, rather than allocating a new WriteSet.- Returns:
- The read sequence. This will be the same object as the passed in writeSet.
-
isEnsembleAdheringToPlacementPolicy
public EnsemblePlacementPolicy.PlacementPolicyAdherence isEnsembleAdheringToPlacementPolicy(List<BookieId> ensembleList, int writeQuorumSize, int ackQuorumSize) Description copied from interface:EnsemblePlacementPolicyreturns AdherenceLevel if the Ensemble is strictly/softly/fails adhering to placement policy, like in the case of RackawareEnsemblePlacementPolicy, bookies in the writeset are from 'minNumRacksPerWriteQuorum' number of racks. And in the case of RegionawareEnsemblePlacementPolicy, check for minimumRegionsForDurability, reppRegionsToWrite, rack distribution within a region and other parameters of RegionAwareEnsemblePlacementPolicy. In ZoneAwareEnsemblePlacementPolicy if bookies in the writeset are from 'desiredNumOfZones' then it is considered as MEETS_STRICT if they are from 'minNumOfZones' then it is considered as MEETS_SOFT otherwise considered as FAIL.- Parameters:
ensembleList- list of BookieId of bookies in the ensemblewriteQuorumSize- writeQuorumSize of the ensembleackQuorumSize- ackQuorumSize of the ensemble- Returns:
-
areAckedBookiesAdheringToPlacementPolicy
public boolean areAckedBookiesAdheringToPlacementPolicy(Set<BookieId> ackedBookies, int writeQuorumSize, int ackQuorumSize) Description copied from interface:EnsemblePlacementPolicyReturns true if the bookies that have acknowledged a write adhere to the minimum fault domains as defined in the placement policy in use. Ex: In the case of RackawareEnsemblePlacementPolicy, bookies belong to at least 'minNumRacksPerWriteQuorum' number of racks.- Parameters:
ackedBookies- list of BookieId of bookies that have acknowledged a write.writeQuorumSize- writeQuorumSize of the ensembleackQuorumSize- ackQuorumSize of the ensemble- Returns:
-