This is an automated email from the ASF dual-hosted git repository. penghui pushed a commit to branch branch-2.10 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit cec950eb3e60c5a78834c1277d8b340b9ecddb05 Author: Lari Hotari <[email protected]> AuthorDate: Tue Jun 14 15:21:30 2022 +0300 [ML] Fix thread safety issues in ManagedCursorContainer related to "heap" field access (#16049) (cherry picked from commit ec9676f6431aa5ebd7df2235f6ebd49ddbf92288) --- .../bookkeeper/mledger/impl/ManagedCursorContainer.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorContainer.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorContainer.java index 65d254112d1..f9591d9ee6a 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorContainer.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorContainer.java @@ -105,7 +105,21 @@ public class ManagedCursorContainer implements Iterable<ManagedCursor> { } public PositionImpl getSlowestReadPositionForActiveCursors() { - return heap.isEmpty() ? null : (PositionImpl) heap.get(0).cursor.getReadPosition(); + long stamp = rwLock.readLock(); + try { + return heap.isEmpty() ? null : (PositionImpl) heap.get(0).cursor.getReadPosition(); + } finally { + rwLock.unlockRead(stamp); + } + } + + public PositionImpl getSlowestMarkDeletedPositionForActiveCursors() { + long stamp = rwLock.readLock(); + try { + return heap.isEmpty() ? null : (PositionImpl) heap.get(0).cursor.getMarkDeletedPosition(); + } finally { + rwLock.unlockRead(stamp); + } } public ManagedCursor get(String name) {
