Package org.apache.bookkeeper.client
Class RegionAwareEnsemblePlacementPolicy
- java.lang.Object
-
- org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
-
- org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImpl
-
- org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy
-
- org.apache.bookkeeper.client.RegionAwareEnsemblePlacementPolicy
-
- All Implemented Interfaces:
EnsemblePlacementPolicy
,ITopologyAwareEnsemblePlacementPolicy<BookieNode>
public class RegionAwareEnsemblePlacementPolicy extends RackawareEnsemblePlacementPolicy
A placement policy use region information in the network topology 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 protected java.util.concurrent.ConcurrentMap<BookieId,java.lang.String>
address2Region
protected Feature
disableDurabilityFeature
protected java.lang.String
disallowBookiePlacementInRegionFeatureName
protected boolean
enableValidation
protected boolean
enforceDurabilityInReplace
protected FeatureProvider
featureProvider
(package private) static org.slf4j.Logger
LOG
(package private) static int
MINIMUM_REGIONS_FOR_DURABILITY_DEFAULT
protected int
minRegionsForDurability
protected java.lang.String
myRegion
protected java.util.Map<java.lang.String,TopologyAwareEnsemblePlacementPolicy>
perRegionPlacement
static java.lang.String
REGION_AWARE_ANOMALOUS_ENSEMBLE
(package private) static int
REGIONID_DISTANCE_FROM_LEAVES
(package private) static int
REMOTE_NODE_IN_REORDER_SEQUENCE
static java.lang.String
REPP_DISABLE_DURABILITY_ENFORCEMENT_FEATURE
static java.lang.String
REPP_DISABLE_DURABILITY_FEATURE_NAME
static java.lang.String
REPP_DISALLOW_BOOKIE_PLACEMENT_IN_REGION_FEATURE_NAME
static java.lang.String
REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE
static java.lang.String
REPP_ENABLE_VALIDATION
static java.lang.String
REPP_MINIMUM_REGIONS_FOR_DURABILITY
static java.lang.String
REPP_REGIONS_TO_WRITE
(package private) static java.lang.String
UNKNOWN_REGION
-
Fields inherited from class org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy
slave
-
Fields inherited from class org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImpl
enforceDurability, enforceMinNumRacksPerWriteQuorum, failedToResolveNetworkLocationCounter, ignoreLocalNodeInPlacementPolicy, LOCAL_FAIL_MASK, LOCAL_MASK, localNode, 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 RegionAwareEnsemblePlacementPolicy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
getLocalRegion(BookieNode node)
protected java.lang.String
getRegion(BookieId addr)
void
handleBookiesThatJoined(java.util.Set<BookieId> joinedBookies)
Handle bookies that joined.void
handleBookiesThatLeft(java.util.Set<BookieId> leftBookies)
Handle bookies that left.RegionAwareEnsemblePlacementPolicy
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> excludedBookies)
Choose numBookies bookies for ensemble.void
onBookieRackChange(java.util.List<BookieId> bookieAddressList)
Handle rack change for the bookies.protected java.lang.String
parseBookieRegion(BookieId addr)
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.protected BookieNode
replaceFromRack(BookieNode bookieNodeToReplace, java.util.Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean enforceDurability)
protected java.util.List<BookieNode>
selectRandomFromRegions(java.util.Set<java.lang.String> availableRegions, int numBookies, java.util.Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble)
-
Methods inherited from class org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy
initialize, initialize, newEnsemble, onClusterChanged, replaceToAdherePlacementPolicy, selectFromNetworkLocation, selectFromNetworkLocation, selectFromNetworkLocation, uninitalize
-
Methods inherited from class org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicyImpl
addDefaultRackBookiesIfMinNumRacksIsEnforced, areAckedBookiesAdheringToPlacementPolicy, getDefaultRack, newEnsembleInternal, registerSlowBookie, reorderReadSequenceWithRegion, selectRandom, selectRandomFromRack, selectRandomInternal, withDefaultRack
-
Methods inherited from class org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy
convertBookiesToNodes, convertBookieToNode, createBookieNode, createDummyLocalBookieNode, differBetweenBookies, getNetworkLocations, 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, registerSlowBookie, updateBookieInfo
-
-
-
-
Field Detail
-
LOG
static final org.slf4j.Logger LOG
-
REPP_REGIONS_TO_WRITE
public static final java.lang.String REPP_REGIONS_TO_WRITE
- See Also:
- Constant Field Values
-
REPP_MINIMUM_REGIONS_FOR_DURABILITY
public static final java.lang.String REPP_MINIMUM_REGIONS_FOR_DURABILITY
- See Also:
- Constant Field Values
-
REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE
public static final java.lang.String REPP_ENABLE_DURABILITY_ENFORCEMENT_IN_REPLACE
- See Also:
- Constant Field Values
-
REPP_DISABLE_DURABILITY_FEATURE_NAME
public static final java.lang.String REPP_DISABLE_DURABILITY_FEATURE_NAME
- See Also:
- Constant Field Values
-
REPP_DISALLOW_BOOKIE_PLACEMENT_IN_REGION_FEATURE_NAME
public static final java.lang.String REPP_DISALLOW_BOOKIE_PLACEMENT_IN_REGION_FEATURE_NAME
- See Also:
- Constant Field Values
-
REPP_DISABLE_DURABILITY_ENFORCEMENT_FEATURE
public static final java.lang.String REPP_DISABLE_DURABILITY_ENFORCEMENT_FEATURE
- See Also:
- Constant Field Values
-
REPP_ENABLE_VALIDATION
public static final java.lang.String REPP_ENABLE_VALIDATION
- See Also:
- Constant Field Values
-
REGION_AWARE_ANOMALOUS_ENSEMBLE
public static final java.lang.String REGION_AWARE_ANOMALOUS_ENSEMBLE
- See Also:
- Constant Field Values
-
MINIMUM_REGIONS_FOR_DURABILITY_DEFAULT
static final int MINIMUM_REGIONS_FOR_DURABILITY_DEFAULT
- See Also:
- Constant Field Values
-
REGIONID_DISTANCE_FROM_LEAVES
static final int REGIONID_DISTANCE_FROM_LEAVES
- See Also:
- Constant Field Values
-
UNKNOWN_REGION
static final java.lang.String UNKNOWN_REGION
- See Also:
- Constant Field Values
-
REMOTE_NODE_IN_REORDER_SEQUENCE
static final int REMOTE_NODE_IN_REORDER_SEQUENCE
- See Also:
- Constant Field Values
-
perRegionPlacement
protected final java.util.Map<java.lang.String,TopologyAwareEnsemblePlacementPolicy> perRegionPlacement
-
address2Region
protected final java.util.concurrent.ConcurrentMap<BookieId,java.lang.String> address2Region
-
featureProvider
protected FeatureProvider featureProvider
-
disallowBookiePlacementInRegionFeatureName
protected java.lang.String disallowBookiePlacementInRegionFeatureName
-
myRegion
protected java.lang.String myRegion
-
minRegionsForDurability
protected int minRegionsForDurability
-
enableValidation
protected boolean enableValidation
-
enforceDurabilityInReplace
protected boolean enforceDurabilityInReplace
-
disableDurabilityFeature
protected Feature disableDurabilityFeature
-
-
Method Detail
-
getLocalRegion
protected java.lang.String getLocalRegion(BookieNode node)
-
getRegion
protected java.lang.String getRegion(BookieId addr)
-
parseBookieRegion
protected java.lang.String parseBookieRegion(BookieId addr)
-
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 classRackawareEnsemblePlacementPolicy
- 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 classRackawareEnsemblePlacementPolicy
- Parameters:
joinedBookies
- bookies that joined.
-
onBookieRackChange
public void onBookieRackChange(java.util.List<BookieId> bookieAddressList)
Description copied from interface:ITopologyAwareEnsemblePlacementPolicy
Handle rack change for the bookies.- Specified by:
onBookieRackChange
in interfaceITopologyAwareEnsemblePlacementPolicy<BookieNode>
- Overrides:
onBookieRackChange
in classTopologyAwareEnsemblePlacementPolicy
-
initialize
public RegionAwareEnsemblePlacementPolicy 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.- Specified by:
initialize
in interfaceEnsemblePlacementPolicy
- Overrides:
initialize
in classRackawareEnsemblePlacementPolicyImpl
- Parameters:
conf
- client configurationoptionalDnsResolver
- dns resolvertimer
- timerfeatureProvider
- feature providerstatsLogger
- stats logger
-
selectRandomFromRegions
protected java.util.List<BookieNode> selectRandomFromRegions(java.util.Set<java.lang.String> availableRegions, int numBookies, java.util.Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble) throws BKException.BKNotEnoughBookiesException
-
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> excludedBookies) 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 classRackawareEnsemblePlacementPolicy
- 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[])
excludedBookies
- 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 classRackawareEnsemblePlacementPolicy
- 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
-
replaceFromRack
protected BookieNode replaceFromRack(BookieNode bookieNodeToReplace, java.util.Set<Node> excludeBookies, ITopologyAwareEnsemblePlacementPolicy.Predicate<BookieNode> predicate, ITopologyAwareEnsemblePlacementPolicy.Ensemble<BookieNode> ensemble, boolean enforceDurability) throws BKException.BKNotEnoughBookiesException
-
reorderReadSequence
public final 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 classRackawareEnsemblePlacementPolicy
- 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 final 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 classRackawareEnsemblePlacementPolicy
- 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.- Specified by:
isEnsembleAdheringToPlacementPolicy
in interfaceEnsemblePlacementPolicy
- Overrides:
isEnsembleAdheringToPlacementPolicy
in classRackawareEnsemblePlacementPolicyImpl
- Parameters:
ensembleList
- list of BookieId of bookies in the ensemblewriteQuorumSize
- writeQuorumSize of the ensembleackQuorumSize
- ackQuorumSize of the ensemble- Returns:
-
-