Class LedgerHandle
- All Implemented Interfaces:
AutoCloseable,ForceableHandle,Handle,ReadHandle,WriteHandle
- Direct Known Subclasses:
LedgerHandleAdv,ReadOnlyLedgerHandle
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classContext objects for synchronous call to read last confirmed.(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final BookiesHealthInfo(package private) boolean(package private) final ClientContext(package private) final DistributionSchedule(package private) final Counter(package private) final ExecutorService(package private) ExplicitLacFlushPolicystatic final longInvalid entry id.static final longInvalid ledger id.(package private) final Counter(package private) final Counter(package private) longLast entryId which has been confirmed to be written durably to the bookies.(package private) long(package private) final long(package private) final byte[](package private) final AtomicLong(package private) static final org.slf4j.Logger(package private) final DigestManager(package private) final Object(package private) boolean(package private) final AtomicInteger(package private) Queue<PendingAddOp>(package private) longNext entryId which is expected to move forward duringsendAddSuccessCallbacks().(package private) final com.google.common.util.concurrent.RateLimiter(package private) ScheduledFuture<?> -
Constructor Summary
ConstructorsConstructorDescriptionLedgerHandle(ClientContext clientCtx, long ledgerId, Versioned<LedgerMetadata> versionedMetadata, BookKeeper.DigestType digestType, byte[] password, EnumSet<WriteFlag> writeFlags) -
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.longaddEntry(long entryId, byte[] data) Add entry synchronously to an open ledger.longaddEntry(long entryId, byte[] data, int offset, int length) Add entry synchronously to an open ledger.(package private) longaddToLength(long delta) Add to the length of the ledger in bytes.appendAsync(io.netty.buffer.ByteBuf data) Add entry asynchronously 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.voidasyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx) Add entry asynchronously to an open ledger, using an offset and range.voidasyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallbackWithLatency cb, Object ctx) Add entry asynchronously to an open ledger, using an offset and range.voidasyncAddEntry(long entryId, byte[] data, AsyncCallback.AddCallback cb, Object ctx) Add entry asynchronously to an open ledger.voidasyncAddEntry(long entryId, io.netty.buffer.ByteBuf data, AsyncCallback.AddCallbackWithLatency cb, Object ctx) Add entry asynchronously to an open ledger, using an offset and range.voidasyncAddEntry(io.netty.buffer.ByteBuf data, AsyncCallback.AddCallback cb, Object ctx) voidasyncBatchReadEntries(long startEntry, int maxCount, long maxSize, AsyncCallback.ReadCallback cb, Object ctx) Read a sequence of entries in asynchronously.(package private) voidasyncBatchReadEntriesInternal(long startEntry, int maxCount, long maxSize, AsyncCallback.ReadCallback cb, Object ctx, boolean isRecoveryRead) voidasyncBatchReadUnconfirmedEntries(long startEntry, int maxCount, long maxSize, AsyncCallback.ReadCallback cb, Object ctx) Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range.voidasyncClose(AsyncCallback.CloseCallback cb, Object ctx) Asynchronous close, any adds in flight will return errors.(package private) voidasyncCloseInternal(AsyncCallback.CloseCallback cb, Object ctx, int rc) voidasyncReadEntries(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, Object ctx) Read a sequence of entries asynchronously.(package private) voidasyncReadEntriesInternal(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, Object ctx, boolean isRecoveryRead) voidObtains asynchronously the explicit last add confirmed from a quorum of bookies.voidObtains asynchronously the last confirmed write from a quorum of bookies.voidasyncReadLastConfirmedAndEntry(long entryId, long timeOutInMillis, boolean parallel, AsyncCallback.ReadLastConfirmedAndEntryCallback cb, Object ctx) Asynchronous read next entry and the latest last add confirmed.voidvoidasyncReadUnconfirmedEntries(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, Object ctx) Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range.(package private) voidasyncRecoveryAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx) Make a recovery add entry request.voidObtains asynchronously the last confirmed write from a quorum of bookies.batchReadAsync(long startEntry, int maxCount, long maxSize) Read a sequence of entries in asynchronously.batchReadEntries(long startEntry, int maxCount, long maxSize) Read a sequence of entries synchronously.batchReadUnconfirmedEntries(long firstEntry, int maxCount, long maxSize) Read a sequence of entries synchronously, allowing to read after the LastAddConfirmed range.
This is the same ofasyncBatchReadUnconfirmedEntries(long, int, long, ReadCallback, Object)voidclose()Synchronous close the write handle, any adds in flight will return errors.Asynchronous close the write handle, any adds in flight will return errors.protected void(package private) voiddoAsyncCloseInternal(AsyncCallback.CloseCallback cb, Object ctx, int rc) Same as public version of asyncClose except that this one takes an additional parameter which is the return code to hand to all the pending add ops.(package private) List<PendingAddOp>(package private) void(package private) voiderrorOutPendingAdds(int rc) (package private) voiderrorOutPendingAdds(int rc, List<PendingAddOp> ops) (package private) voidexecuteOrdered(Runnable runnable) Execute the callback in the thread pinned to the ledger.force()Enforce durability to the entries written by this handle.(package private) BookiesHealthInfoGet the health info for bookies for this ledger.longgetCtime()Returns the ledger creation time.Get the current ensemble from the ensemble list.Get this ledger's customMetadata map.(package private) DigestManagerGet the DigestManager.(package private) DistributionScheduleGet the Distribution Schedule.longgetId()Get the id of the current ledger.longGet the last confirmed entry id on this ledger.longGet the entry id of the last entry that has been enqueued for addition (but may not have possibly been persisted to the ledger).byte[]Get the Ledger's key/password.Returns the metadata of this ledger.longReturns the length of the ledger in bytes.longGet the count of unique bookies that own part of this ledger by going over all the fragments of the ledger.longGet the number of fragments that makeup this ledger.(package private) Versioned<LedgerMetadata>(package private) DistributionSchedule.WriteSetgetWriteSetForReadOperation(long entryId) Return aDistributionSchedule.WriteSetsuitable for reading a particular entry.(package private) voidhandleBookieFailure(Map<Integer, BookieId> failedBookies) (package private) void(package private) booleanprotected voidbooleanisClosed()Returns whether the ledger is sealed or not.(package private) boolean(package private) void(package private) voidnotifyWriteFailed(int index, BookieId addr) readAsync(long firstEntry, long lastEntry) Read a sequence of entries asynchronously.readEntries(long firstEntry, long lastEntry) Read a sequence of entries synchronously.(package private) CompletableFuture<LedgerEntries>readEntriesInternalAsync(long firstEntry, long lastEntry, boolean isRecoveryRead) longreadLastAddConfirmedAndEntryAsync(long entryId, long timeOutInMillis, boolean parallel) Asynchronous read specific entry and the latest last add confirmed.Obtains asynchronously the last confirmed write from a quorum of bookies.longObtains synchronously the last confirmed write from a quorum of bookies.readUnconfirmedAsync(long firstEntry, long lastEntry) Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range.readUnconfirmedEntries(long firstEntry, long lastEntry) Read a sequence of entries synchronously, allowing to read after the LastAddConfirmed range.
This is the same ofasyncReadUnconfirmedEntries(long, long, ReadCallback, Object)(package private) voidrecordReadErrorOnBookie(int bookieIndex) Notify the LedgerHandle that a read operation was failed on a particular bookie.(package private) voidregisterOperationFailureOnBookie(BookieId bookie, long entryId) (package private) void(package private) voidsetLastAddConfirmed(long lac) (package private) booleansetLedgerMetadata(Versioned<LedgerMetadata> expected, Versioned<LedgerMetadata> newMetadata) Obtains asynchronously the last confirmed write from a quorum of bookies but it doesn't wait all the responses from the quorum.longObtains synchronously the last confirmed write from a quorum of bookies.(package private) voidunsetSuccessAndSendWriteRequest(List<BookieId> ensemble, Set<Integer> bookies) (package private) voidupdateLastConfirmed(long lac, long len) protected booleanwaitForWritable(DistributionSchedule.WriteSet writeSet, int allowedNonWritableCount, long durationMs) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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
-
Field Details
-
LOG
static final org.slf4j.Logger LOG -
clientCtx
-
ledgerKey
final byte[] ledgerKey -
ledgerId
final long ledgerId -
executor
-
lastAddPushed
long lastAddPushed -
notSupportBatch
boolean notSupportBatch -
lastAddConfirmed
volatile long lastAddConfirmedLast entryId which has been confirmed to be written durably to the bookies. This value is used by readers, the LAC protocol -
pendingAddsSequenceHead
volatile long pendingAddsSequenceHeadNext entryId which is expected to move forward duringsendAddSuccessCallbacks(). This is important in order to have an ordered sequence of addEntry acknowledged to the writer -
length
-
macManager
-
distributionSchedule
-
throttler
final com.google.common.util.concurrent.RateLimiter throttler -
bookieFailureHistory
-
bookiesHealthInfo
-
writeFlags
-
timeoutFuture
ScheduledFuture<?> timeoutFuture -
delayedWriteFailedBookies
-
INVALID_ENTRY_ID
public static final long INVALID_ENTRY_IDInvalid entry id. This value is returned from methods which should return an entry id but there is no valid entry available.- See Also:
-
INVALID_LEDGER_ID
public static final long INVALID_LEDGER_IDInvalid ledger id. Ledger IDs must be greater than or equal to 0. Large negative used to make it easy to spot in logs if erroneously used.- See Also:
-
metadataLock
-
changingEnsemble
boolean changingEnsemble -
numEnsembleChanges
-
pendingAddOps
Queue<PendingAddOp> pendingAddOps -
explicitLacFlushPolicy
ExplicitLacFlushPolicy explicitLacFlushPolicy -
ensembleChangeCounter
-
lacUpdateHitsCounter
-
lacUpdateMissesCounter
-
-
Constructor Details
-
LedgerHandle
LedgerHandle(ClientContext clientCtx, long ledgerId, Versioned<LedgerMetadata> versionedMetadata, BookKeeper.DigestType digestType, byte[] password, EnumSet<WriteFlag> writeFlags) throws GeneralSecurityException, NumberFormatException
-
-
Method Details
-
recordReadErrorOnBookie
void recordReadErrorOnBookie(int bookieIndex) Notify the LedgerHandle that a read operation was failed on a particular bookie. -
initializeWriteHandleState
protected void initializeWriteHandleState() -
getId
public long getId()Get the id of the current ledger. -
getWriteFlags
-
getLastAddConfirmed
public long getLastAddConfirmed()Get the last confirmed entry id on this ledger. It reads the local state of the ledger handle, which is different from theReadHandle.readLastAddConfirmed()call.In the case the ledger is not closed and the client is a reader, it is necessary to call
ReadHandle.readLastAddConfirmed()to obtain a fresh value of last add confirmed entry id.- Specified by:
getLastAddConfirmedin interfaceReadHandle- Returns:
- the local value for LastAddConfirmed or -1L if no entry has been confirmed.
- See Also:
-
setLastAddConfirmed
void setLastAddConfirmed(long lac) -
getLastAddPushed
public long getLastAddPushed()Get the entry id of the last entry that has been enqueued for addition (but may not have possibly been persisted to the ledger).- Specified by:
getLastAddPushedin interfaceWriteHandle- Returns:
- the entry id of the last entry pushed or -1 if no entry has been pushed
-
getLedgerKey
public byte[] getLedgerKey()Get the Ledger's key/password.- Returns:
- byte array for the ledger's key/password.
-
getLedgerMetadata
Returns the metadata of this ledger.This call only retrieves the metadata cached locally. If there is any metadata updated, the read handle will receive the metadata updates and update the metadata locally. The metadata notification can be deplayed, so it is possible you can receive a stale copy of ledger metadata from this call.
- Specified by:
getLedgerMetadatain interfaceHandle- Returns:
- the metadata of this ledger.
-
getVersionedLedgerMetadata
Versioned<LedgerMetadata> getVersionedLedgerMetadata() -
setLedgerMetadata
boolean setLedgerMetadata(Versioned<LedgerMetadata> expected, Versioned<LedgerMetadata> newMetadata) -
getCustomMetadata
Get this ledger's customMetadata map.- Returns:
- map containing user provided customMetadata.
-
getNumFragments
public long getNumFragments()Get the number of fragments that makeup this ledger.- Returns:
- the count of fragments
-
getNumBookies
public long getNumBookies()Get the count of unique bookies that own part of this ledger by going over all the fragments of the ledger.- Returns:
- count of unique bookies
-
getDigestManager
DigestManager getDigestManager()Get the DigestManager.- Returns:
- DigestManager for the LedgerHandle
-
addToLength
long addToLength(long delta) Add to the length of the ledger in bytes.- Parameters:
delta-- Returns:
- the length of the ledger after the addition
-
getLength
public long getLength()Returns the length of the ledger in bytes.- Specified by:
getLengthin interfaceReadHandle- Returns:
- the length of the ledger in bytes
-
getCtime
public long getCtime()Returns the ledger creation time.- Returns:
- the ledger creation time
-
getDistributionSchedule
DistributionSchedule getDistributionSchedule()Get the Distribution Schedule.- Returns:
- DistributionSchedule for the LedgerHandle
-
getBookiesHealthInfo
BookiesHealthInfo getBookiesHealthInfo()Get the health info for bookies for this ledger.- Returns:
- BookiesHealthInfo for every bookie in the write set.
-
close
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceHandle- Specified by:
closein interfaceWriteHandle- Throws:
InterruptedExceptionBKException- See Also:
-
closeAsync
Asynchronous 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:
closeAsyncin interfaceHandle- Specified by:
closeAsyncin interfaceWriteHandle- Returns:
- an handle to access the result of the operation
-
asyncClose
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.
- Parameters:
cb- callback implementationctx- control object
-
isClosed
public boolean isClosed()Returns whether the ledger is sealed or not.A ledger is sealed when either the client explicitly closes it (
WriteHandle.close()orHandle.close()) or another client explicitly open and recovery itOpenBuilder.withRecovery(boolean).This method only checks the metadata cached locally. The metadata can be not update-to-date because the metadata notification is delayed.
- Specified by:
isClosedin interfaceReadHandle- Returns:
- true if the ledger is sealed, otherwise false.
-
isHandleWritable
boolean isHandleWritable() -
asyncCloseInternal
-
doAsyncCloseInternal
Same as public version of asyncClose except that this one takes an additional parameter which is the return code to hand to all the pending add ops.- Parameters:
cb-ctx-rc-
-
readEntries
public Enumeration<LedgerEntry> readEntries(long firstEntry, long lastEntry) throws InterruptedException, BKException Read a sequence of entries synchronously.- Parameters:
firstEntry- id of first entry of sequence (included)lastEntry- id of last entry of sequence (included)- Throws:
InterruptedExceptionBKException- See Also:
-
batchReadEntries
public Enumeration<LedgerEntry> batchReadEntries(long startEntry, int maxCount, long maxSize) throws InterruptedException, BKException Read a sequence of entries synchronously.- Parameters:
startEntry- start entry idmaxCount- the total entries count.maxSize- the total entries size.- Throws:
InterruptedExceptionBKException- See Also:
-
readUnconfirmedEntries
public Enumeration<LedgerEntry> readUnconfirmedEntries(long firstEntry, long lastEntry) throws InterruptedException, BKException Read a sequence of entries synchronously, allowing to read after the LastAddConfirmed range.
This is the same ofasyncReadUnconfirmedEntries(long, long, ReadCallback, Object)- Parameters:
firstEntry- id of first entry of sequence (included)lastEntry- id of last entry of sequence (included)- Throws:
InterruptedExceptionBKException- See Also:
-
batchReadUnconfirmedEntries
public Enumeration<LedgerEntry> batchReadUnconfirmedEntries(long firstEntry, int maxCount, long maxSize) throws InterruptedException, BKException Read a sequence of entries synchronously, allowing to read after the LastAddConfirmed range.
This is the same ofasyncBatchReadUnconfirmedEntries(long, int, long, ReadCallback, Object)- Parameters:
firstEntry- id of first entry of sequence (included)maxCount- id of last entry of sequence (included)maxSize- the total entries size- Throws:
InterruptedExceptionBKException
-
asyncReadEntries
public void asyncReadEntries(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, Object ctx) Read a sequence of entries asynchronously.- Parameters:
firstEntry- id of first entry of sequencelastEntry- id of last entry of sequencecb- object implementing read callback interfacectx- control object
-
asyncBatchReadEntries
public void asyncBatchReadEntries(long startEntry, int maxCount, long maxSize, AsyncCallback.ReadCallback cb, Object ctx) Read a sequence of entries in asynchronously. It send an RPC to get all entries instead of send multi RPC to get all entries.- Parameters:
startEntry- id of first entry of sequencemaxCount- the entries countmaxSize- the total entries sizecb- object implementing read callback interfacectx- control object
-
asyncReadUnconfirmedEntries
public void asyncReadUnconfirmedEntries(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, Object ctx) Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range.
This is the same ofasyncReadEntries(long, long, ReadCallback, Object)but it lets the client read without checking the local value of LastAddConfirmed, so that it is possible to read entries for which the writer has not received the acknowledge yet.
For entries which are within the range 0..LastAddConfirmed BookKeeper guarantees that the writer has successfully received the acknowledge.
For entries outside that range it is possible that the writer never received the acknowledge and so there is the risk that the reader is seeing entries before the writer and this could result in a consistency issue in some cases.
With this method you can even read entries before the LastAddConfirmed and entries after it with one call, the expected consistency will be as described above for each subrange of ids.- Parameters:
firstEntry- id of first entry of sequencelastEntry- id of last entry of sequencecb- object implementing read callback interfacectx- control object- See Also:
-
asyncBatchReadUnconfirmedEntries
public void asyncBatchReadUnconfirmedEntries(long startEntry, int maxCount, long maxSize, AsyncCallback.ReadCallback cb, Object ctx) Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range. It sends an RPC to get all entries instead of send multi RPC to get all entries.- Parameters:
startEntry- id of first entry of sequencemaxCount- the entries countmaxSize- the total entries sizecb- object implementing read callback interfacectx- control object
-
readAsync
Read a sequence of entries asynchronously.- Specified by:
readAsyncin interfaceReadHandle- Parameters:
firstEntry- id of first entry of sequencelastEntry- id of last entry of sequence- Returns:
- an handle to the result of the operation
-
batchReadAsync
Read a sequence of entries in asynchronously. It sends an RPC to get all entries instead of send multi RPC to get all entries.- Specified by:
batchReadAsyncin interfaceReadHandle- Parameters:
startEntry- id of first entry of sequencemaxCount- the entries countmaxSize- the total entries size- Returns:
- an handle to the result of the operation
-
readUnconfirmedAsync
Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range.
This is the same ofasyncReadEntries(long, long, ReadCallback, Object)but it lets the client read without checking the local value of LastAddConfirmed, so that it is possible to read entries for which the writer has not received the acknowledge yet.
For entries which are within the range 0..LastAddConfirmed BookKeeper guarantees that the writer has successfully received the acknowledge.
For entries outside that range it is possible that the writer never received the acknowledge and so there is the risk that the reader is seeing entries before the writer and this could result in a consistency issue in some cases.
With this method you can even read entries before the LastAddConfirmed and entries after it with one call, the expected consistency will be as described above for each subrange of ids.- Specified by:
readUnconfirmedAsyncin interfaceReadHandle- Parameters:
firstEntry- id of first entry of sequencelastEntry- id of last entry of sequence- Returns:
- an handle to the result of the operation
- See Also:
-
asyncReadEntriesInternal
void asyncReadEntriesInternal(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, Object ctx, boolean isRecoveryRead) -
asyncBatchReadEntriesInternal
void asyncBatchReadEntriesInternal(long startEntry, int maxCount, long maxSize, AsyncCallback.ReadCallback cb, Object ctx, boolean isRecoveryRead) -
asyncReadLastEntry
-
readLastEntry
- Throws:
InterruptedExceptionBKException
-
readEntriesInternalAsync
CompletableFuture<LedgerEntries> readEntriesInternalAsync(long firstEntry, long lastEntry, boolean isRecoveryRead) -
addEntry
Add entry synchronously to an open ledger.- 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
-
appendAsync
Add entry asynchronously to an open ledger.- Specified by:
appendAsyncin interfaceWriteHandle- Parameters:
data- a bytebuf to be written. The bytebuf's reference count will be decremented by 1 after the completable future is returned do not reuse the buffer, bk-client will release it appropriately.- Returns:
- an handle to the result, in case of success it will return the id of the newly appended entry
-
addEntry
Add entry synchronously to an open ledger. This can be used only withLedgerHandleAdvreturned through ledgers created withBookKeeper.createLedgerAdv(int, int, int, BookKeeper.DigestType, byte[]).- Parameters:
entryId- entryId to be addeddata- 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
Add entry synchronously to an open ledger.- 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
-
addEntry
public long addEntry(long entryId, byte[] data, int offset, int length) throws InterruptedException, BKException Add entry synchronously to an open ledger. This can be used only withLedgerHandleAdvreturned through ledgers created withBookKeeper.createLedgerAdv(int, int, int, BookKeeper.DigestType, byte[]).- Parameters:
entryId- entryId to be added.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:
- entryId
- Throws:
InterruptedExceptionBKException
-
asyncAddEntry
Add entry asynchronously to an open ledger.- 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
Add entry asynchronously to an open ledger. This can be used only withLedgerHandleAdvreturned through ledgers created withBookKeeper.createLedgerAdv(int, int, int, BookKeeper.DigestType, byte[]).- Parameters:
entryId- entryId to be addeddata- 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) Add entry asynchronously to an open ledger, using an offset and range.- 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- Throws:
ArrayIndexOutOfBoundsException- if offset or length is negative or offset and length sum to a value higher than the length of data.
-
asyncAddEntry
-
asyncAddEntry
public void asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx) Add entry asynchronously to an open ledger, using an offset and range. This can be used only withLedgerHandleAdvreturned through ledgers created withBookKeeper.createLedgerAdv(int, int, int, BookKeeper.DigestType, byte[]).- Parameters:
entryId- entryId of the entry to add.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- Throws:
ArrayIndexOutOfBoundsException- if offset or length is negative or offset and length sum to a value higher than the length of data.
-
asyncAddEntry
public void asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallbackWithLatency cb, Object ctx) Add entry asynchronously to an open ledger, using an offset and range.- Parameters:
entryId- entryId of the entry to adddata- 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- Throws:
ArrayIndexOutOfBoundsException- if offset or length is negative or offset and length sum to a value higher than the length of data.
-
asyncAddEntry
public void asyncAddEntry(long entryId, io.netty.buffer.ByteBuf data, AsyncCallback.AddCallbackWithLatency cb, Object ctx) Add entry asynchronously to an open ledger, using an offset and range. This can be used only withLedgerHandleAdvreturned through ledgers created withBookKeeper.createLedgerAdv(int, int, int, BookKeeper.DigestType, byte[]).- Parameters:
entryId- entryId of the entry to add.data- io.netty.buffer.ByteBuf of bytes to be written do not reuse the buffer, bk-client will release it appropriatelycb- object implementing callbackinterfacectx- some control object
-
force
Enforce durability to the entries written by this handle.This API is useful with
WriteFlag.DEFERRED_SYNC, because with that flag writes are acknowledged by the bookie without waiting for a durable write- Specified by:
forcein interfaceForceableHandle- Returns:
- an handle to the result
-
asyncRecoveryAddEntry
void asyncRecoveryAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx) Make a recovery add entry request. Recovery adds can add to a ledger even if it has been fenced.This is only valid for bookie and ledger recovery, which may need to replicate entries to a quorum of bookies to ensure data safety.
Normal client should never call this method.
-
waitForWritable
protected boolean waitForWritable(DistributionSchedule.WriteSet writeSet, int allowedNonWritableCount, long durationMs) -
doAsyncAddEntry
-
updateLastConfirmed
void updateLastConfirmed(long lac, long len) -
asyncReadLastConfirmed
Obtains asynchronously the last confirmed write from a quorum of bookies. This call obtains the last add confirmed each bookie has received for this ledger and returns the maximum. If the ledger has been closed, the value returned by this call may not correspond to the id of the last entry of the ledger, since it reads the hint of bookies. Consequently, in the case the ledger has been closed, it may return a different value than getLastAddConfirmed, which returns the local value of the ledger handle.- Parameters:
cb-ctx-- See Also:
-
asyncTryReadLastConfirmed
Obtains asynchronously the last confirmed write from a quorum of bookies. It is similar asasyncReadLastConfirmed(org.apache.bookkeeper.client.AsyncCallback.ReadLastConfirmedCallback, Object), but it doesn't wait all the responses from the quorum. It would callback immediately if it received a LAC which is larger than current LAC.- Parameters:
cb- callback to return read last confirmedctx- callback context- See Also:
-
tryReadLastAddConfirmedAsync
Obtains asynchronously the last confirmed write from a quorum of bookies but it doesn't wait all the responses from the quorum. It would callback immediately if it received a LAC which is larger than current LAC.- Specified by:
tryReadLastAddConfirmedAsyncin interfaceReadHandle- Returns:
- an handle to the result of the operation
-
readLastAddConfirmedAsync
Obtains asynchronously the last confirmed write from a quorum of bookies. This call obtains the last add confirmed each bookie has received for this ledger and returns the maximum. If the ledger has been closed, the value returned by this call may not correspond to the id of the last entry of the ledger, since it reads the hint of bookies. Consequently, in the case the ledger has been closed, it may return a different value than getLastAddConfirmed, which returns the local value of the ledger handle.- Specified by:
readLastAddConfirmedAsyncin interfaceReadHandle- Returns:
- an handle to the result of the operation
- See Also:
-
readLastAddConfirmedAndEntryAsync
public CompletableFuture<LastConfirmedAndEntry> readLastAddConfirmedAndEntryAsync(long entryId, long timeOutInMillis, boolean parallel) Asynchronous read specific entry and the latest last add confirmed. If the next entryId is less than known last add confirmed, the call will read next entry directly. If the next entryId is ahead of known last add confirmed, the call will issue a long poll read to wait for the next entry entryId.- Specified by:
readLastAddConfirmedAndEntryAsyncin interfaceReadHandle- Parameters:
entryId- next entry id to readtimeOutInMillis- timeout period to wait for the entry id to be available (for long poll only) if timeout for get the entry, it will return null entry.parallel- whether to issue the long poll reads in parallel- Returns:
- an handle to the result of the operation
-
asyncReadLastConfirmedAndEntry
public void asyncReadLastConfirmedAndEntry(long entryId, long timeOutInMillis, boolean parallel, AsyncCallback.ReadLastConfirmedAndEntryCallback cb, Object ctx) Asynchronous read next entry and the latest last add confirmed. If the next entryId is less than known last add confirmed, the call will read next entry directly. If the next entryId is ahead of known last add confirmed, the call will issue a long poll read to wait for the next entry entryId.The callback will return the latest last add confirmed and next entry if it is available within timeout period timeOutInMillis.
- Parameters:
entryId- next entry id to readtimeOutInMillis- timeout period to wait for the entry id to be available (for long poll only)parallel- whether to issue the long poll reads in parallelcb- callback to return the resultctx- callback context
-
readLastConfirmed
Obtains synchronously the last confirmed write from a quorum of bookies. This call obtains the last add confirmed each bookie has received for this ledger and returns the maximum. If the ledger has been closed, the value returned by this call may not correspond to the id of the last entry of the ledger, since it reads the hint of bookies. Consequently, in the case the ledger has been closed, it may return a different value than getLastAddConfirmed, which returns the local value of the ledger handle.- Returns:
- The entry id of the last confirmed write or
INVALID_ENTRY_IDif no entry has been confirmed - Throws:
InterruptedExceptionBKException- See Also:
-
tryReadLastConfirmed
Obtains synchronously the last confirmed write from a quorum of bookies. It is similar asreadLastConfirmed(), but it doesn't wait all the responses from the quorum. It would callback immediately if it received a LAC which is larger than current LAC.- Returns:
- The entry id of the last confirmed write or
INVALID_ENTRY_IDif no entry has been confirmed - Throws:
InterruptedExceptionBKException- See Also:
-
asyncReadExplicitLastConfirmed
Obtains asynchronously the explicit last add confirmed from a quorum of bookies. This call obtains Explicit LAC value and piggy-backed LAC value (just likeasyncReadLastConfirmed(ReadLastConfirmedCallback, Object)) from each bookie in the ensemble and returns the maximum. If in the write LedgerHandle, explicitLAC feature is not enabled then this call behavior will be similar toasyncReadLastConfirmed(ReadLastConfirmedCallback, Object). If the read explicit lastaddconfirmed is greater than getLastAddConfirmed, then it updates the lastAddConfirmed of this ledgerhandle. If the ledger has been closed, it returns the value of the last add confirmed from the metadata.- Parameters:
cb- callback to return read explicit last confirmedctx- callback context- See Also:
-
readExplicitLastConfirmed
- Throws:
InterruptedExceptionBKException
-
handleUnrecoverableErrorDuringAdd
void handleUnrecoverableErrorDuringAdd(int rc) -
errorOutPendingAdds
void errorOutPendingAdds(int rc) -
drainPendingAddsAndAdjustLength
List<PendingAddOp> drainPendingAddsAndAdjustLength() -
errorOutPendingAdds
-
sendAddSuccessCallbacks
void sendAddSuccessCallbacks() -
hasDelayedWriteFailedBookies
boolean hasDelayedWriteFailedBookies() -
notifyWriteFailed
-
maybeHandleDelayedWriteBookieFailure
void maybeHandleDelayedWriteBookieFailure() -
handleBookieFailure
-
ensembleChangeLoop
-
unsetSuccessAndSendWriteRequest
-
registerOperationFailureOnBookie
-
getCurrentEnsemble
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.
-
getWriteSetForReadOperation
Return aDistributionSchedule.WriteSetsuitable for reading a particular entry. This will include all bookies that are part of the ensemble for the entry. -
executeOrdered
Execute the callback in the thread pinned to the ledger.- Parameters:
runnable-- Throws:
RejectedExecutionException
-
getPendingAddOps
-