public class LedgerHandle extends java.lang.Object implements WriteHandle
Modifier and Type | Class and Description |
---|---|
(package private) static class |
LedgerHandle.LastConfirmedCtx
Context objects for synchronous call to read last confirmed.
|
(package private) static class |
LedgerHandle.NoopCloseCallback |
Modifier and Type | Field and Description |
---|---|
(package private) com.google.common.cache.LoadingCache<org.apache.bookkeeper.net.BookieSocketAddress,java.lang.Long> |
bookieFailureHistory |
(package private) BookiesHealthInfo |
bookiesHealthInfo |
(package private) boolean |
changingEnsemble |
(package private) ClientContext |
clientCtx |
(package private) java.util.Map<java.lang.Integer,org.apache.bookkeeper.net.BookieSocketAddress> |
delayedWriteFailedBookies |
(package private) DistributionSchedule |
distributionSchedule |
(package private) Counter |
ensembleChangeCounter |
(package private) ExplicitLacFlushPolicy |
explicitLacFlushPolicy |
static long |
INVALID_ENTRY_ID
Invalid entry id.
|
static long |
INVALID_LEDGER_ID
Invalid ledger id.
|
(package private) Counter |
lacUpdateHitsCounter |
(package private) Counter |
lacUpdateMissesCounter |
(package private) long |
lastAddConfirmed
Last entryId which has been confirmed to be written durably to the bookies.
|
(package private) long |
lastAddPushed |
(package private) long |
ledgerId |
(package private) byte[] |
ledgerKey |
(package private) long |
length |
(package private) static org.slf4j.Logger |
LOG |
(package private) org.apache.bookkeeper.proto.checksum.DigestManager |
macManager |
(package private) java.lang.Object |
metadataLock |
(package private) java.util.concurrent.atomic.AtomicInteger |
numEnsembleChanges |
(package private) java.util.Queue<PendingAddOp> |
pendingAddOps |
(package private) long |
pendingAddsSequenceHead
Next entryId which is expected to move forward during
sendAddSuccessCallbacks() . |
(package private) com.google.common.util.concurrent.RateLimiter |
throttler |
(package private) java.util.concurrent.ScheduledFuture<?> |
timeoutFuture |
(package private) java.util.EnumSet<WriteFlag> |
writeFlags |
Constructor and Description |
---|
LedgerHandle(ClientContext clientCtx,
long ledgerId,
org.apache.bookkeeper.versioning.Versioned<LedgerMetadata> versionedMetadata,
BookKeeper.DigestType digestType,
byte[] password,
java.util.EnumSet<WriteFlag> writeFlags) |
Modifier and Type | Method and 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.
|
long |
addEntry(long entryId,
byte[] data)
Add entry synchronously to an open ledger.
|
long |
addEntry(long entryId,
byte[] data,
int offset,
int length)
Add entry synchronously to an open ledger.
|
(package private) long |
addToLength(long delta)
Add to the length of the ledger in bytes.
|
java.util.concurrent.CompletableFuture<java.lang.Long> |
appendAsync(io.netty.buffer.ByteBuf data)
Add entry asynchronously to an open ledger.
|
void |
asyncAddEntry(byte[] data,
AsyncCallback.AddCallback cb,
java.lang.Object ctx)
Add entry asynchronously 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(io.netty.buffer.ByteBuf data,
AsyncCallback.AddCallback cb,
java.lang.Object ctx) |
void |
asyncAddEntry(long entryId,
byte[] data,
AsyncCallback.AddCallback cb,
java.lang.Object ctx)
Add entry asynchronously to an open ledger.
|
void |
asyncAddEntry(long entryId,
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(long entryId,
byte[] data,
int offset,
int length,
AsyncCallback.AddCallbackWithLatency cb,
java.lang.Object ctx)
Add entry asynchronously to an open ledger, using an offset and range.
|
void |
asyncAddEntry(long entryId,
io.netty.buffer.ByteBuf data,
AsyncCallback.AddCallbackWithLatency cb,
java.lang.Object ctx)
Add entry asynchronously to an open ledger, using an offset and range.
|
void |
asyncClose(AsyncCallback.CloseCallback cb,
java.lang.Object ctx)
Asynchronous close, any adds in flight will return errors.
|
(package private) void |
asyncCloseInternal(AsyncCallback.CloseCallback cb,
java.lang.Object ctx,
int rc) |
void |
asyncReadEntries(long firstEntry,
long lastEntry,
AsyncCallback.ReadCallback cb,
java.lang.Object ctx)
Read a sequence of entries asynchronously.
|
(package private) void |
asyncReadEntriesInternal(long firstEntry,
long lastEntry,
AsyncCallback.ReadCallback cb,
java.lang.Object ctx,
boolean isRecoveryRead) |
void |
asyncReadExplicitLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb,
java.lang.Object ctx)
Obtains asynchronously the explicit last add confirmed from a quorum of
bookies.
|
void |
asyncReadLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb,
java.lang.Object ctx)
Obtains asynchronously the last confirmed write from a quorum of bookies.
|
void |
asyncReadLastConfirmedAndEntry(long entryId,
long timeOutInMillis,
boolean parallel,
AsyncCallback.ReadLastConfirmedAndEntryCallback cb,
java.lang.Object ctx)
Asynchronous read next entry and the latest last add confirmed.
|
void |
asyncReadLastEntry(AsyncCallback.ReadCallback cb,
java.lang.Object ctx) |
void |
asyncReadUnconfirmedEntries(long firstEntry,
long lastEntry,
AsyncCallback.ReadCallback cb,
java.lang.Object ctx)
Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range.
|
(package private) void |
asyncRecoveryAddEntry(byte[] data,
int offset,
int length,
AsyncCallback.AddCallback cb,
java.lang.Object ctx)
Make a recovery add entry request.
|
void |
asyncTryReadLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb,
java.lang.Object ctx)
Obtains asynchronously the last confirmed write from a quorum of bookies.
|
void |
close()
Synchronous close the write handle, any adds in flight will return errors.
|
java.util.concurrent.CompletableFuture<java.lang.Void> |
closeAsync()
Asynchronous close the write handle, any adds in flight will return errors.
|
protected void |
doAsyncAddEntry(PendingAddOp op) |
(package private) void |
doAsyncCloseInternal(AsyncCallback.CloseCallback cb,
java.lang.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) java.util.List<PendingAddOp> |
drainPendingAddsAndAdjustLength() |
(package private) void |
ensembleChangeLoop(java.util.List<org.apache.bookkeeper.net.BookieSocketAddress> origEnsemble,
java.util.Map<java.lang.Integer,org.apache.bookkeeper.net.BookieSocketAddress> failedBookies) |
(package private) void |
errorOutPendingAdds(int rc) |
(package private) void |
errorOutPendingAdds(int rc,
java.util.List<PendingAddOp> ops) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
force()
Enforce durability to the entries written by this handle.
|
(package private) BookiesHealthInfo |
getBookiesHealthInfo()
Get the health info for bookies for this ledger.
|
long |
getCtime()
Returns the ledger creation time.
|
(package private) java.util.List<org.apache.bookkeeper.net.BookieSocketAddress> |
getCurrentEnsemble()
Get the current ensemble from the ensemble list.
|
java.util.Map<java.lang.String,byte[]> |
getCustomMetadata()
Get this ledger's customMetadata map.
|
(package private) org.apache.bookkeeper.proto.checksum.DigestManager |
getDigestManager()
Get the DigestManager.
|
(package private) DistributionSchedule |
getDistributionSchedule()
Get the Distribution Schedule.
|
long |
getId()
Get the id of the current ledger.
|
long |
getLastAddConfirmed()
Get the last confirmed entry id on this ledger.
|
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).
|
byte[] |
getLedgerKey()
Get the Ledger's key/password.
|
LedgerMetadata |
getLedgerMetadata()
Returns the metadata of this ledger.
|
long |
getLength()
Returns the length of the ledger in bytes.
|
long |
getNumBookies()
Get the count of unique bookies that own part of this ledger
by going over all the fragments of the ledger.
|
long |
getNumFragments()
Get the number of fragments that makeup this ledger.
|
(package private) org.apache.bookkeeper.versioning.Versioned<LedgerMetadata> |
getVersionedLedgerMetadata() |
java.util.EnumSet<WriteFlag> |
getWriteFlags() |
(package private) DistributionSchedule.WriteSet |
getWriteSetForReadOperation(long entryId)
Return a
DistributionSchedule.WriteSet suitable for reading a particular entry. |
(package private) void |
handleBookieFailure(java.util.Map<java.lang.Integer,org.apache.bookkeeper.net.BookieSocketAddress> failedBookies) |
(package private) void |
handleUnrecoverableErrorDuringAdd(int rc) |
(package private) boolean |
hasDelayedWriteFailedBookies() |
protected void |
initializeWriteHandleState() |
boolean |
isClosed()
Returns whether the ledger is sealed or not.
|
(package private) boolean |
isHandleWritable() |
(package private) void |
maybeHandleDelayedWriteBookieFailure() |
(package private) void |
notifyWriteFailed(int index,
org.apache.bookkeeper.net.BookieSocketAddress addr) |
java.util.concurrent.CompletableFuture<LedgerEntries> |
readAsync(long firstEntry,
long lastEntry)
Read a sequence of entries asynchronously.
|
java.util.Enumeration<LedgerEntry> |
readEntries(long firstEntry,
long lastEntry)
Read a sequence of entries synchronously.
|
(package private) java.util.concurrent.CompletableFuture<LedgerEntries> |
readEntriesInternalAsync(long firstEntry,
long lastEntry,
boolean isRecoveryRead) |
long |
readExplicitLastConfirmed() |
java.util.concurrent.CompletableFuture<LastConfirmedAndEntry> |
readLastAddConfirmedAndEntryAsync(long entryId,
long timeOutInMillis,
boolean parallel)
Asynchronous read specific entry and the latest last add confirmed.
|
java.util.concurrent.CompletableFuture<java.lang.Long> |
readLastAddConfirmedAsync()
Obtains asynchronously the last confirmed write from a quorum of bookies.
|
long |
readLastConfirmed()
Obtains synchronously the last confirmed write from a quorum of bookies.
|
LedgerEntry |
readLastEntry() |
java.util.concurrent.CompletableFuture<LedgerEntries> |
readUnconfirmedAsync(long firstEntry,
long lastEntry)
Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range.
|
java.util.Enumeration<LedgerEntry> |
readUnconfirmedEntries(long firstEntry,
long lastEntry)
Read a sequence of entries synchronously, allowing to read after the LastAddConfirmed range.
This is the same of #asyncReadUnconfirmedEntries(long, long, ReadCallback, Object) |
(package private) void |
recordReadErrorOnBookie(int bookieIndex)
Notify the LedgerHandle that a read operation was failed on a particular bookie.
|
(package private) void |
registerOperationFailureOnBookie(org.apache.bookkeeper.net.BookieSocketAddress bookie,
long entryId) |
(package private) void |
sendAddSuccessCallbacks() |
(package private) void |
setLastAddConfirmed(long lac) |
(package private) boolean |
setLedgerMetadata(org.apache.bookkeeper.versioning.Versioned<LedgerMetadata> expected,
org.apache.bookkeeper.versioning.Versioned<LedgerMetadata> newMetadata) |
java.util.concurrent.CompletableFuture<java.lang.Long> |
tryReadLastAddConfirmedAsync()
Obtains asynchronously the last confirmed write from a quorum of bookies
but it doesn't wait all the responses from the quorum.
|
long |
tryReadLastConfirmed()
Obtains synchronously the last confirmed write from a quorum of bookies.
|
(package private) void |
unsetSuccessAndSendWriteRequest(java.util.List<org.apache.bookkeeper.net.BookieSocketAddress> ensemble,
java.util.Set<java.lang.Integer> bookies) |
(package private) void |
updateLastConfirmed(long lac,
long len) |
protected boolean |
waitForWritable(DistributionSchedule.WriteSet writeSet,
long key,
int allowedNonWritableCount,
long durationMs) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
append, append, append, append, appendAsync, appendAsync, appendAsync
read, readLastAddConfirmed, readLastAddConfirmedAndEntry, readUnconfirmed, tryReadLastAddConfirmed
static final org.slf4j.Logger LOG
final ClientContext clientCtx
final byte[] ledgerKey
final long ledgerId
long lastAddPushed
volatile long lastAddConfirmed
volatile long pendingAddsSequenceHead
sendAddSuccessCallbacks()
. This is important
in order to have an ordered sequence of addEntry ackknowledged to the writerlong length
final org.apache.bookkeeper.proto.checksum.DigestManager macManager
final DistributionSchedule distributionSchedule
final com.google.common.util.concurrent.RateLimiter throttler
final com.google.common.cache.LoadingCache<org.apache.bookkeeper.net.BookieSocketAddress,java.lang.Long> bookieFailureHistory
final BookiesHealthInfo bookiesHealthInfo
final java.util.EnumSet<WriteFlag> writeFlags
java.util.concurrent.ScheduledFuture<?> timeoutFuture
final java.util.Map<java.lang.Integer,org.apache.bookkeeper.net.BookieSocketAddress> delayedWriteFailedBookies
public static final long INVALID_ENTRY_ID
public static final long INVALID_LEDGER_ID
final java.lang.Object metadataLock
boolean changingEnsemble
final java.util.concurrent.atomic.AtomicInteger numEnsembleChanges
java.util.Queue<PendingAddOp> pendingAddOps
ExplicitLacFlushPolicy explicitLacFlushPolicy
final Counter ensembleChangeCounter
final Counter lacUpdateHitsCounter
final Counter lacUpdateMissesCounter
LedgerHandle(ClientContext clientCtx, long ledgerId, org.apache.bookkeeper.versioning.Versioned<LedgerMetadata> versionedMetadata, BookKeeper.DigestType digestType, byte[] password, java.util.EnumSet<WriteFlag> writeFlags) throws java.security.GeneralSecurityException, java.lang.NumberFormatException
java.security.GeneralSecurityException
java.lang.NumberFormatException
void recordReadErrorOnBookie(int bookieIndex)
protected void initializeWriteHandleState()
public long getId()
public java.util.EnumSet<WriteFlag> getWriteFlags()
public long getLastAddConfirmed()
ReadHandle.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.
getLastAddConfirmed
in interface ReadHandle
ReadHandle.readLastAddConfirmed()
void setLastAddConfirmed(long lac)
public long getLastAddPushed()
getLastAddPushed
in interface WriteHandle
public byte[] getLedgerKey()
public LedgerMetadata getLedgerMetadata()
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.
getLedgerMetadata
in interface Handle
org.apache.bookkeeper.versioning.Versioned<LedgerMetadata> getVersionedLedgerMetadata()
boolean setLedgerMetadata(org.apache.bookkeeper.versioning.Versioned<LedgerMetadata> expected, org.apache.bookkeeper.versioning.Versioned<LedgerMetadata> newMetadata)
public java.util.Map<java.lang.String,byte[]> getCustomMetadata()
public long getNumFragments()
public long getNumBookies()
org.apache.bookkeeper.proto.checksum.DigestManager getDigestManager()
long addToLength(long delta)
delta
- public long getLength()
getLength
in interface ReadHandle
public long getCtime()
DistributionSchedule getDistributionSchedule()
BookiesHealthInfo getBookiesHealthInfo()
public void close() throws java.lang.InterruptedException, BKException
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.
close
in interface java.lang.AutoCloseable
close
in interface Handle
close
in interface WriteHandle
java.lang.InterruptedException
BKException
Handle.closeAsync()
public java.util.concurrent.CompletableFuture<java.lang.Void> closeAsync()
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.
closeAsync
in interface Handle
closeAsync
in interface WriteHandle
public void asyncClose(AsyncCallback.CloseCallback cb, java.lang.Object ctx)
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.
cb
- callback implementationctx
- control objectpublic boolean isClosed()
A ledger is sealed when either the client explicitly closes it (WriteHandle.close()
or
Handle.close()
) or another client explicitly open and recovery it
OpenBuilder.withRecovery(boolean)
.
This method only checks the metadata cached locally. The metadata can be not update-to-date because the metadata notification is delayed.
isClosed
in interface ReadHandle
boolean isHandleWritable()
void asyncCloseInternal(AsyncCallback.CloseCallback cb, java.lang.Object ctx, int rc)
void doAsyncCloseInternal(AsyncCallback.CloseCallback cb, java.lang.Object ctx, int rc)
cb
- ctx
- rc
- public java.util.Enumeration<LedgerEntry> readEntries(long firstEntry, long lastEntry) throws java.lang.InterruptedException, BKException
firstEntry
- id of first entry of sequence (included)lastEntry
- id of last entry of sequence (included)java.lang.InterruptedException
BKException
#asyncReadEntries(long, long, ReadCallback, Object)
public java.util.Enumeration<LedgerEntry> readUnconfirmedEntries(long firstEntry, long lastEntry) throws java.lang.InterruptedException, BKException
#asyncReadUnconfirmedEntries(long, long, ReadCallback, Object)
firstEntry
- id of first entry of sequence (included)lastEntry
- id of last entry of sequence (included)java.lang.InterruptedException
BKException
readEntries(long, long)
,
#asyncReadUnconfirmedEntries(long, long, ReadCallback, java.lang.Object)
,
#asyncReadLastConfirmed(ReadLastConfirmedCallback, java.lang.Object)
public void asyncReadEntries(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, java.lang.Object ctx)
firstEntry
- id of first entry of sequencelastEntry
- id of last entry of sequencecb
- object implementing read callback interfacectx
- control objectpublic void asyncReadUnconfirmedEntries(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, java.lang.Object ctx)
#asyncReadEntries(long, long, ReadCallback, Object)
but it lets the client read without checking the local value of LastAddConfirmed, so that it is possibile to
read entries for which the writer has not received the acknowledge yet. firstEntry
- id of first entry of sequencelastEntry
- id of last entry of sequencecb
- object implementing read callback interfacectx
- control object#asyncReadEntries(long, long, ReadCallback, Object)
,
#asyncReadLastConfirmed(ReadLastConfirmedCallback, Object)
,
readUnconfirmedEntries(long, long)
public java.util.concurrent.CompletableFuture<LedgerEntries> readAsync(long firstEntry, long lastEntry)
readAsync
in interface ReadHandle
firstEntry
- id of first entry of sequencelastEntry
- id of last entry of sequencepublic java.util.concurrent.CompletableFuture<LedgerEntries> readUnconfirmedAsync(long firstEntry, long lastEntry)
#asyncReadEntries(long, long, ReadCallback, Object)
but it lets the client read without checking the local value of LastAddConfirmed, so that it is possibile to
read entries for which the writer has not received the acknowledge yet. readUnconfirmedAsync
in interface ReadHandle
firstEntry
- id of first entry of sequencelastEntry
- id of last entry of sequence#asyncReadEntries(long, long, ReadCallback, Object)
,
#asyncReadLastConfirmed(ReadLastConfirmedCallback, Object)
,
readUnconfirmedEntries(long, long)
void asyncReadEntriesInternal(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, java.lang.Object ctx, boolean isRecoveryRead)
public void asyncReadLastEntry(AsyncCallback.ReadCallback cb, java.lang.Object ctx)
public LedgerEntry readLastEntry() throws java.lang.InterruptedException, BKException
java.lang.InterruptedException
BKException
java.util.concurrent.CompletableFuture<LedgerEntries> readEntriesInternalAsync(long firstEntry, long lastEntry, boolean isRecoveryRead)
public long addEntry(byte[] data) throws java.lang.InterruptedException, BKException
data
- array of bytes to be written to the ledger
do not reuse the buffer, bk-client will release it appropriatelyjava.lang.InterruptedException
BKException
public java.util.concurrent.CompletableFuture<java.lang.Long> appendAsync(io.netty.buffer.ByteBuf data)
appendAsync
in interface WriteHandle
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.public long addEntry(long entryId, byte[] data) throws java.lang.InterruptedException, BKException
LedgerHandleAdv
returned through ledgers created with BookKeeper.createLedgerAdv(int, int, int, DigestType, byte[])
.entryId
- entryId to be addeddata
- array of bytes to be written to the ledger
do not reuse the buffer, bk-client will release it appropriatelyjava.lang.InterruptedException
BKException
public long addEntry(byte[] data, int offset, int length) throws java.lang.InterruptedException, BKException
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 datajava.lang.InterruptedException
BKException
public long addEntry(long entryId, byte[] data, int offset, int length) throws java.lang.InterruptedException, BKException
LedgerHandleAdv
returned through ledgers created with BookKeeper.createLedgerAdv(int, int, int, DigestType, byte[])
.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 datajava.lang.InterruptedException
BKException
public void asyncAddEntry(byte[] data, AsyncCallback.AddCallback cb, java.lang.Object ctx)
data
- array of bytes to be written
do not reuse the buffer, bk-client will release it appropriatelycb
- object implementing callbackinterfacectx
- some control objectpublic void asyncAddEntry(long entryId, byte[] data, AsyncCallback.AddCallback cb, java.lang.Object ctx)
LedgerHandleAdv
returned through ledgers created with BookKeeper.createLedgerAdv(int, int, int, DigestType, byte[])
.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 objectpublic void asyncAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, java.lang.Object ctx)
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 objectjava.lang.ArrayIndexOutOfBoundsException
- if offset or length is negative or
offset and length sum to a value higher than the length of data.public void asyncAddEntry(io.netty.buffer.ByteBuf data, AsyncCallback.AddCallback cb, java.lang.Object ctx)
public void asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallback cb, java.lang.Object ctx)
LedgerHandleAdv
returned through
ledgers created with
BookKeeper.createLedgerAdv(int, int, int, org.apache.bookkeeper.client.BookKeeper.DigestType, byte[])
.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 objectjava.lang.ArrayIndexOutOfBoundsException
- if offset or length is negative or offset and length sum to a
value higher than the length of data.public void asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallbackWithLatency cb, java.lang.Object ctx)
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 objectjava.lang.ArrayIndexOutOfBoundsException
- if offset or length is negative or offset and length sum to a
value higher than the length of data.public void asyncAddEntry(long entryId, io.netty.buffer.ByteBuf data, AsyncCallback.AddCallbackWithLatency cb, java.lang.Object ctx)
LedgerHandleAdv
returned through
ledgers created with createLedgerAdv(int, int, int, DigestType, byte[])
.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 objectpublic java.util.concurrent.CompletableFuture<java.lang.Void> force()
This API is useful with WriteFlag.DEFERRED_SYNC
, because with
that flag writes are acknowledged by the bookie without waiting for a
durable write
force
in interface ForceableHandle
void asyncRecoveryAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, java.lang.Object ctx)
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.
protected boolean waitForWritable(DistributionSchedule.WriteSet writeSet, long key, int allowedNonWritableCount, long durationMs)
protected void doAsyncAddEntry(PendingAddOp op)
void updateLastConfirmed(long lac, long len)
public void asyncReadLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb, java.lang.Object ctx)
cb
- ctx
- getLastAddConfirmed()
public void asyncTryReadLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb, java.lang.Object ctx)
asyncReadLastConfirmed(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.cb
- callback to return read last confirmedctx
- callback contextasyncTryReadLastConfirmed(org.apache.bookkeeper.client.AsyncCallback.ReadLastConfirmedCallback, Object)
public java.util.concurrent.CompletableFuture<java.lang.Long> tryReadLastAddConfirmedAsync()
tryReadLastAddConfirmedAsync
in interface ReadHandle
public java.util.concurrent.CompletableFuture<java.lang.Long> readLastAddConfirmedAsync()
readLastAddConfirmedAsync
in interface ReadHandle
ReadHandle.getLastAddConfirmed()
public java.util.concurrent.CompletableFuture<LastConfirmedAndEntry> readLastAddConfirmedAndEntryAsync(long entryId, long timeOutInMillis, boolean parallel)
readLastAddConfirmedAndEntryAsync
in interface ReadHandle
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 parallelpublic void asyncReadLastConfirmedAndEntry(long entryId, long timeOutInMillis, boolean parallel, AsyncCallback.ReadLastConfirmedAndEntryCallback cb, java.lang.Object ctx)
The callback will return the latest last add confirmed and next entry if it is available within timeout period timeOutInMillis.
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 contextpublic long readLastConfirmed() throws java.lang.InterruptedException, BKException
INVALID_ENTRY_ID
if no entry has been confirmedjava.lang.InterruptedException
BKException
getLastAddConfirmed()
public long tryReadLastConfirmed() throws java.lang.InterruptedException, BKException
readLastConfirmed()
, 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.INVALID_ENTRY_ID
if no entry has been confirmedjava.lang.InterruptedException
BKException
readLastConfirmed()
public void asyncReadExplicitLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb, java.lang.Object ctx)
#asyncReadLastConfirmed(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 to #asyncReadLastConfirmed(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.cb
- callback to return read explicit last confirmedctx
- callback contextgetLastAddConfirmed()
public long readExplicitLastConfirmed() throws java.lang.InterruptedException, BKException
java.lang.InterruptedException
BKException
void handleUnrecoverableErrorDuringAdd(int rc)
void errorOutPendingAdds(int rc)
java.util.List<PendingAddOp> drainPendingAddsAndAdjustLength()
void errorOutPendingAdds(int rc, java.util.List<PendingAddOp> ops)
void sendAddSuccessCallbacks()
boolean hasDelayedWriteFailedBookies()
void notifyWriteFailed(int index, org.apache.bookkeeper.net.BookieSocketAddress addr)
void maybeHandleDelayedWriteBookieFailure()
void handleBookieFailure(java.util.Map<java.lang.Integer,org.apache.bookkeeper.net.BookieSocketAddress> failedBookies)
void ensembleChangeLoop(java.util.List<org.apache.bookkeeper.net.BookieSocketAddress> origEnsemble, java.util.Map<java.lang.Integer,org.apache.bookkeeper.net.BookieSocketAddress> failedBookies)
void unsetSuccessAndSendWriteRequest(java.util.List<org.apache.bookkeeper.net.BookieSocketAddress> ensemble, java.util.Set<java.lang.Integer> bookies)
void registerOperationFailureOnBookie(org.apache.bookkeeper.net.BookieSocketAddress bookie, long entryId)
java.util.List<org.apache.bookkeeper.net.BookieSocketAddress> getCurrentEnsemble()
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.
DistributionSchedule.WriteSet getWriteSetForReadOperation(long entryId)
DistributionSchedule.WriteSet
suitable for reading a particular entry.
This will include all bookies that are cotnaCopyright © 2011–2020 The Apache Software Foundation. All rights reserved.