/** * Reliably retrieves the LastAddConfirmed for the Ledger with given LedgerId, by opening the Ledger in fencing mode * and getting the value. NOTE: this open-fences the Ledger which will effectively stop any writing action on it. * * @param ledgerId The Id of the Ledger to query. * @param bookKeeper A references to the BookKeeper client to use. * @param config Configuration to use. * @return The LastAddConfirmed for the given LedgerId. * @throws DurableDataLogException If an exception occurred. The causing exception is wrapped inside it. */ static long readLastAddConfirmed(long ledgerId, BookKeeper bookKeeper, BookKeeperConfig config) throws DurableDataLogException { LedgerHandle h = null; try { // Here we open the Ledger WITH recovery, to force BookKeeper to reconcile any appends that may have been // interrupted and not properly acked. Otherwise there is no guarantee we can get an accurate value for // LastAddConfirmed. h = openFence(ledgerId, bookKeeper, config); return h.getLastAddConfirmed(); } finally { if (h != null) { close(h); } } }
while (iterator.hasPrevious() && (nonEmptyCount < MIN_FENCE_LEDGER_COUNT)) { LedgerMetadata ledgerMetadata = iterator.previous(); LedgerHandle handle = openFence(ledgerMetadata.getLedgerId(), bookKeeper, config); if (handle.getLastAddConfirmed() != NO_ENTRY_ID) {
if (shouldExist.test(i)) { Ledgers.openFence(e.getKey(), this.factory.get().getBookKeeperClient(), this.config.get()); } else { AssertExtensions.assertThrows( "Ledger not deleted from BookKeeper.", () -> Ledgers.openFence(e.getKey(), this.factory.get().getBookKeeperClient(), this.config.get()), ex -> true);
ledger = Ledgers.openFence(metadata.getLedgerId(), this.bookKeeper, this.config);