Skip to content

Commit

Permalink
[improve][broker] Added isActive in ManagedCursorImpl (apache#19341)
Browse files Browse the repository at this point in the history
  • Loading branch information
heesung-sn authored Jan 28, 2023
1 parent ad8d2df commit 96fb7da
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ public class ManagedCursorImpl implements ManagedCursor {
private static final String COMPACTION_CURSOR_NAME = "__compaction";
private volatile boolean cacheReadEntry = false;

// active state cache in ManagedCursor. It should be in sync with the state in activeCursors in ManagedLedger.
private volatile boolean isActive = false;

class MarkDeleteEntry {
final PositionImpl newPosition;
final MarkDeleteCallback callback;
Expand Down Expand Up @@ -1208,19 +1211,23 @@ public void asyncFindNewestMatching(FindPositionConstraint constraint, Predicate

@Override
public void setActive() {
if (!alwaysInactive) {
if (!isActive && !alwaysInactive) {
ledger.activateCursor(this);
isActive = true;
}
}

@Override
public boolean isActive() {
return ledger.isCursorActive(this);
return isActive;
}

@Override
public void setInactive() {
ledger.deactivateCursor(this);
if (isActive) {
ledger.deactivateCursor(this);
isActive = false;
}
}

@Override
Expand Down

0 comments on commit 96fb7da

Please sign in to comment.