horizonzy commented on code in PR #3620:
URL: https://github.com/apache/bookkeeper/pull/3620#discussion_r1070547812
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/client/PendingAddOpTest.java:
##########
@@ -87,4 +103,70 @@ public void testExecuteAfterCancelled() {
assertNull(op.lh);
}
+ @Test
+ public void testLedgerHandleWithDeferredSyncDuringRecoveryAdd() throws
Exception {
+ final BookieId b1 = new BookieSocketAddress("b1", 3181).toBookieId();
+ final BookieId b2 = new BookieSocketAddress("b2", 3181).toBookieId();
+ final BookieId b3 = new BookieSocketAddress("b3", 3181).toBookieId();
+ MockClientContext clientCtx = MockClientContext.create();
+ Versioned<LedgerMetadata> md = ClientUtil.setupLedger(clientCtx, 0,
+
LedgerMetadataBuilder.create().withInRecoveryState().newEnsembleEntry(0L,
+ Lists.newArrayList(b1, b2, b3)));
+ LedgerHandle lh = new LedgerHandle(clientCtx, 0, md,
BookKeeper.DigestType.CRC32C,
+ ClientUtil.PASSWD, EnumSet.of(WriteFlag.DEFERRED_SYNC));
+ lh.notifyWriteFailed(0, b1);
+ AtomicInteger rcHolder = new AtomicInteger(-0xdead);
+ PendingAddOp op = PendingAddOp.create(
+ lh, mockClientContext, lh.getCurrentEnsemble(),
+ payload, EnumSet.of(WriteFlag.DEFERRED_SYNC),
+ (rc, handle, entryId, qwcLatency, ctx) -> {
+ rcHolder.set(rc);
+ }, null).enableRecoveryAdd();
+ assertSame(lh, op.lh);
+ lh.pendingAddOps.add(op);
+ op.setEntryId(0);
+ lh.pendingAddOps.add(op);
+ lh.clientCtx.getMainWorkerPool().submitOrdered(lh.ledgerId,
(Callable<Void>) () -> {
+ op.run();
+ return null;
+ }).get();
+ }
+
+ @Test
+ public void
testReadOnlyLedgerHandleWithNotEnoughBookiesExceptionDuringRecoveryAdd() throws
Exception {
+ final BookieId b1 = new BookieSocketAddress("b1", 3181).toBookieId();
+ final BookieId b2 = new BookieSocketAddress("b2", 3181).toBookieId();
+ final BookieId b3 = new BookieSocketAddress("b3", 3181).toBookieId();
+ MockBookies mockBookies = new MockBookies();
+ ClientConfiguration conf = new ClientConfiguration();
+ MockRegistrationClient regClient = new MockRegistrationClient();
+ EnsemblePlacementPolicy placementPolicy = new
DefaultEnsemblePlacementPolicy();
+ BookieWatcher bookieWatcher = new MockBookieWatcher(conf,
placementPolicy,
+ regClient,
+ new DefaultBookieAddressResolver(regClient),
+ NullStatsLogger.INSTANCE);
+ ClientContext clientCtx = MockClientContext.create(mockBookies, conf,
regClient, placementPolicy,
+ bookieWatcher);
+ Versioned<LedgerMetadata> md = ClientUtil.setupLedger(clientCtx, 0,
+
LedgerMetadataBuilder.create().withInRecoveryState().newEnsembleEntry(0L,
+ Lists.newArrayList(b1, b2, b3)));
+ ReadOnlyLedgerHandle lh = new ReadOnlyLedgerHandle(clientCtx, 0, md,
BookKeeper.DigestType.CRC32C,
+ ClientUtil.PASSWD, true);
+ lh.notifyWriteFailed(0, b1);
Review Comment:
In the normal case, it can't happen.
`lh.notifyWriteFailed(0, b1);` should not before `op.run()`, it just for
test I guess.
I'm curious about why the problem happened. Could you add a test to mock the
real case? thanks a lot.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]