Class 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<org.apache.bookkeeper.net.BookieId,​java.lang.Boolean> quarantinedBookies  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<org.apache.bookkeeper.net.BookieId> getAllBookies()  
      org.apache.bookkeeper.proto.BookieAddressResolver getBookieAddressResolver()  
      java.util.Set<org.apache.bookkeeper.net.BookieId> getBookies()  
      java.util.Set<org.apache.bookkeeper.net.BookieId> getReadOnlyBookies()  
      void initialBlockingBookieRead()
      Blocks until bookies are read from zookeeper, used in the BookKeeper constructor.
      boolean isBookieUnavailable​(org.apache.bookkeeper.net.BookieId id)
      Determine if a bookie should be considered unavailable.
      java.util.List<org.apache.bookkeeper.net.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​(org.apache.bookkeeper.net.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.
      org.apache.bookkeeper.net.BookieId replaceBookie​(int ensembleSize, int writeQuorumSize, int ackQuorumSize, java.util.Map<java.lang.String,​byte[]> customMetadata, java.util.List<org.apache.bookkeeper.net.BookieId> existingBookies, int bookieIdx, java.util.Set<org.apache.bookkeeper.net.BookieId> excludeBookies)
      Choose a bookie to replace bookie bookieIdx in existingBookies.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • quarantinedBookies

        final com.google.common.cache.Cache<org.apache.bookkeeper.net.BookieId,​java.lang.Boolean> quarantinedBookies
    • Constructor Detail

      • BookieWatcherImpl

        public BookieWatcherImpl​(ClientConfiguration conf,
                                 EnsemblePlacementPolicy placementPolicy,
                                 org.apache.bookkeeper.discover.RegistrationClient registrationClient,
                                 org.apache.bookkeeper.proto.BookieAddressResolver bookieAddressResolver,
                                 StatsLogger statsLogger)
    • Method Detail

      • isBookieUnavailable

        public boolean isBookieUnavailable​(org.apache.bookkeeper.net.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 interface BookieWatcher
        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 the BookKeeper constructor.
        Throws:
        BKException - when failed to read bookies
      • newEnsemble

        public java.util.List<org.apache.bookkeeper.net.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 interface BookieWatcher
        Parameters:
        ensembleSize - Ensemble Size
        writeQuorumSize - Write Quorum Size
        Returns:
        list of bookies for new ensemble.
        Throws:
        BKException.BKNotEnoughBookiesException
      • replaceBookie

        public org.apache.bookkeeper.net.BookieId replaceBookie​(int ensembleSize,
                                                                int writeQuorumSize,
                                                                int ackQuorumSize,
                                                                java.util.Map<java.lang.String,​byte[]> customMetadata,
                                                                java.util.List<org.apache.bookkeeper.net.BookieId> existingBookies,
                                                                int bookieIdx,
                                                                java.util.Set<org.apache.bookkeeper.net.BookieId> excludeBookies)
                                                         throws BKException.BKNotEnoughBookiesException
        Description copied from interface: BookieWatcher
        Choose a bookie to replace bookie bookieIdx in existingBookies.
        Specified by:
        replaceBookie in interface BookieWatcher
        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​(org.apache.bookkeeper.net.BookieId bookie)
        Quarantine bookie so it will not be preferred to be chosen for new ensembles.
        Specified by:
        quarantineBookie in interface BookieWatcher
        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 interface BookieWatcher