hangc0276 commented on code in PR #4815:
URL: https://github.com/apache/bookkeeper/pull/4815#discussion_r4761187724


##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java:
##########
@@ -309,8 +310,8 @@ public void testExitCodeZK_REG_FAIL() throws Exception {
                                                  NullStatsLogger.INSTANCE, 
UnpooledByteBufAllocator.DEFAULT,
                                                  new 
MockUncleanShutdownDetection());
 
-        bkServer.start();
-        bkServer.join();
+        assertThatThrownBy(bkServer::start)

Review Comment:
   This asserts only the exception type from `BookieServer.start()`. The 
behaviour that matters to operators is what happens after the exception goes 
through `BookieService` / `ComponentStarter` / `Main` (see my comment on 
`BookieServer.java`), and that is untested.
   
   Also, with this PR `testOneJournalReplayForBookieRestartInReadOnlyMode` and 
`testMultipleJournalReplayForBookieRestartInReadOnlyMode` fail for me (pass on 
the base commit): `IllegalStateException: Bookie failed to start, exit code: 5` 
at line 250. Those aren't journal replay failures; replay succeeds. The restart 
waits for the previous ephemeral znode to expire, hits a ZK timeout and 
triggers shutdown with code 4, and the message shows 5 because of the exit-code 
issue above. The old code swallowed it. The CI "Bookie Tests" job is red too (I 
couldn't read its logs).



##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java:
##########
@@ -899,15 +899,15 @@ public int shutdown() {
     int shutdown(int exitCode) {
         lock.lock();
         try {
+            // the exitCode only set when first shutdown usually due to 
exception found
+            if (this.exitCode == ExitCode.OK) {
+                this.exitCode = exitCode;

Review Comment:
   Moving the assignment above `if (isRunning())` lets a late trigger rewrite 
the code after a completed shutdown. The journal thread calls 
`triggerBookieShutdown(BOOKIE_EXCEPTION)` while `shutdown()` is running, so 
`shutdown(); shutdown(ExitCode.BOOKIE_EXCEPTION); getExitCode()` returns 5, 
where the old code kept 0 
(`testAdversarialLateFailureTriggerDoesNotRewriteCleanExitCode` fails with 
`expected:<0> but was:<5>`). The logs of the failing read-only restart tests 
show exactly this (`Shutting down Bookie exitCode=0`, then `Triggering shutdown 
of Bookie exitCode=5` from the journal thread), and the stale 5 then hides the 
real failure code (4, ZK registration). Record the code only if no shutdown has 
completed yet.



##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java:
##########
@@ -134,7 +134,7 @@ public void start() throws InterruptedException, 
IOException {
         if (!this.bookie.isRunning()) {
             exitCode = bookie.getExitCode();
             this.requestProcessor.close();
-            return;
+            throw new IllegalStateException("Bookie failed to start, exit 
code: " + exitCode);

Review Comment:
   Two things about this `throw`:
   
   1. **It does not make the process fail.** `BookieService.doStart` only 
catches `InterruptedException | IOException`, so the unchecked exception 
reaches `AbstractLifecycleComponent.start()`. There the handler installed by 
`ComponentStarter` runs `ComponentShutdownHook`, which completes the lifecycle 
future *normally*, and `Main.doMain` returns `ExitCode.OK` (0). I reproduced 
this with a real `BookieService` whose registration manager fails (same setup 
as `testExitCodeZK_REG_FAIL`) run through `ComponentStarter.startComponent`: on 
this PR the future completes normally, on the base commit it never completes. 
`BookieServer.getExitCode()` is not read for the process exit code anywhere. A 
supervisor therefore sees a clean exit. Completing the future exceptionally (or 
returning `bookie.getExitCode()` from `Main`) would fix it.
   2. **The type.** `start()` declares `throws InterruptedException, 
IOException` and the description says `IOException`, but this throws the 
unchecked `IllegalStateException`, so embedders that catch `IOException` won't 
catch it.



-- 
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]

Reply via email to