Skip to content

Commit 2bed5ff

Browse files
authored
[fix][test]fix flaky test MLPendingAckStoreTest.testMainProcess (apache#18310)
Fixes apache#18230 ### Motivation `ManagedCursorImpl` has a known problem: when the `cursor.close` and the `cursor.switchLedger` are concurrent executing, a bad version exception is thrown. see: https://github.com/apache/pulsar/blob/0c3c175eb132d4ef0fb3a12842127dcb4fa1933d/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java#L2595-L2619 In this test, it hit this problem: - `MlPendingAckStore.clearUselessLogData` will trigger `cursor.switchLedger` if it is the first execute `mard delete`. - `MlPendingAckStore.close` will trigger `cursor.close` ### Modifications if `MlPendingAckStore.close` fail, just retry, it will be ok
1 parent d54c2cb commit 2bed5ff

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/pendingack/impl/MLPendingAckStoreTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,24 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
256256
Assert.assertTrue(mlPendingAckStoreForRead.pendingAckLogIndex.keySet().iterator().next().getEntryId() > 19);
257257

258258
// cleanup.
259-
mlPendingAckStoreForWrite.closeAsync().get();
260-
mlPendingAckStoreForRead.closeAsync().get();
259+
closePendingAckStoreWithRetry(mlPendingAckStoreForWrite);
260+
closePendingAckStoreWithRetry(mlPendingAckStoreForRead);
261+
}
262+
263+
/**
264+
* Why should retry?
265+
* Because when the cursor close and cursor switch ledger are concurrent executing, the bad version exception is
266+
* thrown.
267+
*/
268+
private void closePendingAckStoreWithRetry(MLPendingAckStore pendingAckStore){
269+
Awaitility.await().until(() -> {
270+
try {
271+
pendingAckStore.closeAsync().get();
272+
return true;
273+
} catch (Exception ex){
274+
return false;
275+
}
276+
});
261277
}
262278

263279
/**

0 commit comments

Comments
 (0)