Class LongZkLedgerIdGenerator
- All Implemented Interfaces:
Closeable,AutoCloseable,LedgerIdGenerator
In order to support the full range of the long ledgerId, once ledgerIds reach Integer.MAX_INT, a new system is employed. The 32 most significant bits of the ledger ID are taken and turned into a directory prefixed with HOB- under (ledgerIdGenPath)
Under this HOB- directory, zookeeper is used to continue generating EPHEMERAL_SEQUENTIAL ids which constitute the lower 32-bits of the ledgerId (sign bit is always 0). Once the HOB- directory runs out of available ids, the process is repeated. The higher bits are incremented, a new HOB- directory is created, and zookeeper generates sequential ids underneath it.
The reason for treating ids which are less than Integer.MAX_INT differently is to maintain backwards compatibility. This is a drop-in replacement for ZkLedgerIdGenerator.
-
Constructor Summary
ConstructorsConstructorDescriptionLongZkLedgerIdGenerator(org.apache.zookeeper.ZooKeeper zk, String ledgersPath, String idGenZnodeName, ZkLedgerIdGenerator shortIdGen, List<org.apache.zookeeper.data.ACL> zkAcls) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidGenerate a global unique ledger id.voidbooleanledgerIdGenPathPresent(org.apache.zookeeper.ZooKeeper zk) Checks the existence of the long ledger id gen path.
-
Constructor Details
-
LongZkLedgerIdGenerator
public LongZkLedgerIdGenerator(org.apache.zookeeper.ZooKeeper zk, String ledgersPath, String idGenZnodeName, ZkLedgerIdGenerator shortIdGen, List<org.apache.zookeeper.data.ACL> zkAcls)
-
-
Method Details
-
invalidateLedgerIdGenPathStatus
public void invalidateLedgerIdGenPathStatus() -
ledgerIdGenPathPresent
public boolean ledgerIdGenPathPresent(org.apache.zookeeper.ZooKeeper zk) throws org.apache.zookeeper.KeeperException, InterruptedException Checks the existence of the long ledger id gen path. Existence indicates we have switched from the legacy algorithm to the new method of generating 63-bit ids. If the existence is UNKNOWN, it looks in zk to find out. If it previously checked in zk, it returns that value. This value changes when we run out of ids < Integer.MAX_VALUE, and try to create the long ledger id gen path.- Parameters:
zk-- Returns:
- Does the long ledger id gen path exist?
- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException- See Also:
-
createLongLedgerIdPathAndGenerateLongLedgerId(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<java.lang.Long>,java.lang.String)
-
generateLedgerId
Description copied from interface:LedgerIdGeneratorGenerate a global unique ledger id.- Specified by:
generateLedgerIdin interfaceLedgerIdGenerator- Parameters:
cb- Callback when a new ledger id is generated, return code:BKException.Code.OKif successBKException.Code.ZKExceptionwhen can't generate new ledger id
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-