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) class
ReadOnlyLedgerHandle.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 long
addEntry(byte[] data)
Add entry synchronously to an open ledger.long
addEntry(byte[] data, int offset, int length)
Add entry synchronously to an open ledger.void
asyncAddEntry(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.void
asyncAddEntry(byte[] data, AsyncCallback.AddCallback cb, java.lang.Object ctx)
Add entry asynchronously to an open ledger.void
asyncClose(AsyncCallback.CloseCallback cb, java.lang.Object ctx)
Asynchronous close, any adds in flight will return errors.void
asyncReadLastEntry(AsyncCallback.ReadCallback cb, java.lang.Object ctx)
void
close()
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) 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.(package private) void
handleUnrecoverableErrorDuringAdd(int rc)
protected void
initializeWriteHandleState()
void
onChanged(long lid, Versioned<LedgerMetadata> newMetadata)
Triggered each time ledger metadata changed.(package private) void
recover(BookkeeperInternalCallbacks.GenericCallback<java.lang.Void> finalCb)
(package private) void
recover(BookkeeperInternalCallbacks.GenericCallback<java.lang.Void> finalCb, BookkeeperInternalCallbacks.ReadEntryListener listener, boolean forceRecovery)
Recover the ledger.java.lang.String
toString()
-
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.GeneralSecurityException
java.lang.NumberFormatException
-
-
Method Detail
-
close
public void close() throws java.lang.InterruptedException, BKException
Description copied from class:LedgerHandle
Synchronous 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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceHandle
- Specified by:
close
in interfaceWriteHandle
- Overrides:
close
in classLedgerHandle
- Throws:
java.lang.InterruptedException
BKException
- See Also:
Handle.closeAsync()
-
asyncClose
public void asyncClose(AsyncCallback.CloseCallback cb, java.lang.Object ctx)
Description copied from class:LedgerHandle
Asynchronous 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:
asyncClose
in classLedgerHandle
- Parameters:
cb
- callback implementationctx
- control object
-
addEntry
public long addEntry(byte[] data) throws java.lang.InterruptedException, BKException
Description copied from class:LedgerHandle
Add entry synchronously to an open ledger.- Overrides:
addEntry
in 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.InterruptedException
BKException
-
addEntry
public long addEntry(byte[] data, int offset, int length) throws java.lang.InterruptedException, BKException
Description copied from class:LedgerHandle
Add entry synchronously to an open ledger.- Overrides:
addEntry
in 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.InterruptedException
BKException
-
asyncAddEntry
public void asyncAddEntry(byte[] data, AsyncCallback.AddCallback cb, java.lang.Object ctx)
Description copied from class:LedgerHandle
Add entry asynchronously to an open ledger.- Overrides:
asyncAddEntry
in 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:LedgerHandle
Add entry asynchronously to an open ledger, using an offset and range.- Overrides:
asyncAddEntry
in 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.LedgerMetadataListener
Triggered each time ledger metadata changed.- Specified by:
onChanged
in interfaceBookkeeperInternalCallbacks.LedgerMetadataListener
- Parameters:
lid
- ledger id.newMetadata
- new ledger metadata.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
initializeWriteHandleState
protected void initializeWriteHandleState()
- Overrides:
initializeWriteHandleState
in classLedgerHandle
-
asyncReadLastEntry
public void asyncReadLastEntry(AsyncCallback.ReadCallback cb, java.lang.Object ctx)
- Overrides:
asyncReadLastEntry
in 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:
handleBookieFailure
in classLedgerHandle
-
handleUnrecoverableErrorDuringAdd
void handleUnrecoverableErrorDuringAdd(int rc)
- Overrides:
handleUnrecoverableErrorDuringAdd
in 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:LedgerHandle
Get 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:
getCurrentEnsemble
in classLedgerHandle
-
-