Class LocalBookieEnsemblePlacementPolicy
- java.lang.Object
-
- org.apache.bookkeeper.bookie.LocalBookieEnsemblePlacementPolicy
-
- All Implemented Interfaces:
EnsemblePlacementPolicy
public class LocalBookieEnsemblePlacementPolicy extends java.lang.Object implements EnsemblePlacementPolicy
Special ensemble placement policy that always return local bookie. Only works with ledgers with ensemble=1.- See Also:
EnsemblePlacementPolicy
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.client.EnsemblePlacementPolicy
EnsemblePlacementPolicy.PlacementPolicyAdherence, EnsemblePlacementPolicy.PlacementResult<T>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static org.slf4j.Logger
LOG
-
Constructor Summary
Constructors Constructor Description LocalBookieEnsemblePlacementPolicy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EnsemblePlacementPolicy
initialize(ClientConfiguration conf, java.util.Optional<DNSToSwitchMapping> optionalDnsResolver, io.netty.util.HashedWheelTimer hashedWheelTimer, 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.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.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.void
uninitalize()
Uninitialize the policy.void
updateBookieInfo(java.util.Map<BookieId,BookieInfoReader.BookieInfo> bookieToFreeSpaceMap)
Send the bookie info details.-
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, replaceToAdherePlacementPolicy
-
-
-
-
Method Detail
-
initialize
public EnsemblePlacementPolicy initialize(ClientConfiguration conf, java.util.Optional<DNSToSwitchMapping> optionalDnsResolver, io.netty.util.HashedWheelTimer hashedWheelTimer, FeatureProvider featureProvider, StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver)
Description copied from interface:EnsemblePlacementPolicy
Initialize the policy.- Specified by:
initialize
in interfaceEnsemblePlacementPolicy
- Parameters:
conf
- client configurationoptionalDnsResolver
- dns resolverhashedWheelTimer
- timerfeatureProvider
- feature providerstatsLogger
- stats logger
-
uninitalize
public void uninitalize()
Description copied from interface:EnsemblePlacementPolicy
Uninitialize the policy.- Specified by:
uninitalize
in interfaceEnsemblePlacementPolicy
-
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
- 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.
-
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
- 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
-
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.- Specified by:
registerSlowBookie
in interfaceEnsemblePlacementPolicy
- 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
- 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
- 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.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
- 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.
-
updateBookieInfo
public void updateBookieInfo(java.util.Map<BookieId,BookieInfoReader.BookieInfo> bookieToFreeSpaceMap)
Description copied from interface:EnsemblePlacementPolicy
Send the bookie info details.- Specified by:
updateBookieInfo
in interfaceEnsemblePlacementPolicy
- Parameters:
bookieToFreeSpaceMap
- A map that has the bookie to BookieInfo
-
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
- Parameters:
ensembleList
- list of BookieId of bookies in the ensemblewriteQuorumSize
- writeQuorumSize of the ensembleackQuorumSize
- ackQuorumSize of the ensemble- Returns:
-
-