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
public class ZoneawareEnsemblePlacementPolicyImpl extends TopologyAwareEnsemblePlacementPolicy
Simple zoneaware ensemble placement policy.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation
Zone 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.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 protected java.util.concurrent.ConcurrentMap<BookieId,ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation>
address2NodePlacement
protected int
desiredNumZonesPerWriteQuorum
protected boolean
enforceStrictZoneawarePlacement
protected Counter
failedToResolveNetworkLocationCounter
(package private) static org.slf4j.Logger
LOG
protected int
maxWeightMultiple
protected int
minNumZonesPerWriteQuorum
protected BookieNode
myNode
protected java.lang.String
myZone
protected Gauge<java.lang.Integer>
numWritableBookiesInDefaultFaultDomain
protected boolean
reorderReadsRandom
protected int
reorderThresholdPendingRequests
protected com.google.common.cache.Cache<BookieId,java.lang.Long>
slowBookies
protected int
stabilizePeriodSeconds
protected StatsLogger
statsLogger
protected io.netty.util.HashedWheelTimer
timer
static java.lang.String
UNKNOWN_ZONE
protected ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation
unresolvedNodeLocation
-
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 ZoneawareEnsemblePlacementPolicyImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Set<BookieId>
addDefaultFaultDomainBookies(java.util.Set<BookieId> excludeBookies)
boolean
areAckedBookiesAdheringToPlacementPolicy(java.util.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.java.lang.String
getDefaultFaultDomain()
protected ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation
getZoneAwareNodeLocation(BookieId addr)
protected ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation
getZoneAwareNodeLocation(BookieNode node)
EnsemblePlacementPolicy
initialize(ClientConfiguration conf, java.util.Optional<DNSToSwitchMapping> optionalDnsResolver, io.netty.util.HashedWheelTimer timer, FeatureProvider featureProvider, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver)
Initialize the policy.EnsemblePlacementPolicy.PlacementPolicyAdherence
isEnsembleAdheringToPlacementPolicy(java.util.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.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.void
registerSlowBookie(BookieId bookieSocketAddress, long entryId)
Register a bookie as slow so that it is tried after available and read-only bookies.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.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)
Select a node from cluster excluding excludeBookies and bookie nodes of excludeRacks.void
uninitalize()
Uninitialize the policy.ZoneawareEnsemblePlacementPolicyImpl
withDefaultFaultDomain(java.lang.String defaultFaultDomain)
-
Methods inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
convertBookiesToNodes, convertBookieToNode, createBookieNode, createDummyLocalBookieNode, differBetweenBookies, getDefaultRack, getNetworkLocations, handleBookiesThatJoined, handleBookiesThatLeft, onBookieRackChange, onClusterChanged, 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
getStickyReadBookieIndex, replaceToAdherePlacementPolicy
-
-
-
-
Field Detail
-
LOG
static final org.slf4j.Logger LOG
-
UNKNOWN_ZONE
public static final java.lang.String UNKNOWN_ZONE
- See Also:
- Constant Field Values
-
unresolvedNodeLocation
protected ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation unresolvedNodeLocation
-
statsLogger
protected StatsLogger statsLogger
-
slowBookies
protected com.google.common.cache.Cache<BookieId,java.lang.Long> slowBookies
-
myNode
protected BookieNode myNode
-
myZone
protected java.lang.String 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 java.util.concurrent.ConcurrentMap<BookieId,ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation> address2NodePlacement
-
failedToResolveNetworkLocationCounter
@StatsDoc(name="FAILED_TO_RESOLVE_NETWORK_LOCATION_TOTAL", help="Counter for number of times DNSResolverDecorator failed to resolve Network Location") protected Counter failedToResolveNetworkLocationCounter
-
-
Method Detail
-
getZoneAwareNodeLocation
protected ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation getZoneAwareNodeLocation(BookieId addr)
-
getZoneAwareNodeLocation
protected ZoneawareEnsemblePlacementPolicyImpl.ZoneAwareNodeLocation getZoneAwareNodeLocation(BookieNode node)
-
initialize
public EnsemblePlacementPolicy initialize(ClientConfiguration conf, java.util.Optional<DNSToSwitchMapping> optionalDnsResolver, io.netty.util.HashedWheelTimer timer, FeatureProvider featureProvider, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver)
Description copied from interface:EnsemblePlacementPolicy
Initialize the policy.- Parameters:
conf
- client configurationoptionalDnsResolver
- dns resolvertimer
- timerfeatureProvider
- feature providerstatsLogger
- stats logger
-
withDefaultFaultDomain
public ZoneawareEnsemblePlacementPolicyImpl withDefaultFaultDomain(java.lang.String defaultFaultDomain)
-
getDefaultFaultDomain
public java.lang.String getDefaultFaultDomain()
-
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.- 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.- 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 interface:ITopologyAwareEnsemblePlacementPolicy
Select 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(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- Returns:
- Throws:
BKException.BKNotEnoughBookiesException
-
uninitalize
public void uninitalize()
Description copied from interface:EnsemblePlacementPolicy
Uninitialize the policy.
-
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.
- 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.
- 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
protected java.util.Set<BookieId> addDefaultFaultDomainBookies(java.util.Set<BookieId> excludeBookies)
-
registerSlowBookie
public void registerSlowBookie(BookieId bookieSocketAddress, long entryId)
Description copied from interface:EnsemblePlacementPolicy
Register 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(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 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(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.
-
isEnsembleAdheringToPlacementPolicy
public EnsemblePlacementPolicy.PlacementPolicyAdherence isEnsembleAdheringToPlacementPolicy(java.util.List<BookieId> ensembleList, int writeQuorumSize, int ackQuorumSize)
Description copied from interface:EnsemblePlacementPolicy
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. 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(java.util.Set<BookieId> ackedBookies, int writeQuorumSize, int ackQuorumSize)
Description copied from interface:EnsemblePlacementPolicy
Returns 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:
-
-