Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][broker] Added isActive in ManagedCursorImpl #19341

Merged
merged 1 commit into from
Jan 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is still the possibility of inconsistent status in the concurrent scenario, but I'm not sure whether it is a problem.

}
}

@Override
Expand Down