Package org.apache.bookkeeper.meta
Class AbstractZkLedgerManager
- java.lang.Object
-
- org.apache.bookkeeper.meta.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractZkLedgerManager.CancelWatchLedgerMetadataTask
CancelWatchLedgerMetadataTask class.protected class
AbstractZkLedgerManager.ReadLedgerMetadataTask
ReadLedgerMetadataTask class.-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.meta.LedgerManager
LedgerManager.LedgerRange, LedgerManager.LedgerRangeIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected AbstractConfiguration
conf
protected java.lang.String
ledgerRootPath
protected java.util.concurrent.ConcurrentMap<java.lang.Long,java.util.Set<BookkeeperInternalCallbacks.LedgerMetadataListener>>
listeners
protected java.util.concurrent.ScheduledExecutorService
scheduler
protected org.apache.zookeeper.ZooKeeper
zk
(package private) static int
ZK_CONNECT_BACKOFF_MS
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractZkLedgerManager(AbstractConfiguration conf, org.apache.zookeeper.ZooKeeper zk)
ZooKeeper-based Ledger Manager Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.void
close()
java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>>
createLedgerMetadata(long ledgerId, LedgerMetadata inputMetadata)
Create a new ledger with provided ledger id and metadata.protected abstract long
getLedgerId(java.lang.String ledgerPath)
Get ledger id from its znode ledger path.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).abstract java.lang.String
getLedgerPath(long ledgerId)
Get the znode path that is used to store ledger metadata.static boolean
isLeadgerIdGeneratorZnode(java.lang.String znode)
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).static boolean
isSpecialZnode(java.lang.String znode)
Whether the znode a special znode.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.void
process(org.apache.zookeeper.WatchedEvent event)
java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>>
readLedgerMetadata(long ledgerId)
Read ledger metadata of a specified ledger.protected java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>>
readLedgerMetadata(long ledgerId, org.apache.zookeeper.Watcher watcher)
void
registerLedgerMetadataListener(long ledgerId, BookkeeperInternalCallbacks.LedgerMetadataListener listener)
Register the ledger metadata listener on ledgerId.java.util.concurrent.CompletableFuture<java.lang.Void>
removeLedgerMetadata(long ledgerId, Version version)
Remove a specified ledger metadata by ledgerId and version.void
unregisterLedgerMetadataListener(long ledgerId, BookkeeperInternalCallbacks.LedgerMetadataListener listener)
Unregister the ledger metadata listener on ledgerId.java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>>
writeLedgerMetadata(long ledgerId, LedgerMetadata metadata, Version currentVersion)
Write ledger metadata.-
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.meta.LedgerManager
asyncProcessLedgers, getLedgerRanges
-
-
-
-
Field Detail
-
ZK_CONNECT_BACKOFF_MS
static final int ZK_CONNECT_BACKOFF_MS
- See Also:
- Constant Field Values
-
conf
protected final AbstractConfiguration conf
-
zk
protected final org.apache.zookeeper.ZooKeeper zk
-
ledgerRootPath
protected final java.lang.String ledgerRootPath
-
listeners
protected final java.util.concurrent.ConcurrentMap<java.lang.Long,java.util.Set<BookkeeperInternalCallbacks.LedgerMetadataListener>> listeners
-
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 objectzk
- 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 interfaceorg.apache.zookeeper.Watcher
-
createLedgerMetadata
public java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>> createLedgerMetadata(long ledgerId, LedgerMetadata inputMetadata)
Description copied from interface:LedgerManager
Create a new ledger with provided ledger id and metadata.- Specified by:
createLedgerMetadata
in interfaceLedgerManager
- Parameters:
ledgerId
- Ledger id provided to be createdinputMetadata
- Metadata provided when creating the new ledger- Returns:
- Future which, when completed returns the metadata of the newly created ledger.
Completed with an exception:
BKException.BKLedgerExistException
if given ledger id existBKException.ZKException
/BKException.BKMetadataSerializationException
for other issues
-
removeLedgerMetadata
public java.util.concurrent.CompletableFuture<java.lang.Void> removeLedgerMetadata(long ledgerId, Version version)
Description copied from interface:LedgerManager
Remove a specified ledger metadata by ledgerId and version.- Specified by:
removeLedgerMetadata
in interfaceLedgerManager
- Parameters:
ledgerId
- Ledger Idversion
- Ledger metadata version- Returns:
- Future which, when completed, denotes that the ledger metadata has been removed.
Completed with an exception:
BKException.BKMetadataVersionException
if version doesn't matchBKException.BKNoSuchLedgerExistsOnMetadataServerException
if ledger not existBKException.ZKException
for other issues
-
registerLedgerMetadataListener
public void registerLedgerMetadataListener(long ledgerId, BookkeeperInternalCallbacks.LedgerMetadataListener listener)
Description copied from interface:LedgerManager
Register the ledger metadata listener on ledgerId.- Specified by:
registerLedgerMetadataListener
in interfaceLedgerManager
- Parameters:
ledgerId
- ledger id.listener
- listener.
-
unregisterLedgerMetadataListener
public void unregisterLedgerMetadataListener(long ledgerId, BookkeeperInternalCallbacks.LedgerMetadataListener listener)
Description copied from interface:LedgerManager
Unregister the ledger metadata listener on ledgerId.- Specified by:
unregisterLedgerMetadataListener
in interfaceLedgerManager
- Parameters:
ledgerId
- ledger id.listener
- ledger metadata listener.
-
readLedgerMetadata
public java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>> readLedgerMetadata(long ledgerId)
Description copied from interface:LedgerManager
Read ledger metadata of a specified ledger.- Specified by:
readLedgerMetadata
in interfaceLedgerManager
- Parameters:
ledgerId
- Ledger Id- Returns:
- Future which, when completed, contains the requested versioned metadata.
Completed with an exception::
BKException.BKNoSuchLedgerExistsOnMetadataServerException
if ledger not existBKException.ZKException
for other issues
-
readLedgerMetadata
protected java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>> readLedgerMetadata(long ledgerId, org.apache.zookeeper.Watcher watcher)
-
writeLedgerMetadata
public java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>> writeLedgerMetadata(long ledgerId, LedgerMetadata metadata, Version currentVersion)
Description copied from interface:LedgerManager
Write ledger metadata.- Specified by:
writeLedgerMetadata
in interfaceLedgerManager
- Parameters:
ledgerId
- Ledger Idmetadata
- Ledger Metadata to writecurrentVersion
- The version of the metadata we expect to be overwriting.- Returns:
- Future which, when completed, contains the newly written metadata.
Completed with an exception:
BKException.BKMetadataVersionException
if version in metadata doesn't matchBKException.ZKException
for other issue
-
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 ledgersprocessor
- Processor provided to process ledgerfinalCb
- Callback object when all ledgers are processedctx
- Context object passed to finalCbsuccessRc
- RC passed to finalCb when all ledgers are processed successfullyfailureRc
- 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 nodespath
- the prefix path of the ledger nodes- Returns:
- ledger id hash set
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-