Skip to content

Commit

Permalink
[ML] Fix thread safety issues in ManagedCursorContainer related to "h…
Browse files Browse the repository at this point in the history
…eap" field access (apache#16049)

(cherry picked from commit ec9676f)
  • Loading branch information
lhotari authored and qunzhong committed Aug 30, 2022
1 parent 06114c5 commit 402fa2a
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,21 @@ private boolean shouldTrackInHeap(ManagedCursor cursor) {
}

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) {
Expand Down

0 comments on commit 402fa2a

Please sign in to comment.