This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new ec9676f6431 [ML] Fix thread safety issues in ManagedCursorContainer
related to "heap" field access (#16049)
ec9676f6431 is described below
commit ec9676f6431aa5ebd7df2235f6ebd49ddbf92288
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)
---
.../bookkeeper/mledger/impl/ManagedCursorContainer.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
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 ef9a546a507..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,11 +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() {
- return heap.isEmpty() ? null : (PositionImpl)
heap.get(0).cursor.getMarkDeletedPosition();
+ long stamp = rwLock.readLock();
+ try {
+ return heap.isEmpty() ? null : (PositionImpl)
heap.get(0).cursor.getMarkDeletedPosition();
+ } finally {
+ rwLock.unlockRead(stamp);
+ }
}
public ManagedCursor get(String name) {