-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-7956 In ShutdownableThread, immediately complete the shutdown if the thread has not been started #6218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
d20095e
292d279
4dfef44
445a3af
a2c0f91
7c6ac0d
92f71e4
4a20222
54826d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,8 @@ abstract class ShutdownableThread(val name: String, val isInterruptible: Boolean | |
| this.logIdent = "[" + name + "]: " | ||
| private val shutdownInitiated = new CountDownLatch(1) | ||
| private val shutdownComplete = new CountDownLatch(1) | ||
|
|
||
| @volatile private var isStarted: Boolean = false | ||
|
|
||
| def shutdown(): Unit = { | ||
| initiateShutdown() | ||
| awaitShutdown() | ||
|
|
@@ -54,8 +55,13 @@ abstract class ShutdownableThread(val name: String, val isInterruptible: Boolean | |
| * After calling initiateShutdown(), use this API to wait until the shutdown is complete | ||
| */ | ||
| def awaitShutdown(): Unit = { | ||
| shutdownComplete.await() | ||
| info("Shutdown completed") | ||
| if (shutdownInitiated.getCount != 0) | ||
| throw new IllegalStateException("initiateShutdown() was not called before awaitShutdown()") | ||
| else { | ||
| if (isStarted) | ||
| shutdownComplete.await() | ||
| info("Shutdown completed") | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -76,6 +82,7 @@ abstract class ShutdownableThread(val name: String, val isInterruptible: Boolean | |
| def doWork(): Unit | ||
|
|
||
| override def run(): Unit = { | ||
| isStarted = true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, do we need to set isStarted here again since it's already set in start()?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to cover the case where
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case, could we just set it in run() and not in start()?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added in the In the current state, if We end up with different guarantees based on how the class is run, which is not optimal. I think the only one we can guarantee across both |
||
| info("Starting") | ||
| try { | ||
| while (isRunning) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a comment like "// The shutting down of the thread has been initiated at this point. Just ignore this event"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sounds good!