Copilot commented on code in PR #4925:
URL: https://github.com/apache/bookkeeper/pull/4925#discussion_r4449581572
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/ZkLedgerAuditorManager.java:
##########
@@ -96,6 +98,10 @@ public void tryToBecomeAuditor(String bookieId,
Consumer<AuditorEvent> listener)
try {
while (!isClosed) {
createMyVote(bookieId);
+ if (isClosed) {
+ // close() might have missed the vote just created
+ break;
+ }
Review Comment:
After this check, `getChildren()` can capture this vote first, then
`close()` can delete it before the winning branch publishes the auditor ID and
returns success. The closed candidate bypasses the new `IllegalStateException`
and can overwrite a replacement auditor's diagnostic ID. Coordinate the final
success check and publication with `close()`, keeping the predecessor wait
outside that synchronization.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorElector.java:
##########
@@ -238,18 +246,14 @@ public void shutdown() throws InterruptedException {
if (executor.isShutdown()) {
return;
}
- // close auditor manager
- try {
- submitShutdownTask().get(10, TimeUnit.SECONDS);
- executor.shutdown();
- } catch (ExecutionException e) {
- log.warn().exception(e).log("Failed to close auditor manager");
- executor.shutdownNow();
- shutdownTask.run();
- } catch (TimeoutException e) {
- log.warn().exception(e).log("Failed to close auditor manager
in 10 seconds");
+ // Close the auditor manager from this thread: on a bookie that is
not the auditor,
+ // the election task waits in tryToBecomeAuditor() until the
bookie becomes the
+ // auditor, and closing the manager is what ends that wait.
+ shutdownTask.run();
Review Comment:
During a ZooKeeper outage, this synchronous close can block shutdown before
it reaches the executor timeout or auditor cleanup: vote deletion retries
connection failures with a default limit of `Integer.MAX_VALUE`. On an elected
auditor, the previous queued close could be interrupted after 10 seconds. Keep
close off the election queue, but run it in a separate bounded, cancellable
task or separate the immediate election wake-up from bounded vote deletion.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorElector.java:
##########
@@ -238,18 +246,14 @@ public void shutdown() throws InterruptedException {
if (executor.isShutdown()) {
return;
}
- // close auditor manager
- try {
- submitShutdownTask().get(10, TimeUnit.SECONDS);
- executor.shutdown();
- } catch (ExecutionException e) {
- log.warn().exception(e).log("Failed to close auditor manager");
- executor.shutdownNow();
- shutdownTask.run();
- } catch (TimeoutException e) {
- log.warn().exception(e).log("Failed to close auditor manager
in 10 seconds");
+ // Close the auditor manager from this thread: on a bookie that is
not the auditor,
+ // the election task waits in tryToBecomeAuditor() until the
bookie becomes the
+ // auditor, and closing the manager is what ends that wait.
+ shutdownTask.run();
+ executor.shutdown();
+ if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
Review Comment:
If `awaitTermination()` is interrupted, including when manager close
restores the caller's interrupt flag, shutdown skips cancellation of the
election and cleanup of the auditor and owned BookKeeper client. Later calls
cannot finish cleanup because the executor is already marked shut down. Cancel
the election and complete the remaining cleanup before propagating the
interruption.
--
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]