Package org.apache.bookkeeper.client
Class BookieWatcherImpl
- java.lang.Object
-
- org.apache.bookkeeper.client.BookieWatcherImpl
-
- All Implemented Interfaces:
BookieWatcher
@StatsDoc(name="bookie_watcher", help="Bookie watcher related stats") class BookieWatcherImpl extends java.lang.Object implements BookieWatcher
This class is responsible for maintaining a consistent view of what bookies are available by reading Zookeeper (and setting watches on the bookie nodes). When a bookie fails, the other parts of the code turn to this class to find a replacement
-
-
Field Summary
Fields Modifier and Type Field Description (package private) com.google.common.cache.Cache<BookieId,java.lang.Boolean>
quarantinedBookies
-
Constructor Summary
Constructors Constructor Description BookieWatcherImpl(ClientConfiguration conf, EnsemblePlacementPolicy placementPolicy, RegistrationClient registrationClient, BookieAddressResolver bookieAddressResolver, StatsLogger statsLogger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<BookieId>
getAllBookies()
BookieAddressResolver
getBookieAddressResolver()
java.util.Set<BookieId>
getBookies()
java.util.Set<BookieId>
getReadOnlyBookies()
void
initialBlockingBookieRead()
Blocks until bookies are read from zookeeper, used in theBookKeeper
constructor.boolean
isBookieUnavailable(BookieId id)
Determine if a bookie should be considered unavailable.java.util.List<BookieId>
newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,byte[]> customMetadata)
Create an ensemble with given ensembleSize and writeQuorumSize.void
quarantineBookie(BookieId bookie)
Quarantine bookie so it will not be preferred to be chosen for new ensembles.void
releaseAllQuarantinedBookies()
Release all quarantined bookies, let it can be chosen for new ensembles.BookieId
replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,byte[]> customMetadata, java.util.List<BookieId> existingBookies, int bookieIdx, java.util.Set<BookieId> excludeBookies)
Choose a bookie to replace bookie bookieIdx in existingBookies.
-
-
-
Field Detail
-
quarantinedBookies
final com.google.common.cache.Cache<BookieId,java.lang.Boolean> quarantinedBookies
-
-
Constructor Detail
-
BookieWatcherImpl
public BookieWatcherImpl(ClientConfiguration conf, EnsemblePlacementPolicy placementPolicy, RegistrationClient registrationClient, BookieAddressResolver bookieAddressResolver, StatsLogger statsLogger)
-
-
Method Detail
-
getBookies
public java.util.Set<BookieId> getBookies() throws BKException
- Specified by:
getBookies
in interfaceBookieWatcher
- Throws:
BKException
-
getAllBookies
public java.util.Set<BookieId> getAllBookies() throws BKException
- Specified by:
getAllBookies
in interfaceBookieWatcher
- Throws:
BKException
-
getBookieAddressResolver
public BookieAddressResolver getBookieAddressResolver()
- Specified by:
getBookieAddressResolver
in interfaceBookieWatcher
-
getReadOnlyBookies
public java.util.Set<BookieId> getReadOnlyBookies() throws BKException
- Specified by:
getReadOnlyBookies
in interfaceBookieWatcher
- Throws:
BKException
-
isBookieUnavailable
public boolean isBookieUnavailable(BookieId id)
Determine if a bookie should be considered unavailable. This does not require a network call because this class maintains a current view of readonly and writable bookies. An unavailable bookie is one that is neither read only nor writable.- Specified by:
isBookieUnavailable
in interfaceBookieWatcher
- Parameters:
id
- Bookie to check- Returns:
- whether or not the given bookie is unavailable
-
initialBlockingBookieRead
public void initialBlockingBookieRead() throws BKException
Blocks until bookies are read from zookeeper, used in theBookKeeper
constructor.- Throws:
BKException
- when failed to read bookies
-
newEnsemble
public java.util.List<BookieId> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,byte[]> customMetadata) throws BKException.BKNotEnoughBookiesException
Description copied from interface:BookieWatcher
Create an ensemble with given ensembleSize and writeQuorumSize.- Specified by:
newEnsemble
in interfaceBookieWatcher
- Parameters:
ensembleSize
- Ensemble SizewriteQuorumSize
- Write Quorum Size- Returns:
- list of bookies for new ensemble.
- Throws:
BKException.BKNotEnoughBookiesException
-
replaceBookie
public BookieId replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,byte[]> customMetadata, java.util.List<BookieId> existingBookies, int bookieIdx, java.util.Set<BookieId> excludeBookies) throws BKException.BKNotEnoughBookiesException
Description copied from interface:BookieWatcher
Choose a bookie to replace bookie bookieIdx in existingBookies.- Specified by:
replaceBookie
in interfaceBookieWatcher
existingBookies
- list of existing bookies.bookieIdx
- index of the bookie in the list to be replaced.- Returns:
- the bookie to replace.
- Throws:
BKException.BKNotEnoughBookiesException
-
quarantineBookie
public void quarantineBookie(BookieId bookie)
Quarantine bookie so it will not be preferred to be chosen for new ensembles.- Specified by:
quarantineBookie
in interfaceBookieWatcher
- Parameters:
bookie
-
-
releaseAllQuarantinedBookies
public void releaseAllQuarantinedBookies()
Description copied from interface:BookieWatcher
Release all quarantined bookies, let it can be chosen for new ensembles.- Specified by:
releaseAllQuarantinedBookies
in interfaceBookieWatcher
-
-