Warning |
---|
The wiki pages are not used for documentation any more. Please visit http://bookkeeper.apache.org/docs/latest/api/overview/ for latest API documentation. |
(this page will contain a description of all the Client API of BookKeeper)
...
Code Block |
---|
try (BookKeeper bookkeeper = BookKeeper.forConfig(new ClientConfiguration()).build(); LedgerHandle ledger = bookkeeper.createLedger(BookKeeper.DigestType.CRC32, "foo".getBytes())) { ledger.addEntry("bar".getBytes()); } |
...
(brief explanation of fencing)
Closing a Ledger
You always have to call LedgerHandle.close(), this operation will ensure the consistency of all metadata of the ledger and will release resources assigned to the ledger, both locally to the client and on Bookies.
Deleting a Ledger
When a Ledger is no more in use it is better to delete it, in order to let all the Bookies release all the resources retained by the ledger. A ledger will also retain resources on ZooKeeper.
The code is simple:
Code Block |
---|
bookkeeper.deleteLedger(id);
|
List ledgers
If you need to discover all the ledgersyou can use the BookKeeperAdmin tool
Code Block |
---|
BookKeeperAdmin admin = new BookKeeperAdmin(bookkeeper);
for (long id : admin.listLedgers()) {
LedgerHandle h = admin.openLedgerNoRecovery(id);
LedgerMetadata meta = admin.getLedgerMetadata(h);
} |
Return Codes