Skip to content

Commit

Permalink
Change nodurable cursor to active (#6769)
Browse files Browse the repository at this point in the history
### Motivation

When use non-durable subscription the cursor is not active which lead to the written entries are not put into cache. This situation would degrade reading performance.

### Modifications

Change the `NonDurableCursorImpl` to active and remove the three override methods: `setActive()/isActive()/setInactive()`

### Verifying this change

This change added tests and can be verified as follows:

*ManagedCursorTest.testNonDurableCursorActive()*
  - add test to check `NonDurableCursorImpl` activity
  • Loading branch information
zhaorongsheng committed Apr 22, 2020
1 parent f9fd59f commit 16ab351
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ public ManagedCursor newNonDurableCursor(Position startCursorPosition, String cu

NonDurableCursorImpl cursor = new NonDurableCursorImpl(bookKeeper, config, this, cursorName,
(PositionImpl) startCursorPosition);
cursor.setActive();

log.info("[{}] Opened new cursor: {}", name, cursor);
synchronized (this) {
Expand Down Expand Up @@ -2894,7 +2895,7 @@ public void deactivateCursor(ManagedCursor cursor) {
}

public boolean isCursorActive(ManagedCursor cursor) {
return cursor.isDurable() && activeCursors.get(cursor.getName()) != null;
return activeCursors.get(cursor.getName()) != null;
}

private boolean currentLedgerIsFull() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,6 @@ protected void internalAsyncMarkDelete(final PositionImpl newPosition, Map<Strin
callback.markDeleteComplete(ctx);
}

@Override
public void setActive() {
/// No-Op
}

@Override
public boolean isActive() {
return false;
}

@Override
public void setInactive() {
/// No-Op
}

@Override
public void asyncClose(CloseCallback callback, Object ctx) {
// No-Op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3000,6 +3000,17 @@ void testAlwaysInactive() throws Exception {
assertFalse(cursor.isActive());
}

@Test
void testNonDurableCursorActive() throws Exception {
ManagedLedger ml = factory.open("testInactive");
ManagedCursor cursor = ml.newNonDurableCursor(PositionImpl.latest, "c1");

assertTrue(cursor.isActive());

cursor.setInactive();
assertFalse(cursor.isActive());
}

@Test
public void deleteMessagesCheckhMarkDelete() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
Expand Down

0 comments on commit 16ab351

Please sign in to comment.