Skip to content
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

MINOR: a small refactor for LogManage#shutdown #9680

Merged
merged 1 commit into from
Dec 4, 2020
Merged

MINOR: a small refactor for LogManage#shutdown #9680

merged 1 commit into from
Dec 4, 2020

Conversation

APaMio
Copy link
Contributor

@APaMio APaMio commented Dec 3, 2020

LogManage Modify

@chia7712

@chia7712
Copy link
Member

chia7712 commented Dec 3, 2020

@APaMio Thanks for your patch. Could you revise the title? The “caee2” is a bit weird to me :)

@APaMio APaMio changed the title MINOR: case2.patch MINOR: LogManage Modify Dec 3, 2020
@chia7712 chia7712 changed the title MINOR: LogManage Modify MINOR: a small refactor for LogManage#shutdown Dec 4, 2020
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@APaMio Thanks for your patch. LGTM

@chia7712 chia7712 merged commit df0c52e into apache:trunk Dec 4, 2020
Try(future.get) match {
case Success(_) => false
case Failure(e) =>
warn(s"There was an error in one of the threads during LogManager shutdown: ${e.getCause}")
true
}
}.contains(true)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712 This changed behavior. Previously we would call get on every Future and now we don't. @kowshik @junrao Seems like we didn't add a test that verifies the recent fix in this area?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my bad. Will revert it with suitable test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #9728

Copy link
Contributor

@kowshik kowshik Dec 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712 @ijuma I think you were referring to #9596 ?

The test added in #9596 to verify this was LogManagerTest.testHandlingExceptionsDuringShutdown (link). I agree that the test wasn't effective enough to catch the problem. The issue was that fundamentally this area of the code was a little bit difficult to test due to the asynchronous behavior.

So for example, although @chia7712 has a fix in #9728, I still think it is not easy to write a test that reliably fails if the bug is introduced again.

Below is my explanation on why it is difficult to improve the existing testHandlingExceptionsDuringShutdown to catch such issues. Let us imagine that the test setup introduced multiple logs for each log dir, and setup an expectation (in the test code) that if one of the logs failed during close(), then, the other logs under the same log directory should still be closed by the time LogManager.shutdown() returns. Such a kind of test expectation would have caught the problem introduced in this PR. Now, writing that kind of a test was not easy, because, even if one of the logs failed to close, the other futures can still be completed by the time LogManager.shutdown() returns (there is no strong need to call future.get for the future to pass). Thus, the test can pass despite the bug.

One potential solution (a bigger change) is to see if we can inject a different thread pool executor that only during test executes the threads lazily i.e. it executes the submitted threads only when future.get is called, otherwise it will never execute them. If we succeed in doing this, then, the test can be improved such that unless future.get is called on all logs, some of the log close() will never happen and will fail the test in the presence of the bug introduced by this PR.

cc @junrao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants