Class ManagedCursorImpl
java.lang.Object
org.apache.bookkeeper.mledger.impl.ManagedCursorImpl
- All Implemented Interfaces:
ManagedCursor
- Direct Known Subclasses:
NonDurableCursorImpl,ReadOnlyCursorImpl
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic interfaceNested classes/interfaces inherited from interface org.apache.bookkeeper.mledger.ManagedCursor
ManagedCursor.FindPositionConstraint, ManagedCursor.IndividualDeletedEntries -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConcurrentSkipListMap<PositionImpl,BitSetRecyclable> protected final BookKeeperprotected final ManagedLedgerConfigstatic final Stringstatic final intprotected final RangeSetWrapper<PositionImpl>protected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,PositionImpl> protected PositionImplprotected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry> protected org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntryprotected final ManagedLedgerImplprotected PositionImplprotected final ManagedCursorMXBeanprotected longprotected final ArrayDeque<org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry>protected PositionImplprotected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,PositionImpl> protected PositionImplprotected ManagedCursorImpl.Stateprotected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,ManagedCursorImpl.State> protected PositionImplstatic final intprotected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,org.apache.bookkeeper.mledger.impl.OpReadEntry> -
Method Summary
Modifier and TypeMethodDescriptionintapplyMaxSizeCap(int maxEntries, long maxSizeBytes) voidasyncClearBacklog(AsyncCallbacks.ClearBacklogCallback callback, Object ctx) Clear the cursor backlog.voidasyncClose(AsyncCallbacks.CloseCallback callback, Object ctx) Close the cursor asynchronously and release the associated resources.voidasyncDelete(Iterable<Position> positions, AsyncCallbacks.DeleteCallback callback, Object ctx) Delete a group of messages asynchronouslyvoidasyncDelete(Position pos, AsyncCallbacks.DeleteCallback callback, Object ctx) Delete a single message asynchronouslyvoidasyncFindNewestMatching(ManagedCursor.FindPositionConstraint constraint, Predicate<Entry> condition, AsyncCallbacks.FindEntryCallback callback, Object ctx) Find the newest entry that matches the given predicate.voidasyncFindNewestMatching(ManagedCursor.FindPositionConstraint constraint, Predicate<Entry> condition, AsyncCallbacks.FindEntryCallback callback, Object ctx, boolean isFindFromLedger) Find the newest entry that matches the given predicate.voidasyncGetNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.ReadEntryCallback callback, Object ctx) Asynchronously get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.voidasyncMarkDelete(Position position, Map<String, Long> properties, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) Asynchronous mark delete.voidasyncMarkDelete(Position position, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) Asynchronous mark delete.voidasyncReadEntries(int numberOfEntriesToRead, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger.voidasyncReadEntries(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger.voidasyncReadEntriesOrWait(int maxEntries, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger, up to the specified number and size.voidasyncReadEntriesOrWait(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger.voidasyncReadEntriesWithSkip(int numberOfEntriesToRead, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition, Predicate<PositionImpl> skipCondition) Asynchronously read entries from the ManagedLedger.voidasyncReadEntriesWithSkipOrWait(int maxEntries, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition, Predicate<PositionImpl> skipCondition) Asynchronously read entries from the ManagedLedger, up to the specified number and size.voidasyncReadEntriesWithSkipOrWait(int maxEntries, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition, Predicate<PositionImpl> skipCondition) Asynchronously read entries from the ManagedLedger, up to the specified number and size.asyncReplayEntries(Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, Object ctx) Async replays given positions: a.asyncReplayEntries(Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, boolean sortEntries) Read the specified set of positions from ManagedLedger.voidasyncResetCursor(Position newPos, boolean forceReset, AsyncCallbacks.ResetCursorCallback callback) reset the cursor to specified position to enable replay of messages.voidasyncSkipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.SkipEntriesCallback callback, Object ctx) Skip n entries from the read position of this cursor.booleanCancel a previously scheduled asyncReadEntriesOrWait operation.booleanChecks if read position changed since this method was called last time.voidClear the cursor backlog.voidclose()Close the cursor and releases the associated resources.voidDelete a group of entries.voidDelete a single message.duplicateNonDurableCursor(String nonDurableCursorName) Create a non-durable cursor and copy the ack stats.findNewestMatching(Predicate<Entry> condition) Find the newest entry that matches the given predicate.findNewestMatching(ManagedCursor.FindPositionConstraint constraint, Predicate<Entry> condition) Find the newest entry that matches the given predicate.long[]getBatchPositionAckSet(Position position) longlongReturn any properties that were associated with the cursor.long[]Get deleted batch indexes list for a batch message.longReturns the estimated size of the unacknowledged backlog for this cursor.Get the first position.longGet the last active time of the cursor.com.google.common.collect.Range<PositionImpl>Get last individual deleted range.longGetManagedLedgerattached with cursor.Get the newest mark deleted position on this cursor.longgetName()Get the unique cursor name.getNextAvailablePosition(PositionImpl position) Checks given position is part of deleted-range and returns next position of upper-end as all the messages are deleted up to that point.getNextLedgerPosition(long currentLedgerId) intReturns the serialized size of mark-Delete ranges.getNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries) Get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.longReturn the number of messages that this cursor still has to read.protected longgetNumberOfEntries(com.google.common.collect.Range<PositionImpl> range) longgetNumberOfEntriesInBacklog(boolean isPrecise) Return the number of non-deleted messages on this cursor.longlongReturns total number of entries from the first not-acked message to current dispatching position.intGet the persistent newest mark deleted position on this cursor.Return any properties that were associated with the last stored position.Get the read position.getState()getStats()doubleReturns cursor throttle mark-delete rate.intReturns number of mark-Delete range.booleanTells whether this cursor has already consumed all the available entries.booleanprotected voidinternalAsyncMarkDelete(PositionImpl newPosition, Map<String, Long> properties, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) protected voidinternalResetCursor(PositionImpl proposedReadPosition, AsyncCallbacks.ResetCursorCallback resetCursorCallback) booleanisActive()Checks if cursor is active or not.static booleanisBkErrorNotRecoverable(int rc) return BK error codes that are considered not likely to be recoverable.booleanbooleanisClosed()Checks if the cursor is closed.booleanTells whether the cursor is durable or just kept in memory.booleanbooleanisMessageDeleted(Position position) voidmarkDelete(Position position) This signals that the reader is done with all the entries up to "position" (included).voidmarkDelete(Position position, Map<String, Long> properties) This signals that the reader is done with all the entries up to "position" (included).putCursorProperty(String key, String value) Add a property associated with the cursor.booleanputProperty(String key, Long value) Add a property associated with the last stored position.readEntries(int numberOfEntriesToRead) Read entries from the ManagedLedger, up to the specified number.readEntriesOrWait(int numberOfEntriesToRead) Read entries from the ManagedLedger, up to the specified number.readEntriesOrWait(int numberOfEntriesToRead, long maxSizeBytes) Read entries from the ManagedLedger, up to the specified number and size.protected voidRemove a property associated with the cursor.booleanremoveProperty(String key) Remove a property associated with the last stored position.replayEntries(Set<? extends Position> positions) Read the specified set of positions from ManagedLedger.voidresetCursor(Position newPos) reset the cursor to specified position to enable replay of messages.voidrewind()Rewind the cursor to the mark deleted position to replay all the already read but not yet mark deleted messages.voidrewind(boolean readCompacted) scan(Optional<Position> position, Predicate<Entry> condition, int batchSize, long maxEntries, long timeOutMs) Scan the cursor from the current position up to the end.voidvoidActivate cursor: EntryCacheManager caches entries only for activated-cursors.voidA cursor that is set as always-inactive will never trigger the caching of entries.voidsetCacheReadEntry(boolean cacheReadEntry) setCursorProperties(Map<String, String> cursorProperties) Set all properties associated with the cursor, but internal properties(start with '#pulsar_internal.') are still preserved and prohibit setting of internal properties by this method.voidDeactivate cursor.voidsetState(ManagedCursorImpl.State state) voidsetThrottleMarkDelete(double throttleMarkDelete) Update throttle mark delete rate.voidskipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries) Skip n entries from the read position of this cursor.voidskipNonRecoverableLedger(long ledgerId) Manually acknowledge all entries in the lost ledger.toString()voidtrimDeletedEntries(List<Entry> entries) Trim delete entries for the given entries.voidUpdate the last active time of the cursor.voidupdateReadStats(int readEntriesCount, long readEntriesSize) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.bookkeeper.mledger.ManagedCursor
seek
-
Field Details
-
bookkeeper
-
config
-
ledger
-
CURSOR_INTERNAL_PROPERTY_PREFIX
- See Also:
-
markDeletePosition
-
persistentMarkDeletePosition
-
INPROGRESS_MARKDELETE_PERSIST_POSITION_UPDATER
protected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,PositionImpl> INPROGRESS_MARKDELETE_PERSIST_POSITION_UPDATER -
inProgressMarkDeletePersistPosition
-
READ_POSITION_UPDATER
protected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,PositionImpl> READ_POSITION_UPDATER -
readPosition
-
statsLastReadPosition
-
LAST_MARK_DELETE_ENTRY_UPDATER
protected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry> LAST_MARK_DELETE_ENTRY_UPDATER -
lastMarkDeleteEntry
protected volatile org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry lastMarkDeleteEntry -
WAITING_READ_OP_UPDATER
protected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,org.apache.bookkeeper.mledger.impl.OpReadEntry> WAITING_READ_OP_UPDATER -
FALSE
public static final int FALSE- See Also:
-
TRUE
public static final int TRUE- See Also:
-
messagesConsumedCounter
protected volatile long messagesConsumedCounter -
individualDeletedMessages
-
batchDeletedIndexes
-
pendingMarkDeleteOps
protected final ArrayDeque<org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry> pendingMarkDeleteOps -
STATE_UPDATER
protected static final AtomicReferenceFieldUpdater<ManagedCursorImpl,ManagedCursorImpl.State> STATE_UPDATER -
state
-
mbean
-
-
Method Details
-
getProperties
Description copied from interface:ManagedCursorReturn any properties that were associated with the last stored position.- Specified by:
getPropertiesin interfaceManagedCursor
-
getCursorProperties
Description copied from interface:ManagedCursorReturn any properties that were associated with the cursor.- Specified by:
getCursorPropertiesin interfaceManagedCursor
-
setCursorProperties
Description copied from interface:ManagedCursorSet all properties associated with the cursor, but internal properties(start with '#pulsar_internal.') are still preserved and prohibit setting of internal properties by this method. Note:ManagedLedgerException.BadVersionExceptionwill be set in thisCompletableFuture, if there are concurrent modification and store data has changed.- Specified by:
setCursorPropertiesin interfaceManagedCursor- Returns:
- a handle to the result of the operation
-
putCursorProperty
Description copied from interface:ManagedCursorAdd a property associated with the cursor. Note:ManagedLedgerException.BadVersionExceptionwill be set in thisCompletableFuture, if there are concurrent modification and store data has changed.- Specified by:
putCursorPropertyin interfaceManagedCursor- Returns:
- a handle to the result of the operation
-
removeCursorProperty
Description copied from interface:ManagedCursorRemove a property associated with the cursor. Note:ManagedLedgerException.BadVersionExceptionwill be set in thisCompletableFuture, if there are concurrent modification and store data has changed.- Specified by:
removeCursorPropertyin interfaceManagedCursor- Returns:
- a handle to the result of the operation
-
putProperty
Description copied from interface:ManagedCursorAdd a property associated with the last stored position.- Specified by:
putPropertyin interfaceManagedCursor
-
removeProperty
Description copied from interface:ManagedCursorRemove a property associated with the last stored position.- Specified by:
removePropertyin interfaceManagedCursor
-
recoverFromLedger
protected void recoverFromLedger(MLDataFormats.ManagedCursorInfo info, ManagedCursorImpl.VoidCallback callback) -
readEntries
public List<Entry> readEntries(int numberOfEntriesToRead) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorRead entries from the ManagedLedger, up to the specified number. The returned list can be smaller.- Specified by:
readEntriesin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to return- Returns:
- the list of entries
- Throws:
ManagedLedgerExceptionInterruptedException
-
asyncReadEntries
public void asyncReadEntries(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger.- Specified by:
asyncReadEntriesin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- See Also:
-
asyncReadEntries
public void asyncReadEntries(int numberOfEntriesToRead, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger.- Specified by:
asyncReadEntriesin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read
-
asyncReadEntriesWithSkip
public void asyncReadEntriesWithSkip(int numberOfEntriesToRead, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition, Predicate<PositionImpl> skipCondition) Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger.- Specified by:
asyncReadEntriesWithSkipin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can readskipCondition- predicate of read filter out
-
getNthEntry
public Entry getNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorGet 'N'th entry from the mark delete position in the cursor without updating any cursor positions.- Specified by:
getNthEntryin interfaceManagedCursor- Parameters:
n- entry positiondeletedEntries- skip individual deleted entries- Returns:
- the entry
- Throws:
InterruptedExceptionManagedLedgerException
-
asyncGetNthEntry
public void asyncGetNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.ReadEntryCallback callback, Object ctx) Description copied from interface:ManagedCursorAsynchronously get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.- Specified by:
asyncGetNthEntryin interfaceManagedCursor- Parameters:
n- entry positiondeletedEntries- skip individual deleted entries
-
readEntriesOrWait
public List<Entry> readEntriesOrWait(int numberOfEntriesToRead) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorRead entries from the ManagedLedger, up to the specified number. The returned list can be smaller. If no entries are available, the method will block until at least a new message will be persisted.- Specified by:
readEntriesOrWaitin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to return- Returns:
- the list of entries
- Throws:
ManagedLedgerExceptionInterruptedException
-
readEntriesOrWait
public List<Entry> readEntriesOrWait(int numberOfEntriesToRead, long maxSizeBytes) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorRead entries from the ManagedLedger, up to the specified number and size. If no entries are available, the method will block until at least a new message will be persisted.- Specified by:
readEntriesOrWaitin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to return- Returns:
- the list of entries
- Throws:
ManagedLedgerExceptionInterruptedException
-
asyncReadEntriesOrWait
public void asyncReadEntriesOrWait(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger. If no entries are available, the callback will not be triggered. Instead it will be registered to wait until a new message will be persisted into the managed ledger- Specified by:
asyncReadEntriesOrWaitin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- See Also:
-
asyncReadEntriesOrWait
public void asyncReadEntriesOrWait(int maxEntries, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger, up to the specified number and size. If no entries are available, the callback will not be triggered. Instead it will be registered to wait until a new message will be persisted into the managed ledger- Specified by:
asyncReadEntriesOrWaitin interfaceManagedCursor- Parameters:
maxEntries- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- See Also:
-
asyncReadEntriesWithSkipOrWait
public void asyncReadEntriesWithSkipOrWait(int maxEntries, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition, Predicate<PositionImpl> skipCondition) Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger, up to the specified number and size. If no entries are available, the callback will not be triggered. Instead it will be registered to wait until a new message will be persisted into the managed ledger- Specified by:
asyncReadEntriesWithSkipOrWaitin interfaceManagedCursor- Parameters:
maxEntries- maximum number of entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can readskipCondition- predicate of read filter out- See Also:
-
asyncReadEntriesWithSkipOrWait
public void asyncReadEntriesWithSkipOrWait(int maxEntries, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition, Predicate<PositionImpl> skipCondition) Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger, up to the specified number and size. If no entries are available, the callback will not be triggered. Instead it will be registered to wait until a new message will be persisted into the managed ledger- Specified by:
asyncReadEntriesWithSkipOrWaitin interfaceManagedCursor- Parameters:
maxEntries- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can readskipCondition- predicate of read filter out- See Also:
-
isClosed
public boolean isClosed()Description copied from interface:ManagedCursorChecks if the cursor is closed.- Specified by:
isClosedin interfaceManagedCursor- Returns:
- whether this cursor is closed.
-
cancelPendingReadRequest
public boolean cancelPendingReadRequest()Description copied from interface:ManagedCursorCancel a previously scheduled asyncReadEntriesOrWait operation.- Specified by:
cancelPendingReadRequestin interfaceManagedCursor- Returns:
- true if the read operation was canceled or false if there was no pending operation
- See Also:
-
hasPendingReadRequest
public boolean hasPendingReadRequest() -
hasMoreEntries
public boolean hasMoreEntries()Description copied from interface:ManagedCursorTells whether this cursor has already consumed all the available entries. This method is not blocking.- Specified by:
hasMoreEntriesin interfaceManagedCursor- Returns:
- true if there are pending entries to read, false otherwise
-
getNumberOfEntries
public long getNumberOfEntries()Description copied from interface:ManagedCursorReturn the number of messages that this cursor still has to read. This method has linear time complexity on the number of ledgers included in the managed ledger.- Specified by:
getNumberOfEntriesin interfaceManagedCursor- Returns:
- the number of entries
-
getNumberOfEntriesSinceFirstNotAckedMessage
public long getNumberOfEntriesSinceFirstNotAckedMessage()Description copied from interface:ManagedCursorReturns total number of entries from the first not-acked message to current dispatching position.- Specified by:
getNumberOfEntriesSinceFirstNotAckedMessagein interfaceManagedCursor- Returns:
-
getTotalNonContiguousDeletedMessagesRange
public int getTotalNonContiguousDeletedMessagesRange()Description copied from interface:ManagedCursorReturns number of mark-Delete range.- Specified by:
getTotalNonContiguousDeletedMessagesRangein interfaceManagedCursor- Returns:
-
getNonContiguousDeletedMessagesRangeSerializedSize
public int getNonContiguousDeletedMessagesRangeSerializedSize()Description copied from interface:ManagedCursorReturns the serialized size of mark-Delete ranges.- Specified by:
getNonContiguousDeletedMessagesRangeSerializedSizein interfaceManagedCursor
-
getEstimatedSizeSinceMarkDeletePosition
public long getEstimatedSizeSinceMarkDeletePosition()Description copied from interface:ManagedCursorReturns the estimated size of the unacknowledged backlog for this cursor.- Specified by:
getEstimatedSizeSinceMarkDeletePositionin interfaceManagedCursor- Returns:
- the estimated size from the mark delete position of the cursor
-
getNumberOfEntriesInBacklog
public long getNumberOfEntriesInBacklog(boolean isPrecise) Description copied from interface:ManagedCursorReturn the number of non-deleted messages on this cursor. This will also include messages that have already been read from the cursor but not deleted or mark-deleted yet. This method has linear time complexity on the number of ledgers included in the managed ledger.- Specified by:
getNumberOfEntriesInBacklogin interfaceManagedCursor- Parameters:
isPrecise- set to true to get precise backlog count- Returns:
- the number of entries
-
getNumberOfEntriesInStorage
public long getNumberOfEntriesInStorage() -
findNewestMatching
public Position findNewestMatching(Predicate<Entry> condition) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorFind the newest entry that matches the given predicate. Will only search among active entries- Specified by:
findNewestMatchingin interfaceManagedCursor- Parameters:
condition- predicate that reads an entry an applies a condition- Returns:
- Position of the newest entry that matches the given predicate
- Throws:
InterruptedExceptionManagedLedgerException
-
scan
public CompletableFuture<ScanOutcome> scan(Optional<Position> position, Predicate<Entry> condition, int batchSize, long maxEntries, long timeOutMs) Description copied from interface:ManagedCursorScan the cursor from the current position up to the end. Please note that this is an expensive operation- Specified by:
scanin interfaceManagedCursor- Parameters:
position- the position to start from, if not provided the scan will start from the lastDeleteMarkPositioncondition- a condition to continue the scan, the condition can access the entrybatchSize- number of entries to process at each readmaxEntries- maximum number of entries to scantimeOutMs- maximum time to spend on this operation
-
findNewestMatching
public Position findNewestMatching(ManagedCursor.FindPositionConstraint constraint, Predicate<Entry> condition) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorFind the newest entry that matches the given predicate.- Specified by:
findNewestMatchingin interfaceManagedCursor- Parameters:
constraint- search only active entries or all entriescondition- predicate that reads an entry an applies a condition- Returns:
- Position of the newest entry that matches the given predicate
- Throws:
InterruptedExceptionManagedLedgerException
-
asyncFindNewestMatching
public void asyncFindNewestMatching(ManagedCursor.FindPositionConstraint constraint, Predicate<Entry> condition, AsyncCallbacks.FindEntryCallback callback, Object ctx) Description copied from interface:ManagedCursorFind the newest entry that matches the given predicate.- Specified by:
asyncFindNewestMatchingin interfaceManagedCursor- Parameters:
constraint- search only active entries or all entriescondition- predicate that reads an entry an applies a conditioncallback- callback object returning the resultant positionctx- opaque context
-
asyncFindNewestMatching
public void asyncFindNewestMatching(ManagedCursor.FindPositionConstraint constraint, Predicate<Entry> condition, AsyncCallbacks.FindEntryCallback callback, Object ctx, boolean isFindFromLedger) Description copied from interface:ManagedCursorFind the newest entry that matches the given predicate.- Specified by:
asyncFindNewestMatchingin interfaceManagedCursor- Parameters:
constraint- search only active entries or all entriescondition- predicate that reads an entry an applies a conditioncallback- callback object returning the resultant positionctx- opaque contextisFindFromLedger- find the newest entry from ledger
-
setActive
public void setActive()Description copied from interface:ManagedCursorActivate cursor: EntryCacheManager caches entries only for activated-cursors.- Specified by:
setActivein interfaceManagedCursor
-
isActive
public boolean isActive()Description copied from interface:ManagedCursorChecks if cursor is active or not.- Specified by:
isActivein interfaceManagedCursor- Returns:
-
setInactive
public void setInactive()Description copied from interface:ManagedCursorDeactivate cursor.- Specified by:
setInactivein interfaceManagedCursor
-
setAlwaysInactive
public void setAlwaysInactive()Description copied from interface:ManagedCursorA cursor that is set as always-inactive will never trigger the caching of entries.- Specified by:
setAlwaysInactivein interfaceManagedCursor
-
getFirstPosition
Description copied from interface:ManagedCursorGet the first position.- Specified by:
getFirstPositionin interfaceManagedCursor- Returns:
- the first position
-
internalResetCursor
protected void internalResetCursor(PositionImpl proposedReadPosition, AsyncCallbacks.ResetCursorCallback resetCursorCallback) -
asyncResetCursor
public void asyncResetCursor(Position newPos, boolean forceReset, AsyncCallbacks.ResetCursorCallback callback) Description copied from interface:ManagedCursorreset the cursor to specified position to enable replay of messages.- Specified by:
asyncResetCursorin interfaceManagedCursor- Parameters:
newPos- position to move the cursor toforceReset- whether to force reset the position even if the position is no longer in the managed ledger, this is used by compacted topic which has data in the compacted ledger, to ensure the cursor can read data from the compacted ledger.callback- callback object
-
resetCursor
Description copied from interface:ManagedCursorreset the cursor to specified position to enable replay of messages.- Specified by:
resetCursorin interfaceManagedCursor- Parameters:
newPos- position to move the cursor to- Throws:
ManagedLedgerExceptionInterruptedException
-
replayEntries
public List<Entry> replayEntries(Set<? extends Position> positions) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorRead the specified set of positions from ManagedLedger.- Specified by:
replayEntriesin interfaceManagedCursor- Parameters:
positions- set of positions to read- Returns:
- the list of entries
- Throws:
InterruptedExceptionManagedLedgerException
-
asyncReplayEntries
public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, Object ctx) Async replays given positions: a. before reading it filters out already-acked messages b. reads remaining entries async and gives it to given ReadEntriesCallback c. returns all already-acked messages which are not replayed so, those messages can be removed by caller(Dispatcher)'s replay-list and it won't try to replay it again- Specified by:
asyncReplayEntriesin interfaceManagedCursor- Parameters:
positions- set of positions to readcallback- callback object returning the list of entriesctx- opaque context- Returns:
- skipped positions set of positions which are already deleted/acknowledged and skipped while replaying them
-
asyncReplayEntries
public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, boolean sortEntries) Description copied from interface:ManagedCursorRead the specified set of positions from ManagedLedger.- Specified by:
asyncReplayEntriesin interfaceManagedCursor- Parameters:
positions- set of positions to readcallback- callback object returning the list of entriesctx- opaque contextsortEntries- callback with sorted entry list.- Returns:
- skipped positions set of positions which are already deleted/acknowledged and skipped while replaying them
-
getNumberOfEntries
-
markDelete
Description copied from interface:ManagedCursorThis signals that the reader is done with all the entries up to "position" (included). This can potentially trigger a ledger deletion, if all the other cursors are done too with the underlying ledger.- Specified by:
markDeletein interfaceManagedCursor- Parameters:
position- the last position that have been successfully consumed- Throws:
ManagedLedgerExceptionInterruptedException
-
markDelete
public void markDelete(Position position, Map<String, Long> properties) throws InterruptedException, ManagedLedgerExceptionDescription copied from interface:ManagedCursorThis signals that the reader is done with all the entries up to "position" (included). This can potentially trigger a ledger deletion, if all the other cursors are done too with the underlying ledger.- Specified by:
markDeletein interfaceManagedCursor- Parameters:
position- the last position that have been successfully consumedproperties- additional user-defined properties that can be associated with a particular cursor position- Throws:
ManagedLedgerExceptionInterruptedException
-
clearBacklog
Description copied from interface:ManagedCursorClear the cursor backlog. Consume all the entries for this cursor.- Specified by:
clearBacklogin interfaceManagedCursor- Throws:
InterruptedExceptionManagedLedgerException
-
asyncClearBacklog
Description copied from interface:ManagedCursorClear the cursor backlog. Consume all the entries for this cursor.- Specified by:
asyncClearBacklogin interfaceManagedCursor- Parameters:
callback- callback objectctx- opaque context
-
skipEntries
public void skipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorSkip n entries from the read position of this cursor.- Specified by:
skipEntriesin interfaceManagedCursor- Parameters:
numEntriesToSkip- number of entries to skipdeletedEntries- skip individual deleted entries- Throws:
InterruptedExceptionManagedLedgerException
-
asyncSkipEntries
public void asyncSkipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.SkipEntriesCallback callback, Object ctx) Description copied from interface:ManagedCursorSkip n entries from the read position of this cursor.- Specified by:
asyncSkipEntriesin interfaceManagedCursor- Parameters:
numEntriesToSkip- number of entries to skipdeletedEntries- skip individual deleted entriescallback- callback objectctx- opaque context
-
asyncMarkDelete
public void asyncMarkDelete(Position position, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) Description copied from interface:ManagedCursorAsynchronous mark delete.- Specified by:
asyncMarkDeletein interfaceManagedCursor- Parameters:
position- the last position that have been successfully consumedcallback- callback objectctx- opaque context- See Also:
-
asyncMarkDelete
public void asyncMarkDelete(Position position, Map<String, Long> properties, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) Description copied from interface:ManagedCursorAsynchronous mark delete.- Specified by:
asyncMarkDeletein interfaceManagedCursor- Parameters:
position- the last position that have been successfully consumedproperties- additional user-defined properties that can be associated with a particular cursor positioncallback- callback objectctx- opaque context- See Also:
-
internalAsyncMarkDelete
protected void internalAsyncMarkDelete(PositionImpl newPosition, Map<String, Long> properties, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) -
delete
Description copied from interface:ManagedCursorDelete a single message. Mark a single message for deletion. When all the previous messages are all deleted, then markDelete() will be called internally to advance the persistent acknowledged position. The deletion of the message is not persisted into the durable storage and cannot be recovered upon the reopening of the ManagedLedger- Specified by:
deletein interfaceManagedCursor- Parameters:
position- the position of the message to be deleted- Throws:
InterruptedExceptionManagedLedgerException
-
asyncDelete
Description copied from interface:ManagedCursorDelete a single message asynchronously Mark a single message for deletion. When all the previous messages are all deleted, then markDelete() will be called internally to advance the persistent acknowledged position. The deletion of the message is not persisted into the durable storage and cannot be recovered upon the reopening of the ManagedLedger- Specified by:
asyncDeletein interfaceManagedCursor- Parameters:
pos- the position of the message to be deletedcallback- callback objectctx- opaque context
-
delete
public void delete(Iterable<Position> positions) throws InterruptedException, ManagedLedgerException Description copied from interface:ManagedCursorDelete a group of entries. Mark multiple single messages for deletion. When all the previous messages are all deleted, then markDelete() will be called internally to advance the persistent acknowledged position. The deletion of the message is not persisted into the durable storage and cannot be recovered upon the reopening of the ManagedLedger- Specified by:
deletein interfaceManagedCursor- Parameters:
positions- positions of the messages to be deleted- Throws:
InterruptedExceptionManagedLedgerException
-
asyncDelete
public void asyncDelete(Iterable<Position> positions, AsyncCallbacks.DeleteCallback callback, Object ctx) Description copied from interface:ManagedCursorDelete a group of messages asynchronously Mark a group of messages for deletion. When all the previous messages are all deleted, then markDelete() will be called internally to advance the persistent acknowledged position. The deletion of the messages is not persisted into the durable storage and cannot be recovered upon the reopening of the ManagedLedger- Specified by:
asyncDeletein interfaceManagedCursor- Parameters:
positions- the positions of the messages to be deletedcallback- callback objectctx- opaque context
-
toString
-
getName
Description copied from interface:ManagedCursorGet the unique cursor name.- Specified by:
getNamein interfaceManagedCursor- Returns:
- the cursor name
-
getLastActive
public long getLastActive()Description copied from interface:ManagedCursorGet the last active time of the cursor.- Specified by:
getLastActivein interfaceManagedCursor- Returns:
- the last active time of the cursor
-
updateLastActive
public void updateLastActive()Description copied from interface:ManagedCursorUpdate the last active time of the cursor.- Specified by:
updateLastActivein interfaceManagedCursor
-
isDurable
public boolean isDurable()Description copied from interface:ManagedCursorTells whether the cursor is durable or just kept in memory.- Specified by:
isDurablein interfaceManagedCursor
-
getReadPosition
Description copied from interface:ManagedCursorGet the read position. This points to the next message to be read from the cursor.- Specified by:
getReadPositionin interfaceManagedCursor- Returns:
- the read position
-
getMarkDeletedPosition
Description copied from interface:ManagedCursorGet the newest mark deleted position on this cursor.- Specified by:
getMarkDeletedPositionin interfaceManagedCursor- Returns:
- the mark deleted position
-
getPersistentMarkDeletedPosition
Description copied from interface:ManagedCursorGet the persistent newest mark deleted position on this cursor.- Specified by:
getPersistentMarkDeletedPositionin interfaceManagedCursor- Returns:
- the persistent mark deleted position
-
rewind
public void rewind()Description copied from interface:ManagedCursorRewind the cursor to the mark deleted position to replay all the already read but not yet mark deleted messages. The next message to be read is the one after the current mark deleted message.- Specified by:
rewindin interfaceManagedCursor
-
rewind
public void rewind(boolean readCompacted) - Specified by:
rewindin interfaceManagedCursor
-
seek
- Specified by:
seekin interfaceManagedCursor
-
close
Description copied from interface:ManagedCursorClose the cursor and releases the associated resources.- Specified by:
closein interfaceManagedCursor- Throws:
InterruptedExceptionManagedLedgerException
-
asyncClose
Description copied from interface:ManagedCursorClose the cursor asynchronously and release the associated resources.- Specified by:
asyncClosein interfaceManagedCursor- Parameters:
callback- callback objectctx- opaque context
-
skipNonRecoverableLedger
public void skipNonRecoverableLedger(long ledgerId) Manually acknowledge all entries in the lost ledger. - Since this is an uncommon event, we focus on maintainability. So we do not modifyindividualDeletedMessagesandbatchDeletedIndexes, but callasyncDelete(Position, AsyncCallbacks.DeleteCallback, Object). - This method is valid regardless of the consumer ACK type. - If there is a consumer ack request after this event, it will also work.- Specified by:
skipNonRecoverableLedgerin interfaceManagedCursor
-
isBkErrorNotRecoverable
public static boolean isBkErrorNotRecoverable(int rc) return BK error codes that are considered not likely to be recoverable. -
getPendingReadOpsCount
public int getPendingReadOpsCount() -
getMessagesConsumedCounter
public long getMessagesConsumedCounter() -
getCursorLedger
public long getCursorLedger() -
getCursorLedgerLastEntry
public long getCursorLedgerLastEntry() -
getIndividuallyDeletedMessages
-
getIndividuallyDeletedMessagesSet
-
isMessageDeleted
-
getBatchPositionAckSet
-
getNextAvailablePosition
Checks given position is part of deleted-range and returns next position of upper-end as all the messages are deleted up to that point.- Parameters:
position-- Returns:
- next available position
-
getNextLedgerPosition
-
isIndividuallyDeletedEntriesEmpty
public boolean isIndividuallyDeletedEntriesEmpty() -
getLastLedgerSwitchTimestamp
public long getLastLedgerSwitchTimestamp() -
getState
-
getThrottleMarkDelete
public double getThrottleMarkDelete()Description copied from interface:ManagedCursorReturns cursor throttle mark-delete rate.- Specified by:
getThrottleMarkDeletein interfaceManagedCursor- Returns:
-
setThrottleMarkDelete
public void setThrottleMarkDelete(double throttleMarkDelete) Description copied from interface:ManagedCursorUpdate throttle mark delete rate.- Specified by:
setThrottleMarkDeletein interfaceManagedCursor
-
getManagedLedger
Description copied from interface:ManagedCursorGetManagedLedgerattached with cursor.- Specified by:
getManagedLedgerin interfaceManagedCursor- Returns:
- ManagedLedger
-
getLastIndividualDeletedRange
Description copied from interface:ManagedCursorGet last individual deleted range.- Specified by:
getLastIndividualDeletedRangein interfaceManagedCursor- Returns:
- range
-
trimDeletedEntries
Description copied from interface:ManagedCursorTrim delete entries for the given entries.- Specified by:
trimDeletedEntriesin interfaceManagedCursor
-
getDeletedBatchIndexesAsLongArray
Description copied from interface:ManagedCursorGet deleted batch indexes list for a batch message.- Specified by:
getDeletedBatchIndexesAsLongArrayin interfaceManagedCursor
-
getStats
- Specified by:
getStatsin interfaceManagedCursor- Returns:
- the managed cursor stats MBean
-
updateReadStats
public void updateReadStats(int readEntriesCount, long readEntriesSize) -
applyMaxSizeCap
public int applyMaxSizeCap(int maxEntries, long maxSizeBytes) -
checkAndUpdateReadPositionChanged
public boolean checkAndUpdateReadPositionChanged()Description copied from interface:ManagedCursorChecks if read position changed since this method was called last time.- Specified by:
checkAndUpdateReadPositionChangedin interfaceManagedCursor- Returns:
- if read position changed
-
setState
-
setCacheReadEntry
public void setCacheReadEntry(boolean cacheReadEntry) -
isCacheReadEntry
public boolean isCacheReadEntry() -
getConfig
-
duplicateNonDurableCursor
public ManagedCursor duplicateNonDurableCursor(String nonDurableCursorName) throws ManagedLedgerException Create a non-durable cursor and copy the ack stats.- Throws:
ManagedLedgerException
-