This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.11 by this push:
new 9a79679eaa3 [improve][broker] Added isActive in ManagedCursorImpl
(#19341)
9a79679eaa3 is described below
commit 9a79679eaa374e2ae104d57f116c49187c57e4c7
Author: Heesung Sohn <[email protected]>
AuthorDate: Sat Jan 28 08:37:13 2023 -0800
[improve][broker] Added isActive in ManagedCursorImpl (#19341)
---
.../apache/bookkeeper/mledger/impl/ManagedCursorImpl.java | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git
a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
index 4f1a376771c..514dd24fa4d 100644
---
a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
+++
b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
@@ -205,6 +205,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;
@@ -1126,19 +1129,23 @@ public class ManagedCursorImpl implements ManagedCursor
{
@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