Class ManagedLedgerImpl
- java.lang.Object
-
- org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl
-
- All Implemented Interfaces:
org.apache.bookkeeper.client.AsyncCallback.CreateCallback,ManagedLedger
- Direct Known Subclasses:
ReadOnlyManagedLedgerImpl
public class ManagedLedgerImpl extends java.lang.Object implements ManagedLedger, org.apache.bookkeeper.client.AsyncCallback.CreateCallback
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classManagedLedgerImpl.PositionBoundstatic classManagedLedgerImpl.State
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.concurrent.atomic.AtomicLongFieldUpdater<ManagedLedgerImpl>ADD_OP_COUNT_UPDATERprotected static intAsyncOperationTimeoutSecondsprotected org.apache.bookkeeper.client.BookKeeperbookKeeperprotected java.time.Clockclockprotected ManagedLedgerConfigconfigprotected static intDEFAULT_LEDGER_DELETE_BACKOFF_TIME_SECprotected static intDEFAULT_LEDGER_DELETE_RETRIESprotected java.util.NavigableMap<java.lang.Long,MLDataFormats.ManagedLedgerInfo.LedgerInfo>ledgersprotected ManagedLedgerMBeanImplmbeanprotected java.util.function.Supplier<java.lang.Boolean>mlOwnershipCheckerprotected java.lang.Stringnameprotected java.util.Map<java.lang.String,java.lang.String>propertiesMapprotected ManagedLedgerImpl.Statestateprotected MetaStorestore
-
Constructor Summary
Constructors Constructor Description ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, org.apache.bookkeeper.client.BookKeeper bookKeeper, MetaStore store, ManagedLedgerConfig config, org.apache.bookkeeper.common.util.OrderedScheduler scheduledExecutor, java.lang.String name)ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, org.apache.bookkeeper.client.BookKeeper bookKeeper, MetaStore store, ManagedLedgerConfig config, org.apache.bookkeeper.common.util.OrderedScheduler scheduledExecutor, java.lang.String name, java.util.function.Supplier<java.lang.Boolean> mlOwnershipChecker)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateCursor(ManagedCursor cursor)PositionaddEntry(byte[] data)Append a new entry to the end of a managed ledger.PositionaddEntry(byte[] data, int numberOfMessages)Append a new entry to the end of a managed ledger.PositionaddEntry(byte[] data, int offset, int length)Append a new entry to the end of a managed ledger.PositionaddEntry(byte[] data, int numberOfMessages, int offset, int length)Append a new entry to the end of a managed ledger.voidaddWaitingEntryCallBack(WaitingEntryCallBack cb)voidasyncAddEntry(byte[] data, int numberOfMessages, int offset, int length, AsyncCallbacks.AddEntryCallback callback, java.lang.Object ctx)Append a new entry asynchronously.voidasyncAddEntry(byte[] data, int offset, int length, AsyncCallbacks.AddEntryCallback callback, java.lang.Object ctx)Append a new entry asynchronously.voidasyncAddEntry(byte[] data, AsyncCallbacks.AddEntryCallback callback, java.lang.Object ctx)Append a new entry asynchronously.voidasyncAddEntry(io.netty.buffer.ByteBuf buffer, int numberOfMessages, AsyncCallbacks.AddEntryCallback callback, java.lang.Object ctx)Append a new entry asynchronously.voidasyncAddEntry(io.netty.buffer.ByteBuf buffer, AsyncCallbacks.AddEntryCallback callback, java.lang.Object ctx)Append a new entry asynchronously.voidasyncClose(AsyncCallbacks.CloseCallback callback, java.lang.Object ctx)Close the ManagedLedger asynchronously.protected voidasyncCreateLedger(org.apache.bookkeeper.client.BookKeeper bookKeeper, ManagedLedgerConfig config, org.apache.bookkeeper.client.BookKeeper.DigestType digestType, org.apache.bookkeeper.client.AsyncCallback.CreateCallback cb, java.util.Map<java.lang.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, java.lang.Object ctx)Async delete a ledger.voidasyncDeleteCursor(java.lang.String consumerName, AsyncCallbacks.DeleteCursorCallback callback, java.lang.Object ctx)Delete a ManagedCursor asynchronously.voidasyncDeleteProperty(java.lang.String key, AsyncCallbacks.UpdatePropertiesCallback callback, java.lang.Object ctx)Async delete the property by key.java.util.concurrent.CompletableFuture<Position>asyncFindPosition(com.google.common.base.Predicate<Entry> predicate)Find position by sequenceId.voidasyncOffloadPrefix(Position pos, AsyncCallbacks.OffloadCallback callback, java.lang.Object ctx)Offload as many entries before position as possible to longterm storage.voidasyncOpenCursor(java.lang.String cursorName, AsyncCallbacks.OpenCursorCallback callback, java.lang.Object ctx)Open a ManagedCursor asynchronously.voidasyncOpenCursor(java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, java.util.Map<java.lang.String,java.lang.Long> properties, AsyncCallbacks.OpenCursorCallback callback, java.lang.Object ctx)Open a ManagedCursor asynchronously.voidasyncOpenCursor(java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, AsyncCallbacks.OpenCursorCallback callback, java.lang.Object ctx)Open a ManagedCursor asynchronously.protected voidasyncReadEntry(org.apache.bookkeeper.client.api.ReadHandle ledger, long firstEntry, long lastEntry, boolean isSlowestReader, org.apache.bookkeeper.mledger.impl.OpReadEntry opReadEntry, java.lang.Object ctx)protected voidasyncReadEntry(org.apache.bookkeeper.client.api.ReadHandle ledger, PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, java.lang.Object ctx)voidasyncReadEntry(PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, java.lang.Object ctx)voidasyncSetProperties(java.util.Map<java.lang.String,java.lang.String> properties, AsyncCallbacks.UpdatePropertiesCallback callback, java.lang.Object ctx)Async update managed-ledger's properties.voidasyncSetProperty(java.lang.String key, java.lang.String value, AsyncCallbacks.UpdatePropertiesCallback callback, java.lang.Object ctx)Async add key-value to propertiesMap.voidasyncTerminate(AsyncCallbacks.TerminateCallback callback, java.lang.Object ctx)java.util.concurrent.CompletableFuture<java.lang.Void>asyncTruncate()Truncate ledgers The truncate operation will move all cursors to the end of the topic and delete all inactive ledgers.protected booleancheckAndCompleteLedgerOpTask(int rc, org.apache.bookkeeper.client.LedgerHandle lh, java.lang.Object ctx)check if ledger-op task is already completed by timeout-task.voidclose()Close the ManagedLedger.voidcreateComplete(int rc, org.apache.bookkeeper.client.LedgerHandle lh, java.lang.Object ctx)static ManagedLedgerExceptioncreateManagedLedgerException(int bkErrorCode)static ManagedLedgerExceptioncreateManagedLedgerException(java.lang.Throwable t)voiddeactivateCursor(ManagedCursor cursor)voiddelete()Delete this ManagedLedger completely from the system.voiddeleteCursor(java.lang.String name)Remove a ManagedCursor from this ManagedLedger.voiddeleteProperty(java.lang.String key)Delete the property by key.ManagedCursorContainergetActiveCursors()Get a list of all the active cursors reading from this ManagedLedger.longgetCacheSize()java.time.ClockgetClock()ManagedLedgerConfiggetConfig()Returns managed-ledger config.longgetCurrentLedgerEntries()longgetCurrentLedgerSize()ManagedCursorContainergetCursors()Get a list of all the cursors reading from this ManagedLedgerjava.util.concurrent.CompletableFuture<java.util.Set<org.apache.bookkeeper.net.BookieId>>getEnsemblesAsync(long ledgerId)longgetEntriesAddedCounter()longgetEstimatedBacklogSize()Get estimated total unconsumed or backlog size in bytes for the managed ledger, without accounting for replicas.longgetEstimatedBacklogSize(PositionImpl pos)Get estimated backlog size from a specific position.PositionImplgetFirstPosition()PositiongetLastConfirmedEntry()Gets last confirmed entry of the managed ledger.longgetLastLedgerCreatedTimestamp()longgetLastLedgerCreationFailureTimestamp()java.util.concurrent.CompletableFuture<MLDataFormats.ManagedLedgerInfo.LedgerInfo>getLedgerInfo(long ledgerId)Get basic ledger summary.java.util.concurrent.CompletableFuture<java.lang.String>getLedgerMetadata(long ledgerId)java.util.NavigableMap<java.lang.Long,MLDataFormats.ManagedLedgerInfo.LedgerInfo>getLedgersInfo()java.util.List<MLDataFormats.ManagedLedgerInfo.LedgerInfo>getLedgersInfoAsList()ManagedLedgerInterceptorgetManagedLedgerInterceptor()Get the ManagedLedgerInterceptor for ManagedLedger.java.util.concurrent.CompletableFuture<org.apache.pulsar.common.policies.data.ManagedLedgerInternalStats>getManagedLedgerInternalStats(boolean includeLedgerMetadata)Get managed ledger internal statsManagedLedgerMBeanImplgetMBean()java.lang.StringgetName()java.lang.LonggetNextValidLedger(long ledgerId)PositionImplgetNextValidPosition(PositionImpl position)PositionImplgetNextValidPositionInternal(PositionImpl position)longgetNumberOfActiveEntries()Get the total number of active entries for this managed ledger.longgetNumberOfEntries()Get the total number of entries for this managed ledger.longgetOffloadedSize()Return the size of all ledgers offloaded to 2nd tier storageintgetPendingAddEntriesCount()PositionImplgetPositionAfterN(PositionImpl startPosition, long n, ManagedLedgerImpl.PositionBound startRange)Get the entry position at a given distance from a given position.PositionImplgetPreviousPosition(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.java.util.Map<java.lang.String,java.lang.String>getProperties()Returns managed-ledger's properties.ManagedCursorgetSlowestConsumer()Get the slowest consumer.ManagedLedgerImpl.StategetState()ManagedLedgerMXBeangetStats()longgetTotalSize()Get the total sizes in bytes of the managed ledger, without accounting for replicas.intgetWaitingCursorsCount()booleanhasActiveCursors()Tells whether the managed ledger has any active-cursor registered.booleanhasMoreEntries(PositionImpl position)booleanisCursorActive(ManagedCursor cursor)protected booleanisReadOnly()booleanisTerminated()Returns whether the managed ledger was terminated.booleanisValidPosition(PositionImpl position)Validate whether a specified position is valid for the current managed ledger.booleanledgerExists(long ledgerId)voidmaybeUpdateCursorBeforeTrimmingConsumedLedger()ManagedCursornewNonDurableCursor(Position startCursorPosition)Creates a new cursor whose metadata is not backed by durable storage.ManagedCursornewNonDurableCursor(Position startPosition, java.lang.String subscriptionName)ManagedCursornewNonDurableCursor(Position startCursorPosition, java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition)PositionoffloadPrefix(Position pos)Offload as many entries before position as possible to longterm storage.ManagedCursoropenCursor(java.lang.String cursorName)Open a ManagedCursor in this ManagedLedger.ManagedCursoropenCursor(java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition)Open a ManagedCursor in this ManagedLedger.ManagedCursoropenCursor(java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, java.util.Map<java.lang.String,java.lang.Long> properties)Open a ManagedCursor in this ManagedLedger.voidreadyToCreateNewLedger()Signaling managed ledger that we can resume after BK write failurevoidrollCurrentLedgerIfFull()Roll current ledger if it is fullvoidsetConfig(ManagedLedgerConfig config)Updates managed-ledger config.voidsetEntriesAddedCounter(long count)voidsetProperties(java.util.Map<java.lang.String,java.lang.String> properties)Update managed-ledger's properties.voidsetProperty(java.lang.String key, java.lang.String value)Add key-value to propertiesMap.Positionterminate()Terminate the managed ledger and return the last committed entry.voidtrimConsumedLedgersInBackground(boolean isTruncate, java.util.concurrent.CompletableFuture<?> promise)voidtrimConsumedLedgersInBackground(java.util.concurrent.CompletableFuture<?> promise)Trim consumed ledgers in backgroundvoidupdateLedgersIdsComplete(org.apache.pulsar.metadata.api.Stat stat)
-
-
-
Field Detail
-
AsyncOperationTimeoutSeconds
protected static final int AsyncOperationTimeoutSeconds
- See Also:
- Constant Field Values
-
bookKeeper
protected final org.apache.bookkeeper.client.BookKeeper bookKeeper
-
name
protected final java.lang.String name
-
config
protected ManagedLedgerConfig config
-
propertiesMap
protected java.util.Map<java.lang.String,java.lang.String> propertiesMap
-
store
protected final MetaStore store
-
ledgers
protected final java.util.NavigableMap<java.lang.Long,MLDataFormats.ManagedLedgerInfo.LedgerInfo> ledgers
-
mlOwnershipChecker
protected final java.util.function.Supplier<java.lang.Boolean> mlOwnershipChecker
-
DEFAULT_LEDGER_DELETE_RETRIES
protected static final int DEFAULT_LEDGER_DELETE_RETRIES
- See Also:
- Constant Field Values
-
DEFAULT_LEDGER_DELETE_BACKOFF_TIME_SEC
protected static final int DEFAULT_LEDGER_DELETE_BACKOFF_TIME_SEC
- See Also:
- Constant Field Values
-
state
protected volatile ManagedLedgerImpl.State state
-
mbean
protected final ManagedLedgerMBeanImpl mbean
-
clock
protected final java.time.Clock clock
-
ADD_OP_COUNT_UPDATER
protected static final java.util.concurrent.atomic.AtomicLongFieldUpdater<ManagedLedgerImpl> ADD_OP_COUNT_UPDATER
-
-
Constructor Detail
-
ManagedLedgerImpl
public ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, org.apache.bookkeeper.client.BookKeeper bookKeeper, MetaStore store, ManagedLedgerConfig config, org.apache.bookkeeper.common.util.OrderedScheduler scheduledExecutor, java.lang.String name)
-
ManagedLedgerImpl
public ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, org.apache.bookkeeper.client.BookKeeper bookKeeper, MetaStore store, ManagedLedgerConfig config, org.apache.bookkeeper.common.util.OrderedScheduler scheduledExecutor, java.lang.String name, java.util.function.Supplier<java.lang.Boolean> mlOwnershipChecker)
-
-
Method Detail
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceManagedLedger- Returns:
- the unique name of this ManagedLedger
-
addEntry
public Position addEntry(byte[] data) throws java.lang.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 persisted- Returns:
- the Position at which the entry has been inserted
- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
addEntry
public Position addEntry(byte[] data, int numberOfMessages) throws java.lang.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:
ManagedLedgerExceptionjava.lang.InterruptedException
-
addEntry
public Position addEntry(byte[] data, int offset, int length) throws java.lang.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:
ManagedLedgerExceptionjava.lang.InterruptedException
-
addEntry
public Position addEntry(byte[] data, int numberOfMessages, int offset, int length) throws java.lang.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:
ManagedLedgerExceptionjava.lang.InterruptedException
-
asyncAddEntry
public void asyncAddEntry(byte[] data, AsyncCallbacks.AddEntryCallback callback, java.lang.Object ctx)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:
ManagedLedger.addEntry(byte[])
-
asyncAddEntry
public void asyncAddEntry(byte[] data, int offset, int length, AsyncCallbacks.AddEntryCallback callback, java.lang.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:
ManagedLedger.addEntry(byte[])
-
asyncAddEntry
public void asyncAddEntry(byte[] data, int numberOfMessages, int offset, int length, AsyncCallbacks.AddEntryCallback callback, java.lang.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:
ManagedLedger.addEntry(byte[])
-
asyncAddEntry
public void asyncAddEntry(io.netty.buffer.ByteBuf buffer, AsyncCallbacks.AddEntryCallback callback, java.lang.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:
ManagedLedger.addEntry(byte[])
-
asyncAddEntry
public void asyncAddEntry(io.netty.buffer.ByteBuf buffer, int numberOfMessages, AsyncCallbacks.AddEntryCallback callback, java.lang.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:
ManagedLedger.addEntry(byte[])
-
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(java.lang.String cursorName) throws java.lang.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:
ManagedLedgerExceptionjava.lang.InterruptedException
-
openCursor
public ManagedCursor openCursor(java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition) throws java.lang.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- the cursor will be set at latest position or not when first created default is true- Returns:
- the ManagedCursor
- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
openCursor
public ManagedCursor openCursor(java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, java.util.Map<java.lang.String,java.lang.Long> properties) throws java.lang.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- the cursor will be set at latest position or not when first created default is trueproperties- 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.- Returns:
- the ManagedCursor
- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
asyncOpenCursor
public void asyncOpenCursor(java.lang.String cursorName, AsyncCallbacks.OpenCursorCallback callback, java.lang.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:
ManagedLedger.openCursor(String)
-
asyncOpenCursor
public void asyncOpenCursor(java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, AsyncCallbacks.OpenCursorCallback callback, java.lang.Object ctx)Description copied from interface:ManagedLedgerOpen a ManagedCursor asynchronously.- Specified by:
asyncOpenCursorin interfaceManagedLedger- Parameters:
cursorName- the name associated with the ManagedCursorinitialPosition- the cursor will be set at lastest position or not when first created default is truecallback- callback objectctx- opaque context- See Also:
ManagedLedger.openCursor(String)
-
asyncOpenCursor
public void asyncOpenCursor(java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition, java.util.Map<java.lang.String,java.lang.Long> properties, AsyncCallbacks.OpenCursorCallback callback, java.lang.Object ctx)Description copied from interface:ManagedLedgerOpen a ManagedCursor asynchronously.- Specified by:
asyncOpenCursorin interfaceManagedLedger- Parameters:
cursorName- the name associated with the ManagedCursorinitialPosition- the cursor will be set at lastest position or not when first created default is truecallback- callback objectctx- opaque context- See Also:
ManagedLedger.openCursor(String)
-
asyncDeleteCursor
public void asyncDeleteCursor(java.lang.String consumerName, AsyncCallbacks.DeleteCursorCallback callback, java.lang.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:
ManagedLedger.deleteCursor(String)
-
deleteCursor
public void deleteCursor(java.lang.String name) throws java.lang.InterruptedException, ManagedLedgerExceptionDescription 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:
java.lang.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, java.lang.String subscriptionName) throws ManagedLedgerException
- Specified by:
newNonDurableCursorin interfaceManagedLedger- Throws:
ManagedLedgerException
-
newNonDurableCursor
public ManagedCursor newNonDurableCursor(Position startCursorPosition, java.lang.String cursorName, org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition initialPosition) throws ManagedLedgerException
- Specified by:
newNonDurableCursorin interfaceManagedLedger- Throws:
ManagedLedgerException
-
getCursors
public ManagedCursorContainer 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
public ManagedCursorContainer 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
-
getEstimatedBacklogSize
public long getEstimatedBacklogSize(PositionImpl pos)
Get estimated backlog size from a specific position.
-
asyncTerminate
public void asyncTerminate(AsyncCallbacks.TerminateCallback callback, java.lang.Object ctx)
- Specified by:
asyncTerminatein interfaceManagedLedger
-
terminate
public Position terminate() throws java.lang.InterruptedException, ManagedLedgerException
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:
java.lang.InterruptedExceptionManagedLedgerException
-
isTerminated
public boolean isTerminated()
Description copied from interface:ManagedLedgerReturns whether the managed ledger was terminated.- Specified by:
isTerminatedin interfaceManagedLedger
-
close
public void close() throws java.lang.InterruptedException, ManagedLedgerExceptionDescription 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:
ManagedLedgerExceptionjava.lang.InterruptedException
-
asyncClose
public void asyncClose(AsyncCallbacks.CloseCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedLedgerClose the ManagedLedger asynchronously.- Specified by:
asyncClosein interfaceManagedLedger- Parameters:
callback- callback objectctx- opaque context- See Also:
ManagedLedger.close()
-
createComplete
public void createComplete(int rc, org.apache.bookkeeper.client.LedgerHandle lh, java.lang.Object ctx)- Specified by:
createCompletein interfaceorg.apache.bookkeeper.client.AsyncCallback.CreateCallback
-
updateLedgersIdsComplete
public void updateLedgersIdsComplete(org.apache.pulsar.metadata.api.Stat stat)
-
rollCurrentLedgerIfFull
public void rollCurrentLedgerIfFull()
Description copied from interface:ManagedLedgerRoll current ledger if it is full- Specified by:
rollCurrentLedgerIfFullin interfaceManagedLedger
-
asyncFindPosition
public java.util.concurrent.CompletableFuture<Position> asyncFindPosition(com.google.common.base.Predicate<Entry> predicate)
Description copied from interface:ManagedLedgerFind position by sequenceId.- Specified by:
asyncFindPositionin interfaceManagedLedger
-
getManagedLedgerInterceptor
public ManagedLedgerInterceptor getManagedLedgerInterceptor()
Description copied from interface:ManagedLedgerGet the ManagedLedgerInterceptor for ManagedLedger.- Specified by:
getManagedLedgerInterceptorin interfaceManagedLedger
-
getLedgerMetadata
public java.util.concurrent.CompletableFuture<java.lang.String> getLedgerMetadata(long ledgerId)
-
getLedgerInfo
public java.util.concurrent.CompletableFuture<MLDataFormats.ManagedLedgerInfo.LedgerInfo> getLedgerInfo(long ledgerId)
Description copied from interface:ManagedLedgerGet basic ledger summary. will got null if corresponding ledger not exists.- Specified by:
getLedgerInfoin interfaceManagedLedger
-
asyncReadEntry
public void asyncReadEntry(PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, java.lang.Object ctx)
-
asyncReadEntry
protected void asyncReadEntry(org.apache.bookkeeper.client.api.ReadHandle ledger, PositionImpl position, AsyncCallbacks.ReadEntryCallback callback, java.lang.Object ctx)
-
asyncReadEntry
protected void asyncReadEntry(org.apache.bookkeeper.client.api.ReadHandle ledger, long firstEntry, long lastEntry, boolean isSlowestReader, org.apache.bookkeeper.mledger.impl.OpReadEntry opReadEntry, java.lang.Object ctx)
-
getStats
public ManagedLedgerMXBean getStats()
- Specified by:
getStatsin interfaceManagedLedger- Returns:
- the managed ledger stats MBean
-
hasMoreEntries
public boolean hasMoreEntries(PositionImpl position)
-
addWaitingEntryCallBack
public void addWaitingEntryCallBack(WaitingEntryCallBack cb)
-
maybeUpdateCursorBeforeTrimmingConsumedLedger
public void maybeUpdateCursorBeforeTrimmingConsumedLedger()
-
trimConsumedLedgersInBackground
public void trimConsumedLedgersInBackground(java.util.concurrent.CompletableFuture<?> promise)
Description copied from interface:ManagedLedgerTrim consumed ledgers in background- Specified by:
trimConsumedLedgersInBackgroundin interfaceManagedLedger
-
trimConsumedLedgersInBackground
public void trimConsumedLedgersInBackground(boolean isTruncate, java.util.concurrent.CompletableFuture<?> promise)
-
delete
public void delete() throws java.lang.InterruptedException, ManagedLedgerExceptionDelete this ManagedLedger completely from the system.- Specified by:
deletein interfaceManagedLedger- Throws:
java.lang.Exceptionjava.lang.InterruptedExceptionManagedLedgerException
-
asyncDelete
public void asyncDelete(AsyncCallbacks.DeleteLedgerCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedLedgerAsync delete a ledger.- Specified by:
asyncDeletein interfaceManagedLedger
-
offloadPrefix
public Position offloadPrefix(Position pos) throws java.lang.InterruptedException, ManagedLedgerException
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:
java.lang.InterruptedExceptionManagedLedgerException- See Also:
ManagedLedger.asyncOffloadPrefix(Position,OffloadCallback,Object)
-
asyncOffloadPrefix
public void asyncOffloadPrefix(Position pos, AsyncCallbacks.OffloadCallback callback, java.lang.Object ctx)
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 or not to include the start position in calculating the distance- Returns:
- the new position that is n entries ahead
-
getPreviousPosition
public PositionImpl 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.- Parameters:
position- the current position- Returns:
- the previous position
-
isValidPosition
public boolean isValidPosition(PositionImpl position)
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
public java.lang.Long getNextValidLedger(long ledgerId)
-
getNextValidPosition
public PositionImpl getNextValidPosition(PositionImpl position)
-
getNextValidPositionInternal
public PositionImpl getNextValidPositionInternal(PositionImpl position)
-
getFirstPosition
public PositionImpl getFirstPosition()
-
getSlowestConsumer
public ManagedCursor getSlowestConsumer()
Description copied from interface:ManagedLedgerGet the slowest consumer.- Specified by:
getSlowestConsumerin interfaceManagedLedger- Returns:
- the slowest consumer
-
activateCursor
public void activateCursor(ManagedCursor cursor)
-
deactivateCursor
public void deactivateCursor(ManagedCursor cursor)
-
isCursorActive
public boolean isCursorActive(ManagedCursor cursor)
-
getLedgersInfoAsList
public java.util.List<MLDataFormats.ManagedLedgerInfo.LedgerInfo> getLedgersInfoAsList()
-
getLedgersInfo
public java.util.NavigableMap<java.lang.Long,MLDataFormats.ManagedLedgerInfo.LedgerInfo> getLedgersInfo()
-
getConfig
public ManagedLedgerConfig getConfig()
Description copied from interface:ManagedLedgerReturns managed-ledger config.- Specified by:
getConfigin interfaceManagedLedger
-
setConfig
public void setConfig(ManagedLedgerConfig config)
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
public Position getLastConfirmedEntry()
Description copied from interface:ManagedLedgerGets last confirmed entry of the managed ledger.- Specified by:
getLastConfirmedEntryin interfaceManagedLedger- Returns:
- the last confirmed entry id
-
getState
public ManagedLedgerImpl.State getState()
-
getMBean
public ManagedLedgerMBeanImpl getMBean()
-
getCacheSize
public long getCacheSize()
-
isReadOnly
protected boolean isReadOnly()
-
createManagedLedgerException
public static ManagedLedgerException createManagedLedgerException(int bkErrorCode)
-
createManagedLedgerException
public static ManagedLedgerException createManagedLedgerException(java.lang.Throwable t)
-
asyncCreateLedger
protected void asyncCreateLedger(org.apache.bookkeeper.client.BookKeeper bookKeeper, ManagedLedgerConfig config, org.apache.bookkeeper.client.BookKeeper.DigestType digestType, org.apache.bookkeeper.client.AsyncCallback.CreateCallback cb, java.util.Map<java.lang.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
public java.time.Clock getClock()
-
checkAndCompleteLedgerOpTask
protected boolean checkAndCompleteLedgerOpTask(int rc, org.apache.bookkeeper.client.LedgerHandle lh, java.lang.Object ctx)check if ledger-op task is already completed by timeout-task. If completed then delete the created ledger- Parameters:
rc-lh-ctx-- Returns:
-
getOffloadedSize
public long getOffloadedSize()
Description copied from interface:ManagedLedgerReturn the size of all ledgers offloaded to 2nd tier storage- Specified by:
getOffloadedSizein interfaceManagedLedger
-
getProperties
public java.util.Map<java.lang.String,java.lang.String> getProperties()
Description copied from interface:ManagedLedgerReturns managed-ledger's properties.- Specified by:
getPropertiesin interfaceManagedLedger- Returns:
- key-values of properties
-
setProperty
public void setProperty(java.lang.String key, java.lang.String value) throws java.lang.InterruptedException, ManagedLedgerExceptionDescription 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:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncSetProperty
public void asyncSetProperty(java.lang.String key, java.lang.String value, AsyncCallbacks.UpdatePropertiesCallback callback, java.lang.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
public void deleteProperty(java.lang.String key) throws java.lang.InterruptedException, ManagedLedgerExceptionDescription copied from interface:ManagedLedgerDelete the property by key.- Specified by:
deletePropertyin interfaceManagedLedger- Parameters:
key- key of property to delete- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncDeleteProperty
public void asyncDeleteProperty(java.lang.String key, AsyncCallbacks.UpdatePropertiesCallback callback, java.lang.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(java.util.Map<java.lang.String,java.lang.String> properties) throws java.lang.InterruptedException, ManagedLedgerExceptionDescription copied from interface:ManagedLedgerUpdate managed-ledger's properties.- Specified by:
setPropertiesin interfaceManagedLedger- Parameters:
properties- key-values of properties- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncSetProperties
public void asyncSetProperties(java.util.Map<java.lang.String,java.lang.String> properties, AsyncCallbacks.UpdatePropertiesCallback callback, java.lang.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
public java.util.concurrent.CompletableFuture<java.lang.Void> 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 java.util.concurrent.CompletableFuture<org.apache.pulsar.common.policies.data.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
public java.util.concurrent.CompletableFuture<java.util.Set<org.apache.bookkeeper.net.BookieId>> getEnsemblesAsync(long ledgerId)
-
-