public class LedgerHandle extends Object implements AutoCloseable
Modifier and Type | Class and Description |
---|---|
(package private) static class |
LedgerHandle.EnsembleInfo |
(package private) static class |
LedgerHandle.LastAddConfirmedCallback |
(package private) static class |
LedgerHandle.LastConfirmedCtx
Context objects for synchronous call to read last confirmed.
|
(package private) static class |
LedgerHandle.NoopCloseCallback |
(package private) static class |
LedgerHandle.SyncAddCallback |
(package private) static class |
LedgerHandle.SyncCloseCallback |
(package private) static class |
LedgerHandle.SyncReadCallback |
(package private) static class |
LedgerHandle.SyncReadLastConfirmedCallback |
Modifier and Type | Field and Description |
---|---|
(package private) BookKeeper |
bk |
(package private) AtomicInteger |
blockAddCompletions |
(package private) com.google.common.cache.LoadingCache<org.apache.bookkeeper.net.BookieSocketAddress,Long> |
bookieFailureHistory |
(package private) DistributionSchedule |
distributionSchedule |
(package private) boolean |
enableParallelRecoveryRead |
(package private) Counter |
ensembleChangeCounter |
(package private) ExplicitLacFlushPolicy |
explicitLacFlushPolicy |
static long |
INVALID_ENTRY_ID
Invalid entry id.
|
(package private) Counter |
lacUpdateHitsCounter |
(package private) Counter |
lacUpdateMissesCounter |
(package private) long |
lastAddConfirmed |
(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) DigestManager |
macManager |
(package private) LedgerMetadata |
metadata |
(package private) AtomicInteger |
numEnsembleChanges |
(package private) Queue<PendingAddOp> |
pendingAddOps |
(package private) int |
recoveryReadBatchSize |
(package private) com.google.common.util.concurrent.RateLimiter |
throttler |
Constructor and Description |
---|
LedgerHandle(BookKeeper bk,
long ledgerId,
LedgerMetadata metadata,
BookKeeper.DigestType digestType,
byte[] password) |
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.
|
void |
asyncAddEntry(byte[] data,
AsyncCallback.AddCallback cb,
Object ctx)
Add entry asynchronously to an open ledger.
|
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.
|
void |
asyncAddEntry(io.netty.buffer.ByteBuf data,
AsyncCallback.AddCallback cb,
Object ctx) |
void |
asyncAddEntry(long entryId,
byte[] data,
AsyncCallback.AddCallback cb,
Object ctx)
Add entry asynchronously to an open ledger.
|
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.
|
void |
asyncClose(AsyncCallback.CloseCallback cb,
Object ctx)
Asynchronous close, any adds in flight will return errors.
|
(package private) void |
asyncCloseInternal(AsyncCallback.CloseCallback cb,
Object ctx,
int rc) |
void |
asyncReadEntries(long firstEntry,
long lastEntry,
AsyncCallback.ReadCallback cb,
Object ctx)
Read a sequence of entries asynchronously.
|
(package private) void |
asyncReadEntriesInternal(long firstEntry,
long lastEntry,
AsyncCallback.ReadCallback cb,
Object ctx) |
void |
asyncReadExplicitLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb,
Object ctx)
Obtains asynchronously the explicit last add confirmed from a quorum of
bookies.
|
void |
asyncReadLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb,
Object ctx)
Obtains asynchronously the last confirmed write from a quorum of bookies.
|
void |
asyncReadLastConfirmedAndEntry(long entryId,
long timeOutInMillis,
boolean parallel,
AsyncCallback.ReadLastConfirmedAndEntryCallback cb,
Object ctx)
Asynchronous read next entry and the latest last add confirmed.
|
void |
asyncReadUnconfirmedEntries(long firstEntry,
long lastEntry,
AsyncCallback.ReadCallback cb,
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,
Object ctx)
Make a recovery add entry request.
|
void |
asyncTryReadLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb,
Object ctx)
Obtains asynchronously the last confirmed write from a quorum of bookies.
|
void |
close()
Close this ledger synchronously.
|
protected void |
doAsyncAddEntry(PendingAddOp op,
io.netty.buffer.ByteBuf data,
AsyncCallback.AddCallback cb,
Object ctx) |
(package private) void |
doAsyncCloseInternal(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> |
drainPendingAddsToErrorOut() |
(package private) void |
errorOutPendingAdds(int rc) |
(package private) void |
errorOutPendingAdds(int rc,
List<PendingAddOp> ops) |
Map<String,byte[]> |
getCustomMetadata()
Get this ledger's customMetadata map.
|
(package private) 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 persited to the ledger)
|
byte[] |
getLedgerKey()
Get the Ledger's key/password.
|
(package private) LedgerMetadata |
getLedgerMetadata()
Get the LedgerMetadata
|
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) void |
handleBookieFailure(Map<Integer,org.apache.bookkeeper.net.BookieSocketAddress> failedBookies) |
(package private) void |
handleUnrecoverableErrorDuringAdd(int rc) |
protected void |
initializeExplicitLacFlushPolicy() |
boolean |
isClosed()
Has the ledger been closed?
|
Enumeration<LedgerEntry> |
readEntries(long firstEntry,
long lastEntry)
Read a sequence of entries synchronously.
|
long |
readExplicitLastConfirmed()
Obtains synchronously the explicit last add confirmed from a quorum of
bookies.
|
long |
readLastConfirmed()
Obtains synchronously the last confirmed write from a quorum of bookies.
|
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, org.apache.bookkeeper.client.AsyncCallback.ReadCallback, java.lang.Object) |
(package private) void |
recover(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<Void> finalCb) |
(package private) void |
recover(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<Void> finalCb,
org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryListener listener,
boolean forceRecovery)
Recover the ledger.
|
(package private) void |
registerOperationFailureOnBookie(org.apache.bookkeeper.net.BookieSocketAddress bookie,
long entryId) |
(package private) LedgerHandle.EnsembleInfo |
replaceBookieInMetadata(Map<Integer,org.apache.bookkeeper.net.BookieSocketAddress> failedBookies,
int ensembleChangeIdx) |
(package private) void |
rereadMetadata(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<LedgerMetadata> cb) |
(package private) void |
sendAddSuccessCallbacks() |
(package private) void |
setLastAddConfirmed(long lac) |
long |
tryReadLastConfirmed()
Obtains synchronously the last confirmed write from a quorum of bookies.
|
(package private) void |
unsetSuccessAndSendWriteRequest(Set<Integer> bookies) |
(package private) void |
updateLastConfirmed(long lac,
long len) |
(package private) void |
writeLedgerConfig(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<Void> writeCb) |
static final org.slf4j.Logger LOG
final byte[] ledgerKey
LedgerMetadata metadata
final BookKeeper bk
final long ledgerId
long lastAddPushed
volatile long lastAddConfirmed
long length
final DigestManager macManager
final DistributionSchedule distributionSchedule
final com.google.common.util.concurrent.RateLimiter throttler
final com.google.common.cache.LoadingCache<org.apache.bookkeeper.net.BookieSocketAddress,Long> bookieFailureHistory
final boolean enableParallelRecoveryRead
final int recoveryReadBatchSize
public static final long INVALID_ENTRY_ID
final AtomicInteger blockAddCompletions
final AtomicInteger numEnsembleChanges
Queue<PendingAddOp> pendingAddOps
ExplicitLacFlushPolicy explicitLacFlushPolicy
final Counter ensembleChangeCounter
final Counter lacUpdateHitsCounter
final Counter lacUpdateMissesCounter
LedgerHandle(BookKeeper bk, long ledgerId, LedgerMetadata metadata, BookKeeper.DigestType digestType, byte[] password) throws GeneralSecurityException, NumberFormatException
protected void initializeExplicitLacFlushPolicy()
public long getId()
public long getLastAddConfirmed()
INVALID_ENTRY_ID
if no entry has been confirmedreadLastConfirmed()
void setLastAddConfirmed(long lac)
public long getLastAddPushed()
INVALID_ENTRY_ID
if no entry has been pushedpublic byte[] getLedgerKey()
LedgerMetadata getLedgerMetadata()
public Map<String,byte[]> getCustomMetadata()
public long getNumFragments()
public long getNumBookies()
DigestManager getDigestManager()
long addToLength(long delta)
delta
- public long getLength()
DistributionSchedule getDistributionSchedule()
void writeLedgerConfig(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<Void> writeCb)
public void close() throws InterruptedException, BKException
close
in interface AutoCloseable
InterruptedException
BKException
asyncClose(org.apache.bookkeeper.client.AsyncCallback.CloseCallback, java.lang.Object)
public void asyncClose(AsyncCallback.CloseCallback cb, Object ctx)
cb
- callback implementationctx
- control objectpublic boolean isClosed()
void asyncCloseInternal(AsyncCallback.CloseCallback cb, Object ctx, int rc)
void doAsyncCloseInternal(AsyncCallback.CloseCallback cb, Object ctx, int rc)
cb
- ctx
- rc
- public Enumeration<LedgerEntry> readEntries(long firstEntry, long lastEntry) throws InterruptedException, BKException
firstEntry
- id of first entry of sequence (included)lastEntry
- id of last entry of sequence (included)InterruptedException
BKException
asyncReadEntries(long, long, org.apache.bookkeeper.client.AsyncCallback.ReadCallback, java.lang.Object)
public Enumeration<LedgerEntry> readUnconfirmedEntries(long firstEntry, long lastEntry) throws InterruptedException, BKException
asyncReadUnconfirmedEntries(long, long, org.apache.bookkeeper.client.AsyncCallback.ReadCallback, java.lang.Object)
firstEntry
- id of first entry of sequence (included)lastEntry
- id of last entry of sequence (included)InterruptedException
BKException
readEntries(long, long)
,
asyncReadUnconfirmedEntries(long, long, org.apache.bookkeeper.client.AsyncCallback.ReadCallback, java.lang.Object)
,
asyncReadLastConfirmed(org.apache.bookkeeper.client.AsyncCallback.ReadLastConfirmedCallback, java.lang.Object)
public void asyncReadEntries(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, 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, Object ctx)
asyncReadEntries(long, long, org.apache.bookkeeper.client.AsyncCallback.ReadCallback, java.lang.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 objectasyncReadEntries(long, long, org.apache.bookkeeper.client.AsyncCallback.ReadCallback, java.lang.Object)
,
asyncReadLastConfirmed(org.apache.bookkeeper.client.AsyncCallback.ReadLastConfirmedCallback, java.lang.Object)
,
readUnconfirmedEntries(long, long)
void asyncReadEntriesInternal(long firstEntry, long lastEntry, AsyncCallback.ReadCallback cb, Object ctx)
public long addEntry(byte[] data) throws InterruptedException, BKException
data
- array of bytes to be written to the ledgerInterruptedException
BKException
public long addEntry(long entryId, byte[] data) throws 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 ledgerInterruptedException
BKException
public long addEntry(byte[] data, int offset, int length) throws InterruptedException, BKException
data
- array of bytes to be written to the ledgeroffset
- offset from which to take bytes from datalength
- number of bytes to take from dataInterruptedException
BKException
public long addEntry(long entryId, byte[] data, int offset, int length) throws 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 ledgeroffset
- offset from which to take bytes from datalength
- number of bytes to take from dataInterruptedException
BKException
public void asyncAddEntry(byte[] data, AsyncCallback.AddCallback cb, Object ctx)
data
- array of bytes to be writtencb
- object implementing callbackinterfacectx
- some control objectpublic void asyncAddEntry(long entryId, byte[] data, AsyncCallback.AddCallback cb, 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 writtencb
- object implementing callbackinterfacectx
- some control objectpublic void asyncAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx)
data
- array of bytes to be writtenoffset
- offset from which to take bytes from datalength
- number of bytes to take from datacb
- object implementing callbackinterfacectx
- some control objectArrayIndexOutOfBoundsException
- 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, Object ctx)
public void asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx) throws BKException
LedgerHandleAdv
returned through
ledgers created with BookKeeper.createLedgerAdv(int, int, int, DigestType, byte[])
.entryId
- entryId of the entry to add.data
- array of bytes to be writtenoffset
- offset from which to take bytes from datalength
- number of bytes to take from datacb
- object implementing callbackinterfacectx
- some control objectArrayIndexOutOfBoundsException
- if offset or length is negative or offset and length sum to a
value higher than the length of data.BKException
void asyncRecoveryAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx)
protected void doAsyncAddEntry(PendingAddOp op, io.netty.buffer.ByteBuf data, AsyncCallback.AddCallback cb, Object ctx)
void updateLastConfirmed(long lac, long len)
public void asyncReadLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb, Object ctx)
cb
- ctx
- getLastAddConfirmed()
public void asyncTryReadLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb, Object ctx)
asyncTryReadLastConfirmed(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 void asyncReadLastConfirmedAndEntry(long entryId, long timeOutInMillis, boolean parallel, AsyncCallback.ReadLastConfirmedAndEntryCallback cb, Object ctx)
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 InterruptedException, BKException
INVALID_ENTRY_ID
if no entry has been confirmedInterruptedException
BKException
getLastAddConfirmed()
public long tryReadLastConfirmed() throws 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 confirmedInterruptedException
BKException
readLastConfirmed()
public void asyncReadExplicitLastConfirmed(AsyncCallback.ReadLastConfirmedCallback cb, Object ctx)
INVALID_ENTRY_ID
. 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 InterruptedException, BKException
INVALID_ENTRY_ID
. 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.INVALID_ENTRY_ID
if no entry has been
confirmed or if explicitLAC feature is not enabled in write
LedgerHandle.InterruptedException
BKException
getLastAddConfirmed()
void handleUnrecoverableErrorDuringAdd(int rc)
void errorOutPendingAdds(int rc)
List<PendingAddOp> drainPendingAddsToErrorOut()
void errorOutPendingAdds(int rc, List<PendingAddOp> ops)
void sendAddSuccessCallbacks()
LedgerHandle.EnsembleInfo replaceBookieInMetadata(Map<Integer,org.apache.bookkeeper.net.BookieSocketAddress> failedBookies, int ensembleChangeIdx) throws BKException.BKNotEnoughBookiesException
void handleBookieFailure(Map<Integer,org.apache.bookkeeper.net.BookieSocketAddress> failedBookies)
void rereadMetadata(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<LedgerMetadata> cb)
void registerOperationFailureOnBookie(org.apache.bookkeeper.net.BookieSocketAddress bookie, long entryId)
void recover(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<Void> finalCb)
void recover(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback<Void> finalCb, org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryListener listener, boolean forceRecovery)
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.Copyright © 2011–2017 The Apache Software Foundation. All rights reserved.