Package org.apache.bookkeeper.meta
Class ZkLedgerIdGenerator
- java.lang.Object
-
- org.apache.bookkeeper.meta.ZkLedgerIdGenerator
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,LedgerIdGenerator
public class ZkLedgerIdGenerator extends java.lang.Object implements LedgerIdGenerator
ZooKeeper based ledger id generator class, which using EPHEMERAL_SEQUENTIAL with (ledgerIdGenPath)/ID- prefix to generate ledger id. Note zookeeper sequential counter has a format of %10d -- that is 10 digits with 0 (zero) padding, i.e. "<path>0000000001", so ledger id space is fundamentally limited to 9 billion.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
LEDGER_ID_GEN_PREFIX
(package private) java.lang.String
ledgerPrefix
(package private) static org.slf4j.Logger
LOG
(package private) org.apache.zookeeper.ZooKeeper
zk
(package private) java.util.List<org.apache.zookeeper.data.ACL>
zkAcls
-
Constructor Summary
Constructors Constructor Description ZkLedgerIdGenerator(org.apache.zookeeper.ZooKeeper zk, java.lang.String ledgersPath, java.lang.String idGenZnodeName, java.util.List<org.apache.zookeeper.data.ACL> zkAcls)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static java.lang.String
createLedgerPrefix(java.lang.String ledgersPath, java.lang.String idGenZnodeName)
void
generateLedgerId(BookkeeperInternalCallbacks.GenericCallback<java.lang.Long> cb)
Generate a global unique ledger id.static void
generateLedgerIdImpl(BookkeeperInternalCallbacks.GenericCallback<java.lang.Long> cb, org.apache.zookeeper.ZooKeeper zk, java.lang.String ledgerPrefix, java.util.List<org.apache.zookeeper.data.ACL> zkAcls)
-
-
-
Field Detail
-
LOG
static final org.slf4j.Logger LOG
-
LEDGER_ID_GEN_PREFIX
static final java.lang.String LEDGER_ID_GEN_PREFIX
- See Also:
- Constant Field Values
-
zk
final org.apache.zookeeper.ZooKeeper zk
-
ledgerPrefix
final java.lang.String ledgerPrefix
-
zkAcls
final java.util.List<org.apache.zookeeper.data.ACL> zkAcls
-
-
Method Detail
-
createLedgerPrefix
public static java.lang.String createLedgerPrefix(java.lang.String ledgersPath, java.lang.String idGenZnodeName)
-
generateLedgerId
public void generateLedgerId(BookkeeperInternalCallbacks.GenericCallback<java.lang.Long> cb)
Description copied from interface:LedgerIdGenerator
Generate a global unique ledger id.- Specified by:
generateLedgerId
in interfaceLedgerIdGenerator
- Parameters:
cb
- Callback when a new ledger id is generated, return code:BKException.Code.OK
if successBKException.Code.ZKException
when can't generate new ledger id
-
generateLedgerIdImpl
public static void generateLedgerIdImpl(BookkeeperInternalCallbacks.GenericCallback<java.lang.Long> cb, org.apache.zookeeper.ZooKeeper zk, java.lang.String ledgerPrefix, java.util.List<org.apache.zookeeper.data.ACL> zkAcls)
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-