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)
  • Loading branch information
lhotari authored Jun 14, 2022
1 parent 72dfcc6 commit ec9676f
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 ec9676f

Please # to comment.