Skip to content

Commit f106e37

Browse files
poorbarcodeBewareMyPower
authored andcommitted
[fix] [ml] incorrect non-durable cursor's backlog due to concurrently trimming ledger and non-durable cursor creation (apache#23951)
Co-authored-by: Yunze Xu <[email protected]> (cherry picked from commit cc7b381) (cherry picked from commit 16bfb1a)
1 parent b17a00a commit f106e37

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,16 +1137,17 @@ public ManagedCursor newNonDurableCursor(Position startCursorPosition, String cu
11371137
return cachedCursor;
11381138
}
11391139

1140-
NonDurableCursorImpl cursor = new NonDurableCursorImpl(bookKeeper, this, cursorName,
1141-
(PositionImpl) startCursorPosition, initialPosition, isReadCompacted);
1142-
cursor.setActive();
1143-
1144-
log.info("[{}] Opened new cursor: {}", name, cursor);
1140+
// The backlog of a non-durable cursor could be incorrect if the cursor is created before `internalTrimLedgers`
1141+
// and added to the managed ledger after `internalTrimLedgers`.
1142+
// For more details, see https://github.com/apache/pulsar/pull/23951.
11451143
synchronized (this) {
1144+
NonDurableCursorImpl cursor = new NonDurableCursorImpl(bookKeeper, this, cursorName,
1145+
(PositionImpl) startCursorPosition, initialPosition, isReadCompacted);
1146+
cursor.setActive();
1147+
log.info("[{}] Opened new cursor: {}", name, cursor);
11461148
addCursor(cursor);
1149+
return cursor;
11471150
}
1148-
1149-
return cursor;
11501151
}
11511152

11521153
@Override

0 commit comments

Comments
 (0)