Remove a potential deadlock when shutting down a RoutingTableProvider.#1751
Merged
jiajunwang merged 1 commit intoapache:masterfrom May 26, 2021
Merged
Remove a potential deadlock when shutting down a RoutingTableProvider.#1751jiajunwang merged 1 commit intoapache:masterfrom
jiajunwang merged 1 commit intoapache:masterfrom
Conversation
This PR aims to avoid a potential deadlock that happens in a race condition when shutting down RoutingTableProvider. The race condition happens when the RoutingTableProvider is shutdown and the corresponding HelixManager is processing an onLiveInstanceChange event. Both threads require 2 locks, HelixManager lock and RoutingTableProvider._lastSeenSessions, in different orders. To resolve this problem, this PR changes 2 logics. 1. Remove the _lastSeenSessions lock usage. So no more deadlock. The logic correctness is now ensured by the AtomicReference.getAndSet method. 2. Remove LiveInstanceChangeListener in the shutdown call before processing the other logics. This is a missing logic and should be done regardless of the deadlock problem.Moreover, this change also avoids a more complicated race condition introduced by the previous change that may lead to CurrentStates callback handler leakage. Test cases in TestZkCallbackHandlerLeak has been updated to validate the logic changes.
junkaixue
reviewed
May 25, 2021
helix-core/src/main/java/org/apache/helix/spectator/RoutingTableProvider.java
Show resolved
Hide resolved
junkaixue
approved these changes
May 26, 2021
Contributor
Author
|
Approved by @junkaixue , I will merge the PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
Fixes #1748
Description
This PR aims to avoid a potential deadlock that happens in a race condition when shutting down RoutingTableProvider.
The race condition happens when the RoutingTableProvider is shut down and the corresponding HelixManager is processing an onLiveInstanceChange event. Both threads require 2 locks, HelixManager lock, and RoutingTableProvider._lastSeenSessions, in different orders.
To resolve this problem, this PR changes 2 logic.
Test cases in TestZkCallbackHandlerLeak have been updated to validate the logic changes.
Tests
TestZkCallbackHandlerLeak
I run the test over the weekend, passed continuously 3533 times already.
(If CI test fails due to known issue, please specify the issue and test PR locally. Then copy & paste the result of "mvn test" to here.)
Changes that Break Backward Compatibility (Optional)
(Consider including all behavior changes for public methods or API. Also include these changes in merge description so that other developers are aware of these changes. This allows them to make relevant code changes in feature branches accounting for the new method/API behavior.)
Documentation (Optional)
(Link the GitHub wiki you added)
Commits
Code Quality
(helix-style-intellij.xml if IntelliJ IDE is used)