codelipenghui commented on code in PR #4924:
URL: https://github.com/apache/bookkeeper/pull/4924#discussion_r4497512523
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java:
##########
@@ -146,10 +147,11 @@ long getEntryId() {
private void sendWriteRequest(List<BookieId> ensemble, int bookieIndex) {
int flags = isRecoveryAdd ? FLAG_RECOVERY_ADD | FLAG_HIGH_PRIORITY :
FLAG_NONE;
+ // The client can report a pool lookup failure inline.
+ ++pendingWriteRequests;
clientCtx.getBookieClient().addEntry(ensemble.get(bookieIndex),
lh.ledgerId, lh.ledgerKey,
entryId, toSend, this, bookieIndex,
flags, allowFailFast,
lh.writeFlags, lh.executor);
Review Comment:
**Protect the initial send loop from inline recycling**
Add through a still-open LedgerHandle after its BookKeeper client closes, or
race client shutdown with the first initial write. BookieClientImpl then
reports ClientClosedException synchronously from addEntry. The error callback
completes, but the initial send loop subsequently dereferences a cleared ledger
handle and throws NullPointerException. Synchronous addEntry no longer produces
the expected BKClientClosedException, and appendAsync can throw instead of
returning its exceptionally completed future.
The pre-increment changes the first inline response's pendingWriteRequests
transition to 1→0.
[BookieClientImpl](<apache/bookkeeper/pr-4924/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieClientImpl.java#L309-L313>)
invokes the callback directly when lookup fails, and
[getRc](<apache/bookkeeper/pr-4924/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieClientImpl.java#L144-L151>)
maps this to ClientClosedException after shutdown.
[writeComplete](<apache/bookkeeper/pr-4924/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java#L266-L268>)
decrements the count, then its [client-closed
branch](<apache/bookkeeper/pr-4924/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java#L324-L327>)
drains pending adds and delivers callbacks. Because initiate already set
hasRun=true,
[maybeRecycle](<apache/bookkeeper/pr-4924/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java#L496-L502>)
n
ow recycles the operation and clears lh. Control returns to the unguarded
[initial
loop](<apache/bookkeeper/pr-4924/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java#L259-L262>),
whose next condition accesses lh.distributionSchedule. The new liveness guard
protects resendEnsembleChange, not initiate. The existing [close
test](<apache/bookkeeper/pr-4924/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java#L241-L278>)
explicitly requires normal client-closed error handling for this scenario; it
was inspected, not executed.
Keep the counter pre-increment, but prevent initiate from accessing recycled
state: check operation liveness before evaluating its loop condition and before
each initial send, or defer recycling until initialization exits. Add a
deterministic test that uses the actual initiation path and invokes
ClientClosedException inline on its first write, asserting one error callback,
no unchecked exception and no further sends. Also run
BookKeeperCloseTest#testAddLedgerEntry.
--
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]