-
Notifications
You must be signed in to change notification settings - Fork 414
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
RATIS-2146 Fixed possible issues caused by concurrent deletion and election when member changes #1140
Merged
Merged
RATIS-2146 Fixed possible issues caused by concurrent deletion and election when member changes #1140
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Oops, something went wrong.
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.
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.
The
CountDownLatch
may not help. When close() returns, it must past the linecloseFinishedLatch.countDown();
. The new code seems the same as the existing code.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.
In fact, there is a difference because lifeCycle.checkStateAndClose is a CAS (Compare-And-Swap) operation, meaning only the thread that successfully performs the CAS can execute this function.
In our reproduced case, the election thread successfully performed the CAS to set the state to closing and was executing the shutdown code inside. Then, when the thread responsible for deleting the raftgroup called this function and found that the state was closing, it essentially did nothing and returned to delete the file directory, which subsequently caused an error in StateMachineUpdater.
I checked the contents of this lambda expression, and except for FollowerState and LeaderElection which are asynchronous, the rest should be synchronous, including the StateMachineUpdater that we discovered this time. Therefore, after adding this countDownLatch, at least the error we found will not occur again.
As for whether it's necessary to also synchronize the waiting for FollowerState and LeaderElection, I think it could be either way. Even if they clean up asynchronously, they will ultimately just transition to Leader, and the underlying shutdownLeaderState and state.close can prevent any impact from occurring.
Additionally, I found that we can't directly add a synchronized signature to the close function, because this lambda function will still only be executed by the thread that successfully performs the CAS.
Overall, I feel that the current changes should not introduce any side effects. What do you think? @szetszwo
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.
@OneSizeFitsQuorum , thanks for the detailed explanation! I understand the change now.