Class RackawareEnsemblePlacementPolicy
- java.lang.Object
- 
- org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
- 
- org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImpl
- 
- org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy
 
 
 
- 
- All Implemented Interfaces:
- EnsemblePlacementPolicy,- ITopologyAwareEnsemblePlacementPolicy<BookieNode>
 - Direct Known Subclasses:
- RegionAwareEnsemblePlacementPolicy
 
 public class RackawareEnsemblePlacementPolicy extends RackawareEnsemblePlacementPolicyImpl implements ITopologyAwareEnsemblePlacementPolicy<BookieNode> A placement policy implementation use rack information for placing ensembles.- See Also:
- EnsemblePlacementPolicy
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicyTopologyAwareEnsemblePlacementPolicy.DefaultResolver, TopologyAwareEnsemblePlacementPolicy.DNSResolverDecorator, TopologyAwareEnsemblePlacementPolicy.EnsembleForReplacementWithNoConstraints, TopologyAwareEnsemblePlacementPolicy.RRTopologyAwareCoverageEnsemble, TopologyAwareEnsemblePlacementPolicy.TruePredicate
 - 
Nested classes/interfaces inherited from interface org.apache.bookkeeper.client.EnsemblePlacementPolicyEnsemblePlacementPolicy.PlacementPolicyAdherence, EnsemblePlacementPolicy.PlacementResult<T>
 - 
Nested classes/interfaces inherited from interface org.apache.bookkeeper.client.ITopologyAwareEnsemblePlacementPolicyITopologyAwareEnsemblePlacementPolicy.Ensemble<T extends Node>, ITopologyAwareEnsemblePlacementPolicy.Predicate<T extends Node>
 
- 
 - 
Field SummaryFields Modifier and Type Field Description (package private) RackawareEnsemblePlacementPolicyImplslave- 
Fields inherited from class org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImplenforceDurability, enforceMinNumRacksPerWriteQuorum, failedToResolveNetworkLocationCounter, ignoreLocalNodeInPlacementPolicy, LOCAL_FAIL_MASK, LOCAL_MASK, localNode, LOG, MASK_BITS, maxWeightMultiple, minNumRacksPerWriteQuorum, numWritableBookiesInDefaultRack, RACKNAME_DISTANCE_FROM_LEAVES, READ_ONLY_MASK, readReorderedCounter, REMOTE_FAIL_MASK, REMOTE_MASK, reorderReadsRandom, reorderThresholdPendingRequests, REPP_RANDOM_READ_REORDERING, SLOW_MASK, slowBookies, stabilizePeriodSeconds, statsLogger, timer, UNAVAIL_MASK
 - 
Fields inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicybookieAddressResolver, bookieInfoMap, bookiesJoinedCounter, bookiesLeftCounter, dnsResolver, isWeighted, knownBookies, readOnlyBookies, REPP_DNS_RESOLVER_CLASS, rwLock, topology, weightedSelection
 
- 
 - 
Constructor SummaryConstructors Constructor Description RackawareEnsemblePlacementPolicy()RackawareEnsemblePlacementPolicy(boolean enforceDurability)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidhandleBookiesThatJoined(java.util.Set<BookieId> joinedBookies)Handle bookies that joined.voidhandleBookiesThatLeft(java.util.Set<BookieId> leftBookies)Handle bookies that left.protected RackawareEnsemblePlacementPolicyinitialize(DNSToSwitchMapping dnsResolver, io.netty.util.HashedWheelTimer timer, boolean reorderReadsRandom, int stabilizePeriodSeconds, int reorderThresholdPendingRequests, boolean isWeighted, int maxWeightMultiple, int minNumRacksPerWriteQuorum, boolean enforceMinNumRacksPerWriteQuorum, boolean ignoreLocalNodeInPlacementPolicy, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver)Initialize the policy.EnsemblePlacementPolicy.PlacementResult<java.util.List<BookieId>>newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,byte[]> customMetadata, java.util.Set<BookieId> excludeBookies)Choose numBookies bookies for ensemble.EnsemblePlacementPolicy.PlacementResult<java.util.List<BookieId>>newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Set<BookieId> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> parentEnsemble, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> parentPredicate)Create an ensemble with parent ensemble.java.util.Set<BookieId>onClusterChanged(java.util.Set<BookieId> writableBookies, java.util.Set<BookieId> readOnlyBookies)A consistent view of the cluster (what bookies are available as writable, what bookies are available as readonly) is updated when any changes happen in the cluster.DistributionSchedule.WriteSetreorderReadLACSequence(java.util.List<BookieId> ensemble, BookiesHealthInfo bookiesHealthInfo, DistributionSchedule.WriteSet writeSet)Reorder the read last add confirmed sequence of a given write quorum writeSet.DistributionSchedule.WriteSetreorderReadSequence(java.util.List<BookieId> ensemble, BookiesHealthInfo bookiesHealthInfo, DistributionSchedule.WriteSet writeSet)Reorder the read sequence of a given write quorum writeSet.EnsemblePlacementPolicy.PlacementResult<BookieId>replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,byte[]> customMetadata, java.util.List<BookieId> currentEnsemble, BookieId bookieToReplace, java.util.Set<BookieId> excludeBookies)Choose a new bookie to replace bookieToReplace.BookieNodeselectFromNetworkLocation(java.lang.String networkLoc, java.util.Set<java.lang.String> excludeRacks, java.util.Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom)Select a node from networkLoc rack excluding excludeBookies.BookieNodeselectFromNetworkLocation(java.lang.String networkLoc, java.util.Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom)Select a node from a given network location.BookieNodeselectFromNetworkLocation(java.util.Set<java.lang.String> excludeRacks, java.util.Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom)It randomly selects aBookieNodethat is not on the excludeRacks set, excluding the nodes in excludeBookies set.voiduninitalize()Uninitialize the policy.- 
Methods inherited from class org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImpladdDefaultRackBookiesIfMinNumRacksIsEnforced, areAckedBookiesAdheringToPlacementPolicy, getDefaultRack, initialize, isEnsembleAdheringToPlacementPolicy, newEnsembleInternal, registerSlowBookie, reorderReadSequenceWithRegion, selectRandom, selectRandomFromRack, selectRandomInternal, withDefaultRack
 - 
Methods inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicyconvertBookiesToNodes, createBookieNode, createDummyLocalBookieNode, getNetworkLocations, onBookieRackChange, resolveNetworkLocation, shuffleWithMask, updateBookieInfo
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.apache.bookkeeper.client.EnsemblePlacementPolicyareAckedBookiesAdheringToPlacementPolicy, getStickyReadBookieIndex, initialize, isEnsembleAdheringToPlacementPolicy, registerSlowBookie, updateBookieInfo
 - 
Methods inherited from interface org.apache.bookkeeper.client.ITopologyAwareEnsemblePlacementPolicyonBookieRackChange
 
- 
 
- 
- 
- 
Field Detail- 
slaveRackawareEnsemblePlacementPolicyImpl slave 
 
- 
 - 
Method Detail- 
initializeprotected RackawareEnsemblePlacementPolicy initialize(DNSToSwitchMapping dnsResolver, io.netty.util.HashedWheelTimer timer, boolean reorderReadsRandom, int stabilizePeriodSeconds, int reorderThresholdPendingRequests, boolean isWeighted, int maxWeightMultiple, int minNumRacksPerWriteQuorum, boolean enforceMinNumRacksPerWriteQuorum, boolean ignoreLocalNodeInPlacementPolicy, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver) Description copied from class:RackawareEnsemblePlacementPolicyImplInitialize the policy.- Overrides:
- initializein class- RackawareEnsemblePlacementPolicyImpl
- Parameters:
- dnsResolver- the object used to resolve addresses to their network address
- Returns:
- initialized ensemble placement policy
 
 - 
uninitalizepublic void uninitalize() Description copied from interface:EnsemblePlacementPolicyUninitialize the policy.- Specified by:
- uninitalizein interface- EnsemblePlacementPolicy
- Overrides:
- uninitalizein class- RackawareEnsemblePlacementPolicyImpl
 
 - 
onClusterChangedpublic java.util.Set<BookieId> onClusterChanged(java.util.Set<BookieId> writableBookies, java.util.Set<BookieId> readOnlyBookies) Description copied from interface:EnsemblePlacementPolicyA consistent view of the cluster (what bookies are available as writable, what bookies are available as readonly) is updated when any changes happen in the cluster.The implementation should take actions when the cluster view is changed. So subsequent EnsemblePlacementPolicy.newEnsemble(int, int, int, Map, Set)and#replaceBookie(int, int, int, java.util.Map, java.util.Set, org.apache.bookkeeper.net.BookieSocketAddress, java.util.Set)can choose proper bookies.- Specified by:
- onClusterChangedin interface- EnsemblePlacementPolicy
- Overrides:
- onClusterChangedin class- TopologyAwareEnsemblePlacementPolicy
- Parameters:
- writableBookies- All the bookies in the cluster available for write/read.
- readOnlyBookies- All the bookies in the cluster available for readonly.
- Returns:
- the dead bookies during this cluster change.
 
 - 
newEnsemblepublic EnsemblePlacementPolicy.PlacementResult<java.util.List<BookieId>> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,byte[]> customMetadata, java.util.Set<BookieId> excludeBookies) throws BKException.BKNotEnoughBookiesException Description 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. - Specified by:
- newEnsemblein interface- EnsemblePlacementPolicy
- Overrides:
- newEnsemblein class- RackawareEnsemblePlacementPolicyImpl
- Parameters:
- ensembleSize- Ensemble Size
- writeQuorumSize- Write Quorum Size
- ackQuorumSize- the value of ackQuorumSize (added since 4.5)
- customMetadata- the value of customMetadata. it is the same user defined metadata that user provides in- BookKeeper.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.
 
 - 
replaceBookiepublic EnsemblePlacementPolicy.PlacementResult<BookieId> replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,byte[]> customMetadata, java.util.List<BookieId> currentEnsemble, BookieId bookieToReplace, java.util.Set<BookieId> excludeBookies) throws BKException.BKNotEnoughBookiesException Description 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. - Specified by:
- replaceBookiein interface- EnsemblePlacementPolicy
- Overrides:
- replaceBookiein class- RackawareEnsemblePlacementPolicyImpl
- Parameters:
- ensembleSize- the value of ensembleSize
- writeQuorumSize- the value of writeQuorumSize
- ackQuorumSize- the value of ackQuorumSize (added since 4.5)
- customMetadata- the value of customMetadata. it is the same user defined metadata that user provides in- BookKeeper.createLedger(int, int, int, BookKeeper.DigestType, byte[])
- currentEnsemble- the value of currentEnsemble
- bookieToReplace- bookie to replace
- excludeBookies- bookies that should not be considered as candidate.
- Returns:
- a placement result containing the new bookie address.
- Throws:
- BKException.BKNotEnoughBookiesException
 
 - 
reorderReadSequencepublic DistributionSchedule.WriteSet reorderReadSequence(java.util.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 interface- EnsemblePlacementPolicy
- Overrides:
- reorderReadSequencein class- RackawareEnsemblePlacementPolicyImpl
- Parameters:
- ensemble- Ensemble to read entries.
- bookiesHealthInfo- Health info for bookies
- writeSet- 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.
 
 - 
reorderReadLACSequencepublic DistributionSchedule.WriteSet reorderReadLACSequence(java.util.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 interface- EnsemblePlacementPolicy
- Overrides:
- reorderReadLACSequencein class- TopologyAwareEnsemblePlacementPolicy
- Parameters:
- ensemble- Ensemble to read entries.
- bookiesHealthInfo- Health info for bookies
- writeSet- 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.
 
 - 
newEnsemblepublic EnsemblePlacementPolicy.PlacementResult<java.util.List<BookieId>> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Set<BookieId> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> parentEnsemble, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> parentPredicate) throws BKException.BKNotEnoughBookiesException Description copied from interface:ITopologyAwareEnsemblePlacementPolicyCreate an ensemble with parent ensemble.- Specified by:
- newEnsemblein interface- ITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
- newEnsemblein class- RackawareEnsemblePlacementPolicyImpl
- Parameters:
- ensembleSize- ensemble size
- writeQuorumSize- write quorum size
- ackQuorumSize- ack quorum size
- excludeBookies- exclude bookies
- parentEnsemble- parent ensemble
- Returns:
- list of bookies forming the ensemble
- Throws:
- BKException.BKNotEnoughBookiesException
 
 - 
selectFromNetworkLocationpublic BookieNode selectFromNetworkLocation(java.lang.String networkLoc, java.util.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.- Specified by:
- selectFromNetworkLocationin interface- ITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
- selectFromNetworkLocationin class- RackawareEnsemblePlacementPolicyImpl
- Parameters:
- networkLoc- network location
- excludeBookies- exclude bookies set
- predicate- predicate to apply
- ensemble- ensemble
- fallbackToRandom- fallbackToRandom
- Returns:
- the selected bookie.
- Throws:
- BKException.BKNotEnoughBookiesException
 
 - 
selectFromNetworkLocationpublic BookieNode selectFromNetworkLocation(java.util.Set<java.lang.String> excludeRacks, java.util.Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean fallbackToRandom) throws BKException.BKNotEnoughBookiesException Description copied from class:RackawareEnsemblePlacementPolicyImplIt randomly selects aBookieNodethat is not on the excludeRacks set, excluding the nodes in excludeBookies set. If it fails to find one, it selects a randomBookieNodefrom the whole cluster.- Specified by:
- selectFromNetworkLocationin interface- ITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
- selectFromNetworkLocationin class- RackawareEnsemblePlacementPolicyImpl
- Returns:
- Throws:
- BKException.BKNotEnoughBookiesException
 
 - 
selectFromNetworkLocationpublic BookieNode selectFromNetworkLocation(java.lang.String networkLoc, java.util.Set<java.lang.String> excludeRacks, java.util.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- Specified by:
- selectFromNetworkLocationin interface- ITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
- selectFromNetworkLocationin class- RackawareEnsemblePlacementPolicyImpl
- Returns:
- Throws:
- BKException.BKNotEnoughBookiesException
 
 - 
handleBookiesThatLeftpublic void handleBookiesThatLeft(java.util.Set<BookieId> leftBookies) Description copied from interface:ITopologyAwareEnsemblePlacementPolicyHandle bookies that left.- Specified by:
- handleBookiesThatLeftin interface- ITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
- handleBookiesThatLeftin class- TopologyAwareEnsemblePlacementPolicy
- Parameters:
- leftBookies- bookies that left
 
 - 
handleBookiesThatJoinedpublic void handleBookiesThatJoined(java.util.Set<BookieId> joinedBookies) Description copied from interface:ITopologyAwareEnsemblePlacementPolicyHandle bookies that joined.- Specified by:
- handleBookiesThatJoinedin interface- ITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
- handleBookiesThatJoinedin class- TopologyAwareEnsemblePlacementPolicy
- Parameters:
- joinedBookies- bookies that joined.
 
 
- 
 
-