zhaohaidao commented on code in PR #3620:
URL: https://github.com/apache/bookkeeper/pull/3620#discussion_r1081025244
##########
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:
I try to give a scenario where the problem might occur.
The client tries to write 945 and 946 to the same ledger (id=1256)
successively, and writes 3 copies of each entry. Write 945 is successful but
one of the bookies returns an exception, so
LedgerHandle.delayedWriteFailedBookies will not be empty. Then when writing
946, if a BKNotEnoughBookiesException is thrown, an NPE issue will occur.
It is a little troublesome to construct the above scenario, so I ensure that
delayedWriteFailedBookies is not empty (by lh.notifyWriteFailed(0, b1)) from
the beginning of my test case, so that I can quickly verify the npe issue.
It should be noted that this is a scenario I deduced from the error log. In
the log, only 946 write failures caused by BKNotEnoughBookiesException can be
seen.
--
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]