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) RackawareEnsemblePlacementPolicyImpl
slave
-
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 void
handleBookiesThatJoined(java.util.Set<BookieId> joinedBookies)
Handle bookies that joined.void
handleBookiesThatLeft(java.util.Set<BookieId> leftBookies)
Handle bookies that left.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)
Initialize the policy.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)
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.WriteSet
reorderReadLACSequence(java.util.List<BookieId> ensemble, BookiesHealthInfo bookiesHealthInfo, DistributionSchedule.WriteSet writeSet)
Reorder the read last add confirmed sequence of a given write quorum writeSet.DistributionSchedule.WriteSet
reorderReadSequence(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.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)
Select a node from networkLoc rack excluding excludeBookies.BookieNode
selectFromNetworkLocation(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.BookieNode
selectFromNetworkLocation(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 aBookieNode
that is not on the excludeRacks set, excluding the nodes in excludeBookies set.void
uninitalize()
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:RackawareEnsemblePlacementPolicyImpl
Initialize the policy.- Overrides:
initialize
in 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:RackawareEnsemblePlacementPolicyImpl
Initialize the policy.- Overrides:
initialize
in 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:EnsemblePlacementPolicy
Uninitialize the policy.- Specified by:
uninitalize
in interfaceEnsemblePlacementPolicy
- Overrides:
uninitalize
in classRackawareEnsemblePlacementPolicyImpl
-
onClusterChanged
public java.util.Set<BookieId> onClusterChanged(java.util.Set<BookieId> writableBookies, java.util.Set<BookieId> readOnlyBookies)
Description copied from interface:EnsemblePlacementPolicy
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.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:
onClusterChanged
in interfaceEnsemblePlacementPolicy
- Overrides:
onClusterChanged
in 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:EnsemblePlacementPolicy
Choose numBookies bookies for ensemble. If the count is more than the number of available nodes,BKException.BKNotEnoughBookiesException
is thrown.The implementation should respect to the replace settings. The size of the returned bookie list should be equal to the provide
ensembleSize
.customMetadata
is 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:
newEnsemble
in interfaceEnsemblePlacementPolicy
- Overrides:
newEnsemble
in 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:EnsemblePlacementPolicy
Choose a new bookie to replace bookieToReplace. If no bookie available in the cluster,BKException.BKNotEnoughBookiesException
is thrown.If 'enforceMinNumRacksPerWriteQuorum' config is enabled then the bookies belonging to default faultzone (rack) will be excluded while selecting bookies.
- Specified by:
replaceBookie
in interfaceEnsemblePlacementPolicy
- Overrides:
replaceBookie
in 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:EnsemblePlacementPolicy
Reorder the read sequence of a given write quorum writeSet.- Specified by:
reorderReadSequence
in interfaceEnsemblePlacementPolicy
- Overrides:
reorderReadSequence
in 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:EnsemblePlacementPolicy
Reorder the read last add confirmed sequence of a given write quorum writeSet.- Specified by:
reorderReadLACSequence
in interfaceEnsemblePlacementPolicy
- Overrides:
reorderReadLACSequence
in 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:ITopologyAwareEnsemblePlacementPolicy
Create an ensemble with parent ensemble.- Specified by:
newEnsemble
in interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
newEnsemble
in 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:ITopologyAwareEnsemblePlacementPolicy
Select a node from a given network location.- Specified by:
selectFromNetworkLocation
in interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
selectFromNetworkLocation
in 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:RackawareEnsemblePlacementPolicyImpl
It randomly selects aBookieNode
that is not on the excludeRacks set, excluding the nodes in excludeBookies set. If it fails to find one, it selects a randomBookieNode
from the whole cluster.- Specified by:
selectFromNetworkLocation
in interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
selectFromNetworkLocation
in 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:ITopologyAwareEnsemblePlacementPolicy
Select 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:
selectFromNetworkLocation
in interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
selectFromNetworkLocation
in 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:EnsemblePlacementPolicy
Returns 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:
replaceToAdherePlacementPolicy
in interfaceEnsemblePlacementPolicy
- Overrides:
replaceToAdherePlacementPolicy
in 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:ITopologyAwareEnsemblePlacementPolicy
Handle bookies that left.- Specified by:
handleBookiesThatLeft
in interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
handleBookiesThatLeft
in classTopologyAwareEnsemblePlacementPolicy
- Parameters:
leftBookies
- bookies that left
-
handleBookiesThatJoined
public void handleBookiesThatJoined(java.util.Set<BookieId> joinedBookies)
Description copied from interface:ITopologyAwareEnsemblePlacementPolicy
Handle bookies that joined.- Specified by:
handleBookiesThatJoined
in interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
handleBookiesThatJoined
in classTopologyAwareEnsemblePlacementPolicy
- Parameters:
joinedBookies
- bookies that joined.
-
-