Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,17 @@ public ManagedCursor newNonDurableCursor(Position startPosition, String subscrip
return newNonDurableCursor(startPosition, subscriptionName, InitialPosition.Latest, false);
}

private ManagedCursor getCachedNonDurableCursor(String cursorName) {
ManagedCursor cachedCursor = cursors.get(cursorName);
if (cachedCursor != null) {
if (log.isDebugEnabled()) {
log.debug("[{}] Cursor was already created {}", name, cachedCursor);
}
return cachedCursor;
}
return null;
}

@Override
public ManagedCursor newNonDurableCursor(Position startCursorPosition, String cursorName,
InitialPosition initialPosition, boolean isReadCompacted)
Expand All @@ -1162,18 +1173,20 @@ public ManagedCursor newNonDurableCursor(Position startCursorPosition, String cu
checkManagedLedgerIsOpen();
checkFenced();

ManagedCursor cachedCursor = cursors.get(cursorName);
if (cachedCursor != null) {
if (log.isDebugEnabled()) {
log.debug("[{}] Cursor was already created {}", name, cachedCursor);
}
return cachedCursor;
ManagedCursor cachedNonDurableCursor = getCachedNonDurableCursor(cursorName);
if (cachedNonDurableCursor != null) {
return cachedNonDurableCursor;
}

// The backlog of a non-durable cursor could be incorrect if the cursor is created before `internalTrimLedgers`
// and added to the managed ledger after `internalTrimLedgers`.
// For more details, see https://github.com/apache/pulsar/pull/23951.
synchronized (this) {
cachedNonDurableCursor = getCachedNonDurableCursor(cursorName);
if (cachedNonDurableCursor != null) {
return cachedNonDurableCursor;
}

NonDurableCursorImpl cursor = new NonDurableCursorImpl(bookKeeper, this, cursorName,
startCursorPosition, initialPosition, isReadCompacted);
cursor.setActive();
Expand Down
Loading