-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix race condition bug during local session repair (CASSANDRA-17335) #1468
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
Conversation
CHANGES.txt
Outdated
| @@ -1,3 +1,5 @@ | |||
| Fix race condition bug during local session repair (CASSANDRA-17335) | |||
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.
This entry should go nder the 4.0.4 section
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.
Moving it
| * @param session The local session to be set to prepared. | ||
| * @return true if the session is prepared, false if not, i.e. session failed | ||
| */ | ||
| private boolean prepareSessionExceptFailed(LocalSession session) { |
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.
wdyt about overloading setStateAndSave() to have compare and set semantics? That would be a generalization of this one that could be more useful in the future.
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.
What do you suggest that should be compared inside the setStateAndSave() method? Would it be a fallback of the Preconditions.checkArgument checking the canTransitionTo of a given state, so instead of failing the method execution we just swallow it silently and log it?
If that's the suggestion, I see that the method is being used in several other places:
- handleFinalizeProposeMessage
- handleFinalizeCommitMessage
- handleStatusResponse
- cancelSession
- maybeSetRepairing
And not all of them have follow a strict compare and set pattern (some of them just have a set).
Having said that, if we wanted to overload setStateAndSave, my opinion is that it would be a slightly out of the scope change that may somehow force us to add fallbacks where we have currently none (those methods which only have a set).
I think it may require a bit of a broader discussion to basically answer this question: Are we sure we want to avoid failing fast on those cases? I am definitely open to debate.
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 suggestion is to add to:
setStateAndSave()and argumentcurrentStatethat can be null. If null the method behaves as it does now. If a state is provided it will then comparestate.getState()tocurrentStateand fail or return false if they don't match. Rename the method tocompareAndSaveStatei.e.- Add a new
setStateAndSavemethod without thecurrentStateargument for all calls that don't need the compare behavior. It will just callcompareAndSaveStatewith null.
No behavioral changes are introduced.
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.
@bereng , understanding the motivation to generalize the CAS-like operation, I'd like to point out the logic here is mostly, if not in some state, then set and save. There is also a call-site that compares with 2 states.
if (response.state == FINALIZED || response.state == FAILED)
{
setStateAndSave(session, response.state);
logger.info("Unfinished local incremental repair session {} set to state {}", sessionID, response.state);
}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.
Well if you guys don't like it I'm fine with it. It's just how I would do it but again, personal opinion, no big thing. +1
918fb59 to
b1f4640
Compare
Syncronizes session onSuccess handlePrepareSession for LocalSessions
patch by Bernardo Botella Corbi