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.TopologyAwareEnsemblePlacementPolicy
TopologyAwareEnsemblePlacementPolicy.DefaultResolver, TopologyAwareEnsemblePlacementPolicy.DNSResolverDecorator, TopologyAwareEnsemblePlacementPolicy.EnsembleForReplacementWithNoConstraints, TopologyAwareEnsemblePlacementPolicy.RRTopologyAwareCoverageEnsemble, TopologyAwareEnsemblePlacementPolicy.TruePredicate
-
Nested 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
Fields Modifier and Type Field Description (package private) RackawareEnsemblePlacementPolicyImplslave-
Fields inherited from class org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImpl
enforceDurability, 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, useHostnameResolveLocalNodePlacementPolicy
-
Fields 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 Constructor Description RackawareEnsemblePlacementPolicy()RackawareEnsemblePlacementPolicy(boolean enforceDurability)
-
Method Summary
All 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, boolean useHostnameResolveLocalNodePlacementPolicy, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver)Initialize the policy.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.EnsemblePlacementPolicy.PlacementResult<java.util.List<BookieId>>replaceToAdherePlacementPolicy(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Set<BookieId> excludeBookies, java.util.List<BookieId> currentEnsemble)Returns placement result.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.RackawareEnsemblePlacementPolicyImpl
addDefaultRackBookiesIfMinNumRacksIsEnforced, areAckedBookiesAdheringToPlacementPolicy, getDefaultRack, initialize, isEnsembleAdheringToPlacementPolicy, newEnsembleInternal, registerSlowBookie, reorderReadSequenceWithRegion, selectRandom, selectRandomFromRack, selectRandomInternal, withDefaultRack
-
Methods inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
convertBookiesToNodes, convertBookieToNode, createBookieNode, createDummyLocalBookieNode, differBetweenBookies, getNetworkLocations, onBookieRackChange, resolveNetworkLocation, shuffleWithMask, updateBookieInfo
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.bookkeeper.client.EnsemblePlacementPolicy
areAckedBookiesAdheringToPlacementPolicy, getStickyReadBookieIndex, initialize, isEnsembleAdheringToPlacementPolicy, registerSlowBookie, updateBookieInfo
-
Methods inherited from interface org.apache.bookkeeper.client.ITopologyAwareEnsemblePlacementPolicy
onBookieRackChange
-
-
-
-
Field Detail
-
slave
RackawareEnsemblePlacementPolicyImpl slave
-
-
Method Detail
-
initialize
protected 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 classRackawareEnsemblePlacementPolicyImpl- Returns:
- initialized ensemble placement policy
-
initialize
protected 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, boolean useHostnameResolveLocalNodePlacementPolicy, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver)
Description copied from class:RackawareEnsemblePlacementPolicyImplInitialize the policy.- Overrides:
initializein classRackawareEnsemblePlacementPolicyImpl- Parameters:
dnsResolver- the object used to resolve addresses to their network address- Returns:
- initialized ensemble placement policy
-
uninitalize
public void uninitalize()
Description copied from interface:EnsemblePlacementPolicyUninitialize the policy.- Specified by:
uninitalizein interfaceEnsemblePlacementPolicy- Overrides:
uninitalizein classRackawareEnsemblePlacementPolicyImpl
-
onClusterChanged
public 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)andEnsemblePlacementPolicy.replaceBookie(int, int, int, java.util.Map, java.util.List, BookieId, java.util.Set)can choose proper bookies.- Specified by:
onClusterChangedin interfaceEnsemblePlacementPolicy- Overrides:
onClusterChangedin classTopologyAwareEnsemblePlacementPolicy- 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.
-
newEnsemble
public 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 interfaceEnsemblePlacementPolicy- Overrides:
newEnsemblein classRackawareEnsemblePlacementPolicyImpl- 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, 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 interfaceEnsemblePlacementPolicy- Overrides:
replaceBookiein classRackawareEnsemblePlacementPolicyImpl- 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
-
reorderReadSequence
public 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 interfaceEnsemblePlacementPolicy- Overrides:
reorderReadSequencein classRackawareEnsemblePlacementPolicyImpl- 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(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 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.
-
newEnsemble
public 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 interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>- Overrides:
newEnsemblein classRackawareEnsemblePlacementPolicyImpl- 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(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 interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>- Overrides:
selectFromNetworkLocationin classRackawareEnsemblePlacementPolicyImpl- Parameters:
networkLoc- network locationexcludeBookies- exclude bookies setpredicate- predicate to applyensemble- ensemblefallbackToRandom- fallbackToRandom- Returns:
- the selected bookie.
- Throws:
BKException.BKNotEnoughBookiesException
-
selectFromNetworkLocation
public 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 interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>- Overrides:
selectFromNetworkLocationin classRackawareEnsemblePlacementPolicyImpl- Returns:
- Throws:
BKException.BKNotEnoughBookiesException
-
selectFromNetworkLocation
public 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 interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>- Overrides:
selectFromNetworkLocationin classRackawareEnsemblePlacementPolicyImpl- Returns:
- Throws:
BKException.BKNotEnoughBookiesException
-
replaceToAdherePlacementPolicy
public EnsemblePlacementPolicy.PlacementResult<java.util.List<BookieId>> replaceToAdherePlacementPolicy(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Set<BookieId> excludeBookies, java.util.List<BookieId> currentEnsemble)
Description copied from interface:EnsemblePlacementPolicyReturns placement result. If the currentEnsemble is not adhering placement policy, returns new ensemble that adheres placement policy. It should be implemented so as to minify the number of bookies replaced.- Specified by:
replaceToAdherePlacementPolicyin interfaceEnsemblePlacementPolicy- Overrides:
replaceToAdherePlacementPolicyin classRackawareEnsemblePlacementPolicyImpl- Parameters:
ensembleSize- ensemble sizewriteQuorumSize- writeQuorumSize of the ensembleackQuorumSize- ackQuorumSize of the ensembleexcludeBookies- bookies that should not be considered as targetscurrentEnsemble- current ensemble- Returns:
- a placement result
-
handleBookiesThatLeft
public void handleBookiesThatLeft(java.util.Set<BookieId> leftBookies)
Description copied from interface:ITopologyAwareEnsemblePlacementPolicyHandle bookies that left.- Specified by:
handleBookiesThatLeftin interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>- Overrides:
handleBookiesThatLeftin classTopologyAwareEnsemblePlacementPolicy- Parameters:
leftBookies- bookies that left
-
handleBookiesThatJoined
public void handleBookiesThatJoined(java.util.Set<BookieId> joinedBookies)
Description copied from interface:ITopologyAwareEnsemblePlacementPolicyHandle bookies that joined.- Specified by:
handleBookiesThatJoinedin interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>- Overrides:
handleBookiesThatJoinedin classTopologyAwareEnsemblePlacementPolicy- Parameters:
joinedBookies- bookies that joined.
-
-