Class ManagedLedgerImpl
java.lang.Object
org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl
- All Implemented Interfaces:
AsyncCallback.CreateCallback,ManagedLedger
- Direct Known Subclasses:
ReadOnlyManagedLedgerImpl,ShadowManagedLedgerImpl
public class ManagedLedgerImpl
extends Object
implements ManagedLedger, AsyncCallback.CreateCallback
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final AtomicLongFieldUpdater<ManagedLedgerImpl>protected static final intprotected final BookKeeperprotected final Clockprotected ManagedLedgerConfigprotected LedgerHandleprotected longprotected longprotected static final intprotected static final intprotected final BookKeeper.DigestTypeprotected final Executorprotected longprotected longprotected final NavigableMap<Long,MLDataFormats.ManagedLedgerInfo.LedgerInfo> protected Statprotected ManagedLedgerInterceptorprotected final ManagedLedgerMBeanImplprotected final Supplier<CompletableFuture<Boolean>>protected final Stringprotected ManagedLedgerImpl.Stateprotected static final AtomicReferenceFieldUpdater<ManagedLedgerImpl,ManagedLedgerImpl.State> protected final MetaStore -
Constructor Summary
ConstructorsConstructorDescriptionManagedLedgerImpl(ManagedLedgerFactoryImpl factory, BookKeeper bookKeeper, MetaStore store, ManagedLedgerConfig config, org.apache.bookkeeper.common.util.OrderedScheduler scheduledExecutor, String name) ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, BookKeeper bookKeeper, MetaStore store, ManagedLedgerConfig config, org.apache.bookkeeper.common.util.OrderedScheduler scheduledExecutor, String name, Supplier<CompletableFuture<Boolean>> mlOwnershipChecker) -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateCursor(ManagedCursor cursor) addEntry(byte[] data) Append a new entry to the end of a managed ledger.addEntry(byte[] data, int numberOfMessages) Append a new entry to the end of a managed ledger.addEntry(byte[] data, int offset, int length) Append a new entry to the end of a managed ledger.addEntry(byte[] data, int numberOfMessages, int offset, int length) Append a new entry to the end of a managed ledger.voidaddWaitingCursor(ManagedCursorImpl cursor) voidprotected voidafterFailedAddEntry(int numOfMessages) voidasyncAddEntry(byte[] data, int numberOfMessages, int offset, int length, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncAddEntry(byte[] data, int offset, int length, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncAddEntry(byte[] data, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncAddEntry(io.netty.buffer.ByteBuf buffer, int numberOfMessages, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncAddEntry(io.netty.buffer.ByteBuf buffer, AsyncCallbacks.AddEntryCallback callback, Object ctx) Append a new entry asynchronously.voidasyncClose(AsyncCallbacks.CloseCallback callback, Object ctx) Close the ManagedLedger asynchronously.protected voidasyncCreateLedger(BookKeeper bookKeeper, ManagedLedgerConfig config, BookKeeper.DigestType digestType, AsyncCallback.CreateCallback cb, Map<String, byte[]> metadata) Create ledger async and schedule a timeout task to check ledger-creation is complete else it fails the callback with TimeoutException.voidasyncDelete(AsyncCallbacks.DeleteLedgerCallback callback, Object ctx) Async delete a ledger.voidasyncDeleteCursor(String consumerName, AsyncCallbacks.DeleteCursorCallback callback, Object ctx) Delete a ManagedCursor asynchronously.voidasyncDeleteProperty(String key, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Async delete the property by key.asyncFindPosition(Predicate<Entry> predicate) Find position by sequenceId.voidasyncOffloadPrefix(Position pos, AsyncCallbacks.OffloadCallback callback, Object ctx) Offload as many entries before position as possible to longterm storage.voidasyncOpenCursor(String cursorName, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Open a ManagedCursor asynchronously.voidasyncOpenCursor(String cursorName, CommandSubscribe.InitialPosition initialPosition, Map<String, Long> properties, Map<String, String> cursorProperties, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Open a ManagedCursor asynchronously.voidasyncOpenCursor(String cursorName, CommandSubscribe.InitialPosition initialPosition, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Open a ManagedCursor asynchronously.protected voidasyncReadEntry(org.apache.bookkeeper.client.api.ReadHandle ledger, long firstEntry, long lastEntry, org.apache.bookkeeper.mledger.impl.OpReadEntry opReadEntry, Object ctx) protected voidasyncReadEntry(org.apache.bookkeeper.client.api.ReadHandle ledger, PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, Object ctx) voidasyncReadEntry(PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, Object ctx) voidasyncSetProperties(Map<String, String> properties, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Async update managed-ledger's properties.voidasyncSetProperty(String key, String value, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Async add key-value to propertiesMap.voidasyncTerminate(AsyncCallbacks.TerminateCallback callback, Object ctx) Truncate ledgers The truncate operation will move all cursors to the end of the topic and delete all inactive ledgers.protected booleanbeforeAddEntry(OpAddEntry addOperation) protected booleancheckAndCompleteLedgerOpTask(int rc, LedgerHandle lh, Object ctx) check if ledger-op task is already completed by timeout-task.voidCheck if managed ledger should cache backlog reads.booleanCheck current inactive ledger (based onManagedLedgerConfig.getInactiveLedgerRollOverTimeMs()and roll over that ledger if inactive.voidclose()Close the ManagedLedger.voidcreateComplete(int rc, LedgerHandle lh, Object ctx) static ManagedLedgerExceptioncreateManagedLedgerException(int bkErrorCode) static ManagedLedgerExceptionvoiddeactivateCursor(ManagedCursor cursor) voiddelete()Delete this ManagedLedger completely from the system.voiddeleteCursor(String name) Remove a ManagedCursor from this ManagedLedger.voiddeleteProperty(String key) Delete the property by key.protected voiddoDeleteLedgers(List<MLDataFormats.ManagedLedgerInfo.LedgerInfo> ledgersToDelete) Get a list of all the active cursors reading from this ManagedLedger.longgetClock()Returns managed-ledger config.longlongGet a list of all the cursors reading from this ManagedLedger.Get the publishing time of the oldest message in the backlog.CompletableFuture<Set<org.apache.bookkeeper.net.BookieId>>getEnsemblesAsync(long ledgerId) longlongGet estimated total unconsumed or backlog size in bytes for the managed ledger, without accounting for replicas.longGet estimated backlog size from a specific position.Gets last confirmed entry of the managed ledger.longlonglongGet last failed offloaded timestamp.longGet last offloaded ledgerId.longGet last suceessful offloaded timestamp.getLedgerInfo(long ledgerId) Get basic ledger summary.getLedgerMetadata(long ledgerId) protected MLDataFormats.ManagedLedgerInfoGet the ManagedLedgerInterceptor for ManagedLedger.getManagedLedgerInternalStats(boolean includeLedgerMetadata) Get managed ledger internal stats.getName()getNextValidLedger(long ledgerId) getNextValidPosition(PositionImpl position) getNextValidPositionInternal(PositionImpl position) longGet the total number of active entries for this managed ledger.longGet the total number of entries for this managed ledger.longReturn the size of all ledgers offloaded to 2nd tier storage.getOptionalLedgerInfo(long ledgerId) Get basic ledger summary.intgetPositionAfterN(PositionImpl startPosition, long n, ManagedLedgerImpl.PositionBound startRange) Get the entry position at a given distance from a given position.getPreviousPosition(PositionImpl position) Get the entry position that come before the specified position in the message stream, using information from the ledger list and each ledger entries count.Returns managed-ledger's properties.Get the slowest consumer.getState()getStats()longGet the total sizes in bytes of the managed ledger, without accounting for replicas.getValidPositionAfterSkippedEntries(PositionImpl position, int skippedEntryNum) intprotected voidbooleanTells whether the managed ledger has any active-cursor registered.booleanhasMoreEntries(PositionImpl position) protected voidinitializeBookKeeper(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.ManagedLedgerInitializeLedgerCallback callback) protected voidinitializeCursors(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.ManagedLedgerInitializeLedgerCallback callback) protected voidinternalAsyncAddEntry(OpAddEntry addOperation) voidinvalidateLedgerHandle(org.apache.bookkeeper.client.api.ReadHandle ledgerHandle) booleanisCursorActive(ManagedCursor cursor) booleanReturns whether the managed ledger was migrated.booleanprotected booleanbooleanReturns whether the managed ledger was terminated.booleanisValidPosition(PositionImpl position) Validate whether a specified position is valid for the current managed ledger.booleanledgerExists(long ledgerId) voidnewNonDurableCursor(Position startCursorPosition) Creates a new cursor whose metadata is not backed by durable storage.newNonDurableCursor(Position startPosition, String subscriptionName) newNonDurableCursor(Position startCursorPosition, String cursorName, CommandSubscribe.InitialPosition initialPosition, boolean isReadCompacted) offloadPrefix(Position pos) Offload as many entries before position as possible to longterm storage.voidonCursorReadPositionUpdated(ManagedCursorImpl cursor, Position newReadPosition) openCursor(String cursorName) Open a ManagedCursor in this ManagedLedger.openCursor(String cursorName, CommandSubscribe.InitialPosition initialPosition) Open a ManagedCursor in this ManagedLedger.openCursor(String cursorName, CommandSubscribe.InitialPosition initialPosition, Map<String, Long> properties, Map<String, String> cursorProperties) Open a ManagedCursor in this ManagedLedger.voidSignaling managed ledger that we can resume after BK write failure.voidremoveWaitingCursor(ManagedCursor cursor) Remove a ManagedCursor from this ManagedLedger's waitingCursors.voidRoll current ledger if it is full.voidsetConfig(ManagedLedgerConfig config) Updates managed-ledger config.voidsetEntriesAddedCounter(long count) voidsetProperties(Map<String, String> properties) Update managed-ledger's properties.voidsetProperty(String key, String value) Add key-value to propertiesMap.voidskipNonRecoverableLedger(long ledgerId) If a ledger is lost, this ledger will be skipped after enabled "autoSkipNonRecoverableData", and the method is used to delete information about this ledger in the ManagedCursor.Terminate the managed ledger and return the last committed entry.voidtrimConsumedLedgersInBackground(boolean isTruncate, CompletableFuture<?> promise) voidtrimConsumedLedgersInBackground(CompletableFuture<?> promise) Trim consumed ledgers in background.protected voidprotected voidupdateLedgersIdsComplete(LedgerHandle originalCurrentLedger)
-
Field Details
-
AsyncOperationTimeoutSeconds
protected static final int AsyncOperationTimeoutSeconds- See Also:
-
bookKeeper
-
name
-
digestType
-
config
-
propertiesMap
-
store
-
ledgers
-
ledgersStat
-
currentLedger
-
currentLedgerEntries
protected volatile long currentLedgerEntries -
currentLedgerSize
protected volatile long currentLedgerSize -
lastLedgerCreatedTimestamp
protected volatile long lastLedgerCreatedTimestamp -
mlOwnershipChecker
-
managedLedgerInterceptor
-
lastAddEntryTimeMs
protected volatile long lastAddEntryTimeMs -
DEFAULT_LEDGER_DELETE_RETRIES
protected static final int DEFAULT_LEDGER_DELETE_RETRIES- See Also:
-
DEFAULT_LEDGER_DELETE_BACKOFF_TIME_SEC
protected static final int DEFAULT_LEDGER_DELETE_BACKOFF_TIME_SEC- See Also:
-
STATE_UPDATER
protected static final AtomicReferenceFieldUpdater<ManagedLedgerImpl,ManagedLedgerImpl.State> STATE_UPDATER -
state
-
executor
-
mbean
-
clock
-
ADD_OP_COUNT_UPDATER
-
-
Constructor Details
-
ManagedLedgerImpl
public ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, BookKeeper bookKeeper, MetaStore store, ManagedLedgerConfig config, org.apache.bookkeeper.common.util.OrderedScheduler scheduledExecutor, String name) -
ManagedLedgerImpl
public ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, BookKeeper bookKeeper, MetaStore store, ManagedLedgerConfig config, org.apache.bookkeeper.common.util.OrderedScheduler scheduledExecutor, String name, Supplier<CompletableFuture<Boolean>> mlOwnershipChecker)
-
-
Method Details
-
initializeBookKeeper
protected void initializeBookKeeper(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.ManagedLedgerInitializeLedgerCallback callback) -
initializeCursors
protected void initializeCursors(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.ManagedLedgerInitializeLedgerCallback callback) -
getName
- Specified by:
getNamein interfaceManagedLedger- Returns:
- the unique name of this ManagedLedger
-
addEntry
Description copied from interface:ManagedLedgerAppend a new entry to the end of a managed ledger.- Specified by:
addEntryin interfaceManagedLedger- Parameters:
data- data entry to be persisted- Returns:
- the Position at which the entry has been inserted
- Throws:
ManagedLedgerExceptionInterruptedException
-
addEntry
public Position addEntry(byte[] data, int numberOfMessages) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedLedgerAppend a new entry to the end of a managed ledger.- Specified by:
addEntryin interfaceManagedLedger- Parameters:
data- data entry to be persistednumberOfMessages- numberOfMessages of entry- Returns:
- the Position at which the entry has been inserted
- Throws:
ManagedLedgerExceptionInterruptedException
-
addEntry
public Position addEntry(byte[] data, int offset, int length) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedLedgerAppend a new entry to the end of a managed ledger.- Specified by:
addEntryin interfaceManagedLedger- Parameters:
data- data entry to be persistedoffset- offset in the data arraylength- number of bytes- Returns:
- the Position at which the entry has been inserted
- Throws:
ManagedLedgerExceptionInterruptedException
-
addEntry
public Position addEntry(byte[] data, int numberOfMessages, int offset, int length) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedLedgerAppend a new entry to the end of a managed ledger.- Specified by:
addEntryin interfaceManagedLedger- Parameters:
data- data entry to be persistednumberOfMessages- numberOfMessages of entryoffset- offset in the data arraylength- number of bytes- Returns:
- the Position at which the entry has been inserted
- Throws:
ManagedLedgerExceptionInterruptedException
-
asyncAddEntry
Description copied from interface:ManagedLedgerAppend a new entry asynchronously.- Specified by:
asyncAddEntryin interfaceManagedLedger- Parameters:
data- data entry to be persistedcallback- callback objectctx- opaque context- See Also:
-
asyncAddEntry
public void asyncAddEntry(byte[] data, int offset, int length, AsyncCallbacks.AddEntryCallback callback, Object ctx) Description copied from interface:ManagedLedgerAppend a new entry asynchronously.- Specified by:
asyncAddEntryin interfaceManagedLedger- Parameters:
data- data entry to be persistedoffset- offset in the data arraylength- number of bytescallback- callback objectctx- opaque context- See Also:
-
asyncAddEntry
public void asyncAddEntry(byte[] data, int numberOfMessages, int offset, int length, AsyncCallbacks.AddEntryCallback callback, Object ctx) Description copied from interface:ManagedLedgerAppend a new entry asynchronously.- Specified by:
asyncAddEntryin interfaceManagedLedger- Parameters:
data- data entry to be persistednumberOfMessages- numberOfMessages of entryoffset- offset in the data arraylength- number of bytescallback- callback objectctx- opaque context- See Also:
-
asyncAddEntry
public void asyncAddEntry(io.netty.buffer.ByteBuf buffer, AsyncCallbacks.AddEntryCallback callback, Object ctx) Description copied from interface:ManagedLedgerAppend a new entry asynchronously.- Specified by:
asyncAddEntryin interfaceManagedLedger- Parameters:
buffer- buffer with the data entrycallback- callback objectctx- opaque context- See Also:
-
asyncAddEntry
public void asyncAddEntry(io.netty.buffer.ByteBuf buffer, int numberOfMessages, AsyncCallbacks.AddEntryCallback callback, Object ctx) Description copied from interface:ManagedLedgerAppend a new entry asynchronously.- Specified by:
asyncAddEntryin interfaceManagedLedger- Parameters:
buffer- buffer with the data entrynumberOfMessages- numberOfMessages for data entrycallback- callback objectctx- opaque context- See Also:
-
internalAsyncAddEntry
-
afterFailedAddEntry
protected void afterFailedAddEntry(int numOfMessages) -
beforeAddEntry
-
readyToCreateNewLedger
public void readyToCreateNewLedger()Description copied from interface:ManagedLedgerSignaling managed ledger that we can resume after BK write failure.- Specified by:
readyToCreateNewLedgerin interfaceManagedLedger
-
openCursor
public ManagedCursor openCursor(String cursorName) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedLedgerOpen a ManagedCursor in this ManagedLedger. If the cursors doesn't exist, a new one will be created and its position will be at the end of the ManagedLedger.- Specified by:
openCursorin interfaceManagedLedger- Parameters:
cursorName- the name associated with the ManagedCursor- Returns:
- the ManagedCursor
- Throws:
ManagedLedgerExceptionInterruptedException
-
openCursor
public ManagedCursor openCursor(String cursorName, CommandSubscribe.InitialPosition initialPosition) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedLedgerOpen a ManagedCursor in this ManagedLedger.If the cursors doesn't exist, a new one will be created and its position will be at the end of the ManagedLedger.
- Specified by:
openCursorin interfaceManagedLedger- Parameters:
cursorName- the name associated with the ManagedCursorinitialPosition- if null, the cursor will be set at latest position when first created- Returns:
- the ManagedCursor
- Throws:
ManagedLedgerExceptionInterruptedException
-
openCursor
public ManagedCursor openCursor(String cursorName, CommandSubscribe.InitialPosition initialPosition, Map<String, Long> properties, Map<String, throws InterruptedException, ManagedLedgerExceptionString> cursorProperties) Description copied from interface:ManagedLedgerOpen a ManagedCursor in this ManagedLedger.If the cursors doesn't exist, a new one will be created and its position will be at the end of the ManagedLedger.
- Specified by:
openCursorin interfaceManagedLedger- Parameters:
cursorName- the name associated with the ManagedCursorinitialPosition- if null, the cursor will be set at latest position when first createdproperties- user defined properties that will be attached to the first position of the cursor, if the open operation will trigger the creation of the cursor.cursorProperties- the properties for the Cursor- Returns:
- the ManagedCursor
- Throws:
ManagedLedgerExceptionInterruptedException
-
asyncOpenCursor
public void asyncOpenCursor(String cursorName, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Description copied from interface:ManagedLedgerOpen a ManagedCursor asynchronously.- Specified by:
asyncOpenCursorin interfaceManagedLedger- Parameters:
cursorName- the name associated with the ManagedCursorcallback- callback objectctx- opaque context- See Also:
-
asyncOpenCursor
public void asyncOpenCursor(String cursorName, CommandSubscribe.InitialPosition initialPosition, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Description copied from interface:ManagedLedgerOpen a ManagedCursor asynchronously.- Specified by:
asyncOpenCursorin interfaceManagedLedger- Parameters:
cursorName- the name associated with the ManagedCursorinitialPosition- if null, the cursor will be set at latest position when first createdcallback- callback objectctx- opaque context- See Also:
-
asyncOpenCursor
public void asyncOpenCursor(String cursorName, CommandSubscribe.InitialPosition initialPosition, Map<String, Long> properties, Map<String, String> cursorProperties, AsyncCallbacks.OpenCursorCallback callback, Object ctx) Description copied from interface:ManagedLedgerOpen a ManagedCursor asynchronously.- Specified by:
asyncOpenCursorin interfaceManagedLedger- Parameters:
cursorName- the name associated with the ManagedCursorinitialPosition- if null, the cursor will be set at latest position when first createdcursorProperties- the properties for the Cursorcallback- callback objectctx- opaque context- See Also:
-
asyncDeleteCursor
public void asyncDeleteCursor(String consumerName, AsyncCallbacks.DeleteCursorCallback callback, Object ctx) Description copied from interface:ManagedLedgerDelete a ManagedCursor asynchronously.- Specified by:
asyncDeleteCursorin interfaceManagedLedger- Parameters:
consumerName- the name associated with the ManagedCursorcallback- callback objectctx- opaque context- See Also:
-
deleteCursor
Description copied from interface:ManagedLedgerRemove a ManagedCursor from this ManagedLedger. If the cursor doesn't exist, the operation will still succeed.- Specified by:
deleteCursorin interfaceManagedLedger- Parameters:
name- the name associated with the ManagedCursor- Throws:
InterruptedExceptionManagedLedgerException
-
newNonDurableCursor
public ManagedCursor newNonDurableCursor(Position startCursorPosition) throws ManagedLedgerException Description copied from interface:ManagedLedgerCreates a new cursor whose metadata is not backed by durable storage. A caller can treat the non-durable cursor exactly like a normal cursor, with the only difference in that after restart it will not remember which entries were deleted. Also it does not prevent data from being deleted. The cursor is anonymous and can be positioned on an arbitrary position. This method is not-blocking.- Specified by:
newNonDurableCursorin interfaceManagedLedger- Parameters:
startCursorPosition- the position where the cursor should be initialized, or null to start from the current latest entry. When starting on a particular cursor position, the first entry to be returned will be the entry next to the specified position- Returns:
- the new NonDurableCursor
- Throws:
ManagedLedgerException
-
newNonDurableCursor
public ManagedCursor newNonDurableCursor(Position startPosition, String subscriptionName) throws ManagedLedgerException - Specified by:
newNonDurableCursorin interfaceManagedLedger- Throws:
ManagedLedgerException
-
newNonDurableCursor
public ManagedCursor newNonDurableCursor(Position startCursorPosition, String cursorName, CommandSubscribe.InitialPosition initialPosition, boolean isReadCompacted) throws ManagedLedgerException - Specified by:
newNonDurableCursorin interfaceManagedLedger- Throws:
ManagedLedgerException
-
getCursors
Description copied from interface:ManagedLedgerGet a list of all the cursors reading from this ManagedLedger.- Specified by:
getCursorsin interfaceManagedLedger- Returns:
- a list of cursors
-
getActiveCursors
Description copied from interface:ManagedLedgerGet a list of all the active cursors reading from this ManagedLedger.- Specified by:
getActiveCursorsin interfaceManagedLedger- Returns:
- a list of cursors
-
hasActiveCursors
public boolean hasActiveCursors()Tells whether the managed ledger has any active-cursor registered.- Returns:
- true if at least a cursor exists
-
getNumberOfEntries
public long getNumberOfEntries()Description copied from interface:ManagedLedgerGet the total number of entries for this managed ledger. This is defined by the number of entries in all the BookKeeper ledgers that are being maintained by this ManagedLedger. This method is non-blocking.- Specified by:
getNumberOfEntriesin interfaceManagedLedger- Returns:
- the number of entries
-
getNumberOfActiveEntries
public long getNumberOfActiveEntries()Description copied from interface:ManagedLedgerGet the total number of active entries for this managed ledger. This is defined by the number of non consumed entries in all the BookKeeper ledgers that are being maintained by this ManagedLedger. This method is non-blocking.- Specified by:
getNumberOfActiveEntriesin interfaceManagedLedger- Returns:
- the number of entries
-
getTotalSize
public long getTotalSize()Description copied from interface:ManagedLedgerGet the total sizes in bytes of the managed ledger, without accounting for replicas. This is defined by the sizes of all the BookKeeper ledgers that are being maintained by this ManagedLedger. This method is non-blocking.- Specified by:
getTotalSizein interfaceManagedLedger- Returns:
- total size in bytes
-
getEstimatedBacklogSize
public long getEstimatedBacklogSize()Description copied from interface:ManagedLedgerGet estimated total unconsumed or backlog size in bytes for the managed ledger, without accounting for replicas.- Specified by:
getEstimatedBacklogSizein interfaceManagedLedger- Returns:
- estimated total backlog size
-
getEarliestMessagePublishTimeInBacklog
Description copied from interface:ManagedLedgerGet the publishing time of the oldest message in the backlog.- Specified by:
getEarliestMessagePublishTimeInBacklogin interfaceManagedLedger- Returns:
- the publishing time of the oldest message
-
getEarliestMessagePublishTimeOfPos
-
getEstimatedBacklogSize
Get estimated backlog size from a specific position. -
asyncMigrate
- Specified by:
asyncMigratein interfaceManagedLedger
-
asyncTerminate
- Specified by:
asyncTerminatein interfaceManagedLedger
-
terminate
Description copied from interface:ManagedLedgerTerminate the managed ledger and return the last committed entry. Once the managed ledger is terminated, it will not accept any more write- Specified by:
terminatein interfaceManagedLedger- Returns:
- Throws:
InterruptedExceptionManagedLedgerException
-
isTerminated
public boolean isTerminated()Description copied from interface:ManagedLedgerReturns whether the managed ledger was terminated.- Specified by:
isTerminatedin interfaceManagedLedger
-
isMigrated
public boolean isMigrated()Description copied from interface:ManagedLedgerReturns whether the managed ledger was migrated.- Specified by:
isMigratedin interfaceManagedLedger
-
close
Description copied from interface:ManagedLedgerClose the ManagedLedger. This will close all the underlying BookKeeper ledgers. All the ManagedCursors associated will be invalidated.- Specified by:
closein interfaceManagedLedger- Throws:
ManagedLedgerExceptionInterruptedException
-
asyncClose
Description copied from interface:ManagedLedgerClose the ManagedLedger asynchronously.- Specified by:
asyncClosein interfaceManagedLedger- Parameters:
callback- callback objectctx- opaque context- See Also:
-
createComplete
- Specified by:
createCompletein interfaceAsyncCallback.CreateCallback
-
handleBadVersion
-
updateLedgersIdsComplete
-
skipNonRecoverableLedger
public void skipNonRecoverableLedger(long ledgerId) Description copied from interface:ManagedLedgerIf a ledger is lost, this ledger will be skipped after enabled "autoSkipNonRecoverableData", and the method is used to delete information about this ledger in the ManagedCursor.- Specified by:
skipNonRecoverableLedgerin interfaceManagedLedger
-
rollCurrentLedgerIfFull
public void rollCurrentLedgerIfFull()Description copied from interface:ManagedLedgerRoll current ledger if it is full.- Specified by:
rollCurrentLedgerIfFullin interfaceManagedLedger
-
asyncFindPosition
Description copied from interface:ManagedLedgerFind position by sequenceId.- Specified by:
asyncFindPositionin interfaceManagedLedger
-
getManagedLedgerInterceptor
Description copied from interface:ManagedLedgerGet the ManagedLedgerInterceptor for ManagedLedger.- Specified by:
getManagedLedgerInterceptorin interfaceManagedLedger
-
getLedgerMetadata
-
getLedgerInfo
Description copied from interface:ManagedLedgerGet basic ledger summary. will got null if corresponding ledger not exists.- Specified by:
getLedgerInfoin interfaceManagedLedger
-
getOptionalLedgerInfo
Description copied from interface:ManagedLedgerGet basic ledger summary. will getOptional.empty()if corresponding ledger not exists.- Specified by:
getOptionalLedgerInfoin interfaceManagedLedger
-
invalidateLedgerHandle
public void invalidateLedgerHandle(org.apache.bookkeeper.client.api.ReadHandle ledgerHandle) -
asyncReadEntry
public void asyncReadEntry(PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, Object ctx) -
asyncReadEntry
protected void asyncReadEntry(org.apache.bookkeeper.client.api.ReadHandle ledger, PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, Object ctx) -
asyncReadEntry
protected void asyncReadEntry(org.apache.bookkeeper.client.api.ReadHandle ledger, long firstEntry, long lastEntry, org.apache.bookkeeper.mledger.impl.OpReadEntry opReadEntry, Object ctx) -
getStats
- Specified by:
getStatsin interfaceManagedLedger- Returns:
- the managed ledger stats MBean
-
hasMoreEntries
-
onCursorReadPositionUpdated
-
addWaitingEntryCallBack
-
maybeUpdateCursorBeforeTrimmingConsumedLedger
public void maybeUpdateCursorBeforeTrimmingConsumedLedger() -
trimConsumedLedgersInBackground
Description copied from interface:ManagedLedgerTrim consumed ledgers in background.- Specified by:
trimConsumedLedgersInBackgroundin interfaceManagedLedger
-
trimConsumedLedgersInBackground
-
doDeleteLedgers
-
delete
Delete this ManagedLedger completely from the system.- Specified by:
deletein interfaceManagedLedger- Throws:
ExceptionInterruptedExceptionManagedLedgerException
-
asyncDelete
Description copied from interface:ManagedLedgerAsync delete a ledger.- Specified by:
asyncDeletein interfaceManagedLedger
-
offloadPrefix
Description copied from interface:ManagedLedgerOffload as many entries before position as possible to longterm storage.- Specified by:
offloadPrefixin interfaceManagedLedger- Parameters:
pos- the position before which entries will be offloaded- Returns:
- the earliest position which was not offloaded
- Throws:
InterruptedExceptionManagedLedgerException- See Also:
-
asyncOffloadPrefix
Description copied from interface:ManagedLedgerOffload as many entries before position as possible to longterm storage. As internally, entries is stored in ledgers, and ledgers can only be operated on as a whole, it is likely not possible to offload every entry before the passed in position. Only complete ledgers will be offloaded. On completion a position will be passed to the callback. This position is the earliest entry which was not offloaded.- Specified by:
asyncOffloadPrefixin interfaceManagedLedger- Parameters:
pos- the position before which entries will be offloadedcallback- a callback which will be supplied with the earliest unoffloaded position on completionctx- a context object which will be passed to the callback on completion
-
getPositionAfterN
public PositionImpl getPositionAfterN(PositionImpl startPosition, long n, ManagedLedgerImpl.PositionBound startRange) Get the entry position at a given distance from a given position.- Parameters:
startPosition- starting positionn- number of entries to skip aheadstartRange- specifies whether to include the start position in calculating the distance- Returns:
- the new position that is n entries ahead
-
isNoMessagesAfterPos
-
getPreviousPosition
Get the entry position that come before the specified position in the message stream, using information from the ledger list and each ledger entries count.- Parameters:
position- the current position- Returns:
- the previous position
-
isValidPosition
Validate whether a specified position is valid for the current managed ledger.- Parameters:
position- the position to validate- Returns:
- true if the position is valid, false otherwise
-
ledgerExists
public boolean ledgerExists(long ledgerId) -
getNextValidLedger
-
getNextValidPosition
-
getValidPositionAfterSkippedEntries
-
getNextValidPositionInternal
-
getFirstPosition
-
getSlowestConsumer
Description copied from interface:ManagedLedgerGet the slowest consumer.- Specified by:
getSlowestConsumerin interfaceManagedLedger- Returns:
- the slowest consumer
-
activateCursor
-
deactivateCursor
-
removeWaitingCursor
Description copied from interface:ManagedLedgerRemove a ManagedCursor from this ManagedLedger's waitingCursors.- Specified by:
removeWaitingCursorin interfaceManagedLedger- Parameters:
cursor- the ManagedCursor
-
addWaitingCursor
-
isCursorActive
-
getLedgersInfoAsList
-
getLedgersInfo
-
getManagedLedgerInfo
-
getConfig
Description copied from interface:ManagedLedgerReturns managed-ledger config.- Specified by:
getConfigin interfaceManagedLedger
-
setConfig
Description copied from interface:ManagedLedgerUpdates managed-ledger config.- Specified by:
setConfigin interfaceManagedLedger
-
getEntriesAddedCounter
public long getEntriesAddedCounter() -
getCurrentLedgerEntries
public long getCurrentLedgerEntries() -
getCurrentLedgerSize
public long getCurrentLedgerSize() -
getLastLedgerCreatedTimestamp
public long getLastLedgerCreatedTimestamp() -
getLastLedgerCreationFailureTimestamp
public long getLastLedgerCreationFailureTimestamp() -
getWaitingCursorsCount
public int getWaitingCursorsCount() -
getPendingAddEntriesCount
public int getPendingAddEntriesCount() -
getLastConfirmedEntry
Description copied from interface:ManagedLedgerGets last confirmed entry of the managed ledger.- Specified by:
getLastConfirmedEntryin interfaceManagedLedger- Returns:
- the last confirmed entry id
-
getState
-
getCacheSize
public long getCacheSize() -
isReadOnly
protected boolean isReadOnly() -
createManagedLedgerException
-
createManagedLedgerException
-
asyncCreateLedger
protected void asyncCreateLedger(BookKeeper bookKeeper, ManagedLedgerConfig config, BookKeeper.DigestType digestType, AsyncCallback.CreateCallback cb, Map<String, byte[]> metadata) Create ledger async and schedule a timeout task to check ledger-creation is complete else it fails the callback with TimeoutException.- Parameters:
bookKeeper-config-digestType-cb-metadata-
-
getClock
-
checkAndCompleteLedgerOpTask
check if ledger-op task is already completed by timeout-task. If completed then delete the created ledger- Returns:
-
getOffloadedSize
public long getOffloadedSize()Description copied from interface:ManagedLedgerReturn the size of all ledgers offloaded to 2nd tier storage.- Specified by:
getOffloadedSizein interfaceManagedLedger
-
getLastOffloadedLedgerId
public long getLastOffloadedLedgerId()Description copied from interface:ManagedLedgerGet last offloaded ledgerId. If no offloaded yet, it returns 0.- Specified by:
getLastOffloadedLedgerIdin interfaceManagedLedger- Returns:
- last offloaded ledgerId
-
getLastOffloadedSuccessTimestamp
public long getLastOffloadedSuccessTimestamp()Description copied from interface:ManagedLedgerGet last suceessful offloaded timestamp. If no successful offload, it returns 0.- Specified by:
getLastOffloadedSuccessTimestampin interfaceManagedLedger- Returns:
- last successful offloaded timestamp
-
getLastOffloadedFailureTimestamp
public long getLastOffloadedFailureTimestamp()Description copied from interface:ManagedLedgerGet last failed offloaded timestamp. If no failed offload, it returns 0.- Specified by:
getLastOffloadedFailureTimestampin interfaceManagedLedger- Returns:
- last failed offloaded timestamp
-
getProperties
Description copied from interface:ManagedLedgerReturns managed-ledger's properties.- Specified by:
getPropertiesin interfaceManagedLedger- Returns:
- key-values of properties
-
setProperty
public void setProperty(String key, String value) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedLedgerAdd key-value to propertiesMap.- Specified by:
setPropertyin interfaceManagedLedger- Parameters:
key- key of property to addvalue- value of property to add- Throws:
InterruptedExceptionManagedLedgerException
-
asyncSetProperty
public void asyncSetProperty(String key, String value, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Description copied from interface:ManagedLedgerAsync add key-value to propertiesMap.- Specified by:
asyncSetPropertyin interfaceManagedLedger- Parameters:
key- key of property to addvalue- value of property to addcallback- a callback which will be supplied with the newest properties in managedLedger.ctx- a context object which will be passed to the callback on completion.
-
deleteProperty
Description copied from interface:ManagedLedgerDelete the property by key.- Specified by:
deletePropertyin interfaceManagedLedger- Parameters:
key- key of property to delete- Throws:
InterruptedExceptionManagedLedgerException
-
asyncDeleteProperty
public void asyncDeleteProperty(String key, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Description copied from interface:ManagedLedgerAsync delete the property by key.- Specified by:
asyncDeletePropertyin interfaceManagedLedger- Parameters:
key- key of property to deletecallback- a callback which will be supplied with the newest properties in managedLedger.ctx- a context object which will be passed to the callback on completion.
-
setProperties
public void setProperties(Map<String, String> properties) throws InterruptedException, ManagedLedgerExceptionDescription copied from interface:ManagedLedgerUpdate managed-ledger's properties.- Specified by:
setPropertiesin interfaceManagedLedger- Parameters:
properties- key-values of properties- Throws:
InterruptedExceptionManagedLedgerException
-
asyncSetProperties
public void asyncSetProperties(Map<String, String> properties, AsyncCallbacks.UpdatePropertiesCallback callback, Object ctx) Description copied from interface:ManagedLedgerAsync update managed-ledger's properties.- Specified by:
asyncSetPropertiesin interfaceManagedLedger- Parameters:
properties- key-values of properties.callback- a callback which will be supplied with the newest properties in managedLedger.ctx- a context object which will be passed to the callback on completion.
-
setEntriesAddedCounter
public void setEntriesAddedCounter(long count) -
asyncTruncate
Description copied from interface:ManagedLedgerTruncate ledgers The truncate operation will move all cursors to the end of the topic and delete all inactive ledgers.- Specified by:
asyncTruncatein interfaceManagedLedger
-
getManagedLedgerInternalStats
public CompletableFuture<ManagedLedgerInternalStats> getManagedLedgerInternalStats(boolean includeLedgerMetadata) Description copied from interface:ManagedLedgerGet managed ledger internal stats.- Specified by:
getManagedLedgerInternalStatsin interfaceManagedLedger- Parameters:
includeLedgerMetadata- the flag to control managed ledger internal stats include ledger metadata- Returns:
- the future of managed ledger internal stats
-
getEnsemblesAsync
-
updateLastLedgerCreatedTimeAndScheduleRolloverTask
protected void updateLastLedgerCreatedTimeAndScheduleRolloverTask() -
checkInactiveLedgerAndRollOver
public boolean checkInactiveLedgerAndRollOver()Description copied from interface:ManagedLedgerCheck current inactive ledger (based onManagedLedgerConfig.getInactiveLedgerRollOverTimeMs()and roll over that ledger if inactive.- Specified by:
checkInactiveLedgerAndRollOverin interfaceManagedLedger- Returns:
- true if ledger is considered for rolling over
-
checkCursorsToCacheEntries
public void checkCursorsToCacheEntries()Description copied from interface:ManagedLedgerCheck if managed ledger should cache backlog reads.- Specified by:
checkCursorsToCacheEntriesin interfaceManagedLedger
-
getTheSlowestNonDurationReadPosition
-