Class AbstractZkLedgerManager

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, LedgerManager, org.apache.zookeeper.Watcher
    Direct Known Subclasses:
    AbstractHierarchicalLedgerManager, FlatLedgerManager

    public abstract class AbstractZkLedgerManager
    extends java.lang.Object
    implements LedgerManager, org.apache.zookeeper.Watcher
    Abstract ledger manager based on zookeeper, which provides common methods such as query zk nodes.
    • Field Detail

      • zk

        protected final org.apache.zookeeper.ZooKeeper zk
      • ledgerRootPath

        protected final java.lang.String ledgerRootPath
      • scheduler

        protected java.util.concurrent.ScheduledExecutorService scheduler
    • Constructor Detail

      • AbstractZkLedgerManager

        protected AbstractZkLedgerManager​(AbstractConfiguration conf,
                                          org.apache.zookeeper.ZooKeeper zk)
        ZooKeeper-based Ledger Manager Constructor.
        Parameters:
        conf - Configuration object
        zk - ZooKeeper Client Handle
    • Method Detail

      • getLedgerPath

        public abstract java.lang.String getLedgerPath​(long ledgerId)
        Get the znode path that is used to store ledger metadata.
        Parameters:
        ledgerId - Ledger ID
        Returns:
        ledger node path
      • getLedgerId

        protected abstract long getLedgerId​(java.lang.String ledgerPath)
                                     throws java.io.IOException
        Get ledger id from its znode ledger path.
        Parameters:
        ledgerPath - Ledger path to store metadata
        Returns:
        ledger id
        Throws:
        java.io.IOException - when the ledger path is invalid
      • process

        public void process​(org.apache.zookeeper.WatchedEvent event)
        Specified by:
        process in interface org.apache.zookeeper.Watcher
      • readLedgerMetadata

        protected java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>> readLedgerMetadata​(long ledgerId,
                                                                                                       org.apache.zookeeper.Watcher watcher)
      • asyncProcessLedgersInSingleNode

        protected void asyncProcessLedgersInSingleNode​(java.lang.String path,
                                                       BookkeeperInternalCallbacks.Processor<java.lang.Long> processor,
                                                       org.apache.zookeeper.AsyncCallback.VoidCallback finalCb,
                                                       java.lang.Object ctx,
                                                       int successRc,
                                                       int failureRc)
        Process ledgers in a single zk node.

        for each ledger found in this zk node, processor#process(ledgerId) will be triggered to process a specific ledger. after all ledgers has been processed, the finalCb will be called with provided context object. The RC passed to finalCb is decided by :

        • All ledgers are processed successfully, successRc will be passed.
        • Either ledger is processed failed, failureRc will be passed.

        Parameters:
        path - Zk node path to store ledgers
        processor - Processor provided to process ledger
        finalCb - Callback object when all ledgers are processed
        ctx - Context object passed to finalCb
        successRc - RC passed to finalCb when all ledgers are processed successfully
        failureRc - RC passed to finalCb when either ledger is processed failed
      • isSpecialZnode

        public static boolean isSpecialZnode​(java.lang.String znode)
        Whether the znode a special znode.
        Parameters:
        znode - Znode Name
        Returns:
        true if the znode is a special znode otherwise false
      • isLeadgerIdGeneratorZnode

        public static boolean isLeadgerIdGeneratorZnode​(java.lang.String znode)
      • getLedgerParentNodeRegex

        protected abstract java.lang.String getLedgerParentNodeRegex()
        regex expression for name of top level parent znode for ledgers (in HierarchicalLedgerManager) or znode of a ledger (in FlatLedgerManager).
        Returns:
      • isLedgerParentNode

        public boolean isLedgerParentNode​(java.lang.String znode)
        whether the child of ledgersRootPath is a top level parent znode for ledgers (in HierarchicalLedgerManager) or znode of a ledger (in FlatLedgerManager).
        Parameters:
        znode - Znode Name
        Returns:
      • ledgerListToSet

        protected java.util.NavigableSet<java.lang.Long> ledgerListToSet​(java.util.List<java.lang.String> ledgerNodes,
                                                                         java.lang.String path)
        Convert the ZK retrieved ledger nodes to a HashSet for easier comparisons.
        Parameters:
        ledgerNodes - zk ledger nodes
        path - the prefix path of the ledger nodes
        Returns:
        ledger id hash set
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable