Class ReadOnlyLedgerHandle
- All Implemented Interfaces:
AutoCloseable,ForceableHandle,Handle,ReadHandle,WriteHandle,BookkeeperInternalCallbacks.LedgerMetadataListener
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.bookkeeper.client.LedgerHandle
LedgerHandle.LastConfirmedCtx, LedgerHandle.NoopCloseCallback -
Field Summary
Fields inherited from class org.apache.bookkeeper.client.LedgerHandle
bookieFailureHistory, bookiesHealthInfo, changingEnsemble, clientCtx, delayedWriteFailedBookies, distributionSchedule, ensembleChangeCounter, executor, explicitLacFlushPolicy, INVALID_ENTRY_ID, INVALID_LEDGER_ID, lacUpdateHitsCounter, lacUpdateMissesCounter, lastAddConfirmed, lastAddPushed, ledgerId, ledgerKey, length, macManager, notSupportBatch, numEnsembleChanges, pendingAddOps, pendingAddsSequenceHead, throttler, timeoutFuture, writeFlags -
Constructor Summary
ConstructorsConstructorDescriptionReadOnlyLedgerHandle(ClientContext clientCtx, long ledgerId, Versioned<LedgerMetadata> metadata, BookKeeper.DigestType digestType, byte[] password, boolean watchImmediately) -
Method Summary
Modifier and TypeMethodDescriptionlongaddEntry(byte[] data) Add entry synchronously to an open ledger.longaddEntry(byte[] data, int offset, int length) Add entry synchronously to an open ledger.voidasyncAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx) Add entry asynchronously to an open ledger, using an offset and range.voidasyncAddEntry(byte[] data, AsyncCallback.AddCallback cb, Object ctx) Add entry asynchronously to an open ledger.voidasyncClose(AsyncCallback.CloseCallback cb, Object ctx) Asynchronous close, any adds in flight will return errors.voidvoidclose()Synchronous close the write handle, any adds in flight will return errors.(package private) CompletableFuture<Versioned<LedgerMetadata>>Get the current ensemble from the ensemble list.(package private) voidhandleBookieFailure(Map<Integer, BookieId> failedBookies) For a read only ledger handle, this method will only ever be called during recovery, when we are reading forward from LAC and writing back those entries.(package private) voidprotected voidvoidonChanged(long lid, Versioned<LedgerMetadata> newMetadata) Triggered each time ledger metadata changed.(package private) void(package private) voidrecover(BookkeeperInternalCallbacks.GenericCallback<Void> finalCb, BookkeeperInternalCallbacks.ReadEntryListener listener, boolean forceRecovery) Recover the ledger.(package private) voidtoString()Methods inherited from class org.apache.bookkeeper.client.LedgerHandle
addEntry, addEntry, addToLength, appendAsync, asyncAddEntry, asyncAddEntry, asyncAddEntry, asyncAddEntry, asyncAddEntry, asyncBatchReadEntries, asyncBatchReadEntriesInternal, asyncBatchReadUnconfirmedEntries, asyncCloseInternal, asyncReadEntries, asyncReadEntriesInternal, asyncReadExplicitLastConfirmed, asyncReadLastConfirmed, asyncReadLastConfirmedAndEntry, asyncReadUnconfirmedEntries, asyncRecoveryAddEntry, asyncTryReadLastConfirmed, batchReadAsync, batchReadEntries, batchReadUnconfirmedEntries, closeAsync, doAsyncAddEntry, doAsyncCloseInternal, drainPendingAddsAndAdjustLength, ensembleChangeLoop, errorOutPendingAdds, errorOutPendingAdds, executeOrdered, force, getBookiesHealthInfo, getCtime, getCustomMetadata, getDigestManager, getDistributionSchedule, getId, getLastAddConfirmed, getLastAddPushed, getLedgerKey, getLedgerMetadata, getLength, getNumBookies, getNumFragments, getPendingAddOps, getVersionedLedgerMetadata, getWriteFlags, getWriteSetForReadOperation, hasDelayedWriteFailedBookies, isClosed, isHandleWritable, maybeHandleDelayedWriteBookieFailure, notifyWriteFailed, readAsync, readEntries, readEntriesInternalAsync, readExplicitLastConfirmed, readLastAddConfirmedAndEntryAsync, readLastAddConfirmedAsync, readLastConfirmed, readLastEntry, readUnconfirmedAsync, readUnconfirmedEntries, recordReadErrorOnBookie, registerOperationFailureOnBookie, sendAddSuccessCallbacks, setLastAddConfirmed, setLedgerMetadata, tryReadLastAddConfirmedAsync, tryReadLastConfirmed, unsetSuccessAndSendWriteRequest, updateLastConfirmed, waitForWritableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.bookkeeper.client.api.ReadHandle
batchRead, read, readLastAddConfirmed, readLastAddConfirmedAndEntry, readUnconfirmed, tryReadLastAddConfirmedMethods inherited from interface org.apache.bookkeeper.client.api.WriteHandle
append, append, append, append, appendAsync, appendAsync, appendAsync
-
Constructor Details
-
ReadOnlyLedgerHandle
ReadOnlyLedgerHandle(ClientContext clientCtx, long ledgerId, Versioned<LedgerMetadata> metadata, BookKeeper.DigestType digestType, byte[] password, boolean watchImmediately) throws GeneralSecurityException, NumberFormatException
-
-
Method Details
-
registerLedgerMetadataListener
void registerLedgerMetadataListener() -
close
Description copied from class:LedgerHandleSynchronous close the write handle, any adds in flight will return errors.Closing a ledger will ensure that all clients agree on what the last entry of the ledger is. Once the ledger has been closed, all reads from the ledger will return the same set of entries.
The close operation can error if it finds conflicting metadata when it tries to write to the metadata store. On close, the metadata state is set to closed and lastEntry and length of the ledger are fixed in the metadata. A conflict occurs if the metadata in the metadata store has a different value for the lastEntry or length. If another process has updated the metadata, setting it to closed, but have fixed the lastEntry and length to the same values as this process is trying to write, the operation completes successfully.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceHandle- Specified by:
closein interfaceWriteHandle- Overrides:
closein classLedgerHandle- Throws:
InterruptedExceptionBKException- See Also:
-
asyncClose
Description copied from class:LedgerHandleAsynchronous close, any adds in flight will return errors.Closing a ledger will ensure that all clients agree on what the last entry of the ledger is. This ensures that, once the ledger has been closed, all reads from the ledger will return the same set of entries.
- Overrides:
asyncClosein classLedgerHandle- Parameters:
cb- callback implementationctx- control object
-
addEntry
Description copied from class:LedgerHandleAdd entry synchronously to an open ledger.- Overrides:
addEntryin classLedgerHandle- Parameters:
data- array of bytes to be written to the ledger do not reuse the buffer, bk-client will release it appropriately- Returns:
- the entryId of the new inserted entry
- Throws:
InterruptedExceptionBKException
-
addEntry
Description copied from class:LedgerHandleAdd entry synchronously to an open ledger.- Overrides:
addEntryin classLedgerHandle- Parameters:
data- array of bytes to be written to the ledger do not reuse the buffer, bk-client will release it appropriatelyoffset- offset from which to take bytes from datalength- number of bytes to take from data- Returns:
- the entryId of the new inserted entry
- Throws:
InterruptedExceptionBKException
-
asyncAddEntry
Description copied from class:LedgerHandleAdd entry asynchronously to an open ledger.- Overrides:
asyncAddEntryin classLedgerHandle- Parameters:
data- array of bytes to be written do not reuse the buffer, bk-client will release it appropriatelycb- object implementing callbackinterfacectx- some control object
-
asyncAddEntry
public void asyncAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx) Description copied from class:LedgerHandleAdd entry asynchronously to an open ledger, using an offset and range.- Overrides:
asyncAddEntryin classLedgerHandle- Parameters:
data- array of bytes to be written do not reuse the buffer, bk-client will release it appropriatelyoffset- offset from which to take bytes from datalength- number of bytes to take from datacb- object implementing callbackinterfacectx- some control object
-
onChanged
Description copied from interface:BookkeeperInternalCallbacks.LedgerMetadataListenerTriggered each time ledger metadata changed.- Specified by:
onChangedin interfaceBookkeeperInternalCallbacks.LedgerMetadataListener- Parameters:
lid- ledger id.newMetadata- new ledger metadata.
-
toString
-
initializeWriteHandleState
protected void initializeWriteHandleState()- Overrides:
initializeWriteHandleStatein classLedgerHandle
-
asyncReadLastEntry
- Overrides:
asyncReadLastEntryin classLedgerHandle
-
handleBookieFailure
For a read only ledger handle, this method will only ever be called during recovery, when we are reading forward from LAC and writing back those entries. As such, unlike with LedgerHandle, we do not want to persist changes to the metadata as they occur, but rather, we want to defer the persistence until recovery has completed, and do it all on the close.- Overrides:
handleBookieFailurein classLedgerHandle
-
handleUnrecoverableErrorDuringAdd
void handleUnrecoverableErrorDuringAdd(int rc) - Overrides:
handleUnrecoverableErrorDuringAddin classLedgerHandle
-
recover
-
recover
void recover(BookkeeperInternalCallbacks.GenericCallback<Void> finalCb, BookkeeperInternalCallbacks.ReadEntryListener listener, boolean forceRecovery) Recover the ledger.- Parameters:
finalCb- callback after recovery is done.listener- read entry listener on recovery reads.forceRecovery- force the recovery procedure even the ledger metadata shows the ledger is closed.
-
closeRecovered
CompletableFuture<Versioned<LedgerMetadata>> closeRecovered() -
getCurrentEnsemble
Description copied from class:LedgerHandleGet the current ensemble from the ensemble list. The current ensemble is the last ensemble in the list. The ledger handle uses this ensemble when triggering operations which work on the end of the ledger, such as adding new entries or reading the last add confirmed.This method is also used by ReadOnlyLedgerHandle during recovery, and when tailing a ledger.
Generally, this method should only be called by LedgerHandle and not by the operations themselves, to avoid adding more dependencies between the classes. There are too many already.
- Overrides:
getCurrentEnsemblein classLedgerHandle
-