Class ReadOnlyLedgerHandle
- java.lang.Object
-
- org.apache.bookkeeper.client.LedgerHandle
-
- org.apache.bookkeeper.client.ReadOnlyLedgerHandle
-
- All Implemented Interfaces:
java.lang.AutoCloseable,ForceableHandle,Handle,ReadHandle,WriteHandle,BookkeeperInternalCallbacks.LedgerMetadataListener
class ReadOnlyLedgerHandle extends LedgerHandle implements BookkeeperInternalCallbacks.LedgerMetadataListener
Read only ledger handle. This ledger handle allows you to read from a ledger but not to write to it. It overrides all the public write operations from LedgerHandle. It should be returned for BookKeeper#openLedger operations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classReadOnlyLedgerHandle.MetadataUpdater-
Nested 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
Constructors Constructor Description ReadOnlyLedgerHandle(ClientContext clientCtx, long ledgerId, Versioned<LedgerMetadata> metadata, BookKeeper.DigestType digestType, byte[] password, boolean watch)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddEntry(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, java.lang.Object ctx)Add entry asynchronously to an open ledger, using an offset and range.voidasyncAddEntry(byte[] data, AsyncCallback.AddCallback cb, java.lang.Object ctx)Add entry asynchronously to an open ledger.voidasyncClose(AsyncCallback.CloseCallback cb, java.lang.Object ctx)Asynchronous close, any adds in flight will return errors.voidasyncReadLastEntry(AsyncCallback.ReadCallback cb, java.lang.Object ctx)voidclose()Synchronous close the write handle, any adds in flight will return errors.(package private) java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>>closeRecovered()(package private) java.util.List<BookieId>getCurrentEnsemble()Get the current ensemble from the ensemble list.(package private) voidhandleBookieFailure(java.util.Map<java.lang.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) voidhandleUnrecoverableErrorDuringAdd(int rc)protected voidinitializeWriteHandleState()voidonChanged(long lid, Versioned<LedgerMetadata> newMetadata)Triggered each time ledger metadata changed.(package private) voidrecover(BookkeeperInternalCallbacks.GenericCallback<java.lang.Void> finalCb)(package private) voidrecover(BookkeeperInternalCallbacks.GenericCallback<java.lang.Void> finalCb, BookkeeperInternalCallbacks.ReadEntryListener listener, boolean forceRecovery)Recover the ledger.java.lang.StringtoString()-
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, waitForWritable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.bookkeeper.client.api.ReadHandle
batchRead, read, readLastAddConfirmed, readLastAddConfirmedAndEntry, readUnconfirmed, tryReadLastAddConfirmed
-
Methods inherited from interface org.apache.bookkeeper.client.api.WriteHandle
append, append, append, append, appendAsync, appendAsync, appendAsync
-
-
-
-
Constructor Detail
-
ReadOnlyLedgerHandle
ReadOnlyLedgerHandle(ClientContext clientCtx, long ledgerId, Versioned<LedgerMetadata> metadata, BookKeeper.DigestType digestType, byte[] password, boolean watch) throws java.security.GeneralSecurityException, java.lang.NumberFormatException
- Throws:
java.security.GeneralSecurityExceptionjava.lang.NumberFormatException
-
-
Method Detail
-
close
public void close() throws java.lang.InterruptedException, BKExceptionDescription 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 interfacejava.lang.AutoCloseable- Specified by:
closein interfaceHandle- Specified by:
closein interfaceWriteHandle- Overrides:
closein classLedgerHandle- Throws:
java.lang.InterruptedExceptionBKException- See Also:
Handle.closeAsync()
-
asyncClose
public void asyncClose(AsyncCallback.CloseCallback cb, java.lang.Object ctx)
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
public long addEntry(byte[] data) throws java.lang.InterruptedException, BKExceptionDescription 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:
java.lang.InterruptedExceptionBKException
-
addEntry
public long addEntry(byte[] data, int offset, int length) throws java.lang.InterruptedException, BKExceptionDescription 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:
java.lang.InterruptedExceptionBKException
-
asyncAddEntry
public void asyncAddEntry(byte[] data, AsyncCallback.AddCallback cb, java.lang.Object ctx)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, java.lang.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
public void onChanged(long lid, Versioned<LedgerMetadata> newMetadata)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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
initializeWriteHandleState
protected void initializeWriteHandleState()
- Overrides:
initializeWriteHandleStatein classLedgerHandle
-
asyncReadLastEntry
public void asyncReadLastEntry(AsyncCallback.ReadCallback cb, java.lang.Object ctx)
- Overrides:
asyncReadLastEntryin classLedgerHandle
-
handleBookieFailure
void handleBookieFailure(java.util.Map<java.lang.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. 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
void recover(BookkeeperInternalCallbacks.GenericCallback<java.lang.Void> finalCb)
-
recover
void recover(BookkeeperInternalCallbacks.GenericCallback<java.lang.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
java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>> closeRecovered()
-
getCurrentEnsemble
java.util.List<BookieId> 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
-
-