merlimat commented on code in PR #4925:
URL: https://github.com/apache/bookkeeper/pull/4925#discussion_r4449879509
##########
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:
Fixed in 158e0b7412: an elected candidate now checks `isClosed` and
publishes its id under the lock that `close()` takes to set `isClosed` before
deleting the vote, so a closed candidate fails with `IllegalStateException`
instead. The wait for the previous vote stays outside the lock. New test:
`AuditorBookieTest.testCloseWhileCandidateIsElected`.
_🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
##########
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:
Fixed in 158e0b7412: `shutdown()` now closes the auditor manager on a
separate thread and gives it 10 seconds before interrupting it, like the close
queued on the elector's thread before. `close()` still releases a waiting
candidate before it deletes the vote.
_🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
##########
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:
Fixed in 158e0b7412: an interrupted wait now stops the election with
`shutdownNow()`, and `shutdown()` still shuts the auditor down and closes its
own client before rethrowing the `InterruptedException`. The manager close runs
on its own thread, so it no longer leaves the caller's interrupt flag set. New
test: `AuditorBookieTest.testInterruptedShutdownStopsAuditor`.
_🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
--
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]