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()BookieAddressResolvergetBookieAddressResolver()java.util.Set<BookieId>getBookies()java.util.Set<BookieId>getReadOnlyBookies()voidinitialBlockingBookieRead()Blocks until bookies are read from zookeeper, used in theBookKeeperconstructor.booleanisBookieUnavailable(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.voidquarantineBookie(BookieId bookie)Quarantine bookie so it will not be preferred to be chosen for new ensembles.voidreleaseAllQuarantinedBookies()Release all quarantined bookies, let it can be chosen for new ensembles.BookieIdreplaceBookie(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:
 getBookiesin interfaceBookieWatcher- Throws:
 BKException
 
- 
getAllBookies
public java.util.Set<BookieId> getAllBookies() throws BKException
- Specified by:
 getAllBookiesin interfaceBookieWatcher- Throws:
 BKException
 
- 
getBookieAddressResolver
public BookieAddressResolver getBookieAddressResolver()
- Specified by:
 getBookieAddressResolverin interfaceBookieWatcher
 
- 
getReadOnlyBookies
public java.util.Set<BookieId> getReadOnlyBookies() throws BKException
- Specified by:
 getReadOnlyBookiesin 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:
 isBookieUnavailablein interfaceBookieWatcher- Parameters:
 id- Bookie to check- Returns:
 - whether or not the given bookie is unavailable
 
 
- 
initialBlockingBookieRead
public void initialBlockingBookieRead() throws BKExceptionBlocks until bookies are read from zookeeper, used in theBookKeeperconstructor.- 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:BookieWatcherCreate an ensemble with given ensembleSize and writeQuorumSize.- Specified by:
 newEnsemblein 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:BookieWatcherChoose a bookie to replace bookie bookieIdx in existingBookies.- Specified by:
 replaceBookiein interfaceBookieWatcherexistingBookies- 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:
 quarantineBookiein interfaceBookieWatcher- Parameters:
 bookie-
 
- 
releaseAllQuarantinedBookies
public void releaseAllQuarantinedBookies()
Description copied from interface:BookieWatcherRelease all quarantined bookies, let it can be chosen for new ensembles.- Specified by:
 releaseAllQuarantinedBookiesin interfaceBookieWatcher
 
 - 
 
 -