Skip to content

Commit

Permalink
[fix][transaction] Properly close transaction-buffer-sub non durable …
Browse files Browse the repository at this point in the history
…cursor (apache#14900)

Fixes apache#14880

### Motivation

Non durable cursor was not closed properly.

### Modifications
For non durable cursor,  `cursor.asyncClose` did nothing. The proper way is `topic.getManagedLedger().asyncDeleteCursor`
  • Loading branch information
gaozhangmin authored Mar 28, 2022
1 parent 6d9ba7b commit 4e62ffc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.pulsar.common.policies.data.TransactionInBufferStats;
import org.apache.pulsar.common.protocol.Commands;
import org.apache.pulsar.common.protocol.Markers;
import org.apache.pulsar.common.util.Codec;
import org.jctools.queues.MessagePassingQueue;
import org.jctools.queues.SpscArrayQueue;

Expand Down Expand Up @@ -639,7 +640,7 @@ public void run() {
}
}

closeCursor(managedCursor);
closeCursor(SUBSCRIPTION_NAME);
callBack.recoverComplete();
}, topic.getBrokerService().getPulsar().getTransactionExecutorProvider()
.getExecutor(this)).exceptionally(e -> {
Expand All @@ -656,17 +657,19 @@ public void run() {
});
}

private void closeCursor(ManagedCursor cursor) {
cursor.asyncClose(new AsyncCallbacks.CloseCallback() {
private void closeCursor(String subscriptionName) {
topic.getManagedLedger().asyncDeleteCursor(Codec.encode(subscriptionName),
new AsyncCallbacks.DeleteCursorCallback() {
@Override
public void closeComplete(Object ctx) {
public void deleteCursorComplete(Object ctx) {
log.info("[{}]Transaction buffer snapshot recover cursor close complete.", topic.getName());
}

@Override
public void closeFailed(ManagedLedgerException exception, Object ctx) {
public void deleteCursorFailed(ManagedLedgerException exception, Object ctx) {
log.error("[{}]Transaction buffer snapshot recover cursor close fail.", topic.getName());
}

}, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public void testEndTBRecoveringWhenManagerLedgerDisReadable() throws Exception{
.getTopic("persistent://" + topic, false).get().get();
persistentTopic.getManagedLedger().getConfig().setAutoSkipNonRecoverableData(true);

ManagedCursor managedCursor = mock(ManagedCursor.class);
ManagedCursorImpl managedCursor = mock(ManagedCursorImpl.class);
doReturn("transaction-buffer-sub").when(managedCursor).getName();
doReturn(true).when(managedCursor).hasMoreEntries();
doAnswer(invocation -> {
Expand Down Expand Up @@ -577,6 +577,9 @@ public void testEndTBRecoveringWhenManagerLedgerDisReadable() throws Exception{
TransactionBuffer buffer3 = new TopicTransactionBuffer(persistentTopic);
Awaitility.await().atMost(30, TimeUnit.SECONDS).untilAsserted(() ->
assertEquals(buffer3.getStats().state, "Ready"));
persistentTopic.getInternalStats(false).thenAccept(internalStats -> {
assertTrue(internalStats.cursors.isEmpty());
});
managedCursors.removeCursor("transaction-buffer-sub");
}

Expand Down Expand Up @@ -895,4 +898,4 @@ public void testAutoCreateSchemaForTransactionSnapshot() throws Exception {
pulsarServiceList.forEach((pulsarService ->
pulsarService.getConfiguration().setAllowAutoUpdateSchemaEnabled(true)));
}
}
}

0 comments on commit 4e62ffc

Please sign in to comment.