poorbarcode commented on code in PR #21542:
URL: https://github.com/apache/pulsar/pull/21542#discussion_r1390134908
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -4052,33 +4051,39 @@ protected void asyncCreateLedger(BookKeeper bookKeeper,
ManagedLedgerConfig conf
));
} catch
(EnsemblePlacementPolicyConfig.ParseEnsemblePlacementPolicyConfigException e) {
log.error("[{}] Serialize the placement configuration failed",
name, e);
- cb.createComplete(Code.UnexpectedConditionException, null,
ledgerCreated);
+ cb.createComplete(Code.UnexpectedConditionException, null,
ledgerFutureHook);
return;
}
}
createdLedgerCustomMetadata = finalMetadata;
-
try {
bookKeeper.asyncCreateLedger(config.getEnsembleSize(),
config.getWriteQuorumSize(),
- config.getAckQuorumSize(), digestType,
config.getPassword(), cb, ledgerCreated, finalMetadata);
+ config.getAckQuorumSize(), digestType,
config.getPassword(), cb, ledgerFutureHook, finalMetadata);
} catch (Throwable cause) {
log.error("[{}] Encountered unexpected error when creating ledger",
name, cause);
- cb.createComplete(Code.UnexpectedConditionException, null,
ledgerCreated);
+ ledgerFutureHook.completeExceptionally(cause);
+ cb.createComplete(Code.UnexpectedConditionException, null,
ledgerFutureHook);
Review Comment:
> I am curious why method bookKeeper.asyncCreateLedger will throw an
exception but not call the callback. How does the caller know whether a
callback is called or not?
I think the `try{}catch{}` here is just to ensure that all the situations
are handled correctly. Since `bookKeeper.asyncCreateLedger` will try to get a
lock, maybe an `InterruptedException` will be through?
> Because it has a risk of calling the callback method twice.
There are 3 places that will call `cb. createComplete `
- Catch an Ex here
- Create a ledger successfully
- Timeout
If we get an Ex here, it means something wrong before switching a thread to
actually create the ledger, so the ledger will not be created successfully.
If we get an Ex here, it means the timeout checker will not be created.
So there is no risk of calling the callback method twice.
--
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]