Skip to content

Conversation

@bbotella
Copy link
Contributor

@bbotella bbotella commented Feb 23, 2022

Syncronizes session onSuccess handlePrepareSession for LocalSessions
patch by Bernardo Botella Corbi

CHANGES.txt Outdated
@@ -1,3 +1,5 @@
Fix race condition bug during local session repair (CASSANDRA-17335)
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@bereng bereng Mar 2, 2022

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 argument currentState that can be null. If null the method behaves as it does now. If a state is provided it will then compare state.getState() to currentState and fail or return false if they don't match. Rename the method to compareAndSaveStatei.e.
  • Add a new setStateAndSavemethod without the currentState argument for all calls that don't need the compare behavior. It will just call compareAndSaveStatewith null.

No behavioral changes are introduced.

Copy link
Contributor

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);
        }

Copy link
Contributor

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

@bbotella bbotella force-pushed the CASSANDRA-17335-4.0 branch from 918fb59 to b1f4640 Compare March 1, 2022 16:09
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