Repository navigation
Conversation
SingleThreadExecutor.awaitTermination() returned runner.isAlive(): true when the thread was still running after the timeout, false when it had terminated. It also waited with runner.join(unit.toMillis(timeout)), so a timeout under 1 ms, 0 included, became join(0) and waited until the thread ended. Every OrderedExecutor is made of SingleThreadExecutors: - OrderedExecutor.awaitTermination() stops at the first thread that returns false, so it returned false as soon as the first thread had terminated, without waiting for the others. BookKeeper.close() logged "The mainWorkerPool did not shutdown cleanly" exactly when it did, and went on while the other worker threads could still run tasks. - OrderedExecutor.forceShutdown(), which BookieRequestProcessor uses for the bookie read, write and high priority thread pools, called shutdownNow() on the threads that had terminated and left alone the ones still running after the timeout. awaitTermination() now waits with TimeUnit.timedJoin(), which doesn't wait for a timeout of 0 or less and rounds a sub-millisecond one up, and returns whether the thread has ended.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the executor termination and timeout changes.
No open issues 🎉
What changed in this PR
Corrects SingleThreadExecutor.awaitTermination(), restoring termination reporting and timeout behavior used by OrderedExecutor shutdown paths.
Changes:
- Returns
trueonly when the worker thread has terminated. - Uses
TimeUnit.timedJoin()to avoid indefinite waits for zero or sub-millisecond timeouts. - Adds regression tests for termination reporting and short timeouts.
| File | Description |
|---|---|
bookkeeper-common/src/test/java/org/apache/bookkeeper/common/util/TestSingleThreadExecutor.java |
Adds termination and short-timeout regression tests. |
bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/SingleThreadExecutor.java |
Fixes the wait mechanism and termination return value. |
Review effort: Balanced
codelipenghui
left a comment
There was a problem hiding this comment.
Reviewed head ec0dfe0. No actionable findings identified within the reviewed scope. The localized fix correctly restores termination reporting and avoids unbounded waits for zero/sub-millisecond timeouts.
Validation caveats: affected-module and prerequisite test compilation passed, but the focused local test invocation stopped in a prerequisite module before executing the new tests. The existing metadata-driver integration CI failure remains unexplained.
Problem
SingleThreadExecutor.awaitTermination()returns the opposite of what it should, and waits forever for a timeoutunder 1 ms:
Every
OrderedExecutoris made ofSingleThreadExecutors, so:OrderedExecutor.awaitTermination()returnsfalseas soon as the first thread has terminated, without waiting forthe others.
BookKeeper.close()logsThe mainWorkerPool did not shutdown cleanlyprecisely when it did, and goeson while the other worker threads may still be running tasks.
OrderedExecutor.forceShutdown(), whichBookieRequestProcessoruses for the bookie read, write and high prioritythread pools, calls
shutdownNow()on the threads that terminated and leaves alone the ones still running after thetimeout.
Example
Change
TimeUnit.timedJoin()doesn't wait for a timeout of 0 or less and rounds a sub-millisecond one up to 1 ms.Testing
TestSingleThreadExecutor.testAwaitTermination: aftershutdown(), while a task still runs,awaitTermination(100 ms)must returnfalse, thentrueonce the task ends. Fails on master(
Terminated while running a task).TestSingleThreadExecutor.testAwaitTerminationWithTimeoutUnderOneMillisecond: while a task runs,awaitTermination(0, MILLISECONDS)returnsfalsewithout waiting andawaitTermination(500, MICROSECONDS)after1 ms. On master the first call waits until the 10 s JUnit timeout.
bookkeeper-commonpass. With thisbookkeeper-commonin the same reactor build,BookKeeperTest,BookKeeperCloseTest,LedgerCloseTest,BookieClientTest,TestPerChannelBookieClient,TestBookieRequestProcessor,ForceReadOnlyBookieTestandBookieShutdownTestpass (64 tests), and their logs nolonger have
The mainWorkerPool did not shutdown cleanly. With master'sbookkeeper-common,BookKeeperTestlogsit 67 times,
BookKeeperCloseTest20 andLedgerCloseTest5.