raft: require app to consume result from Ready() #10920
Merged
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.
I changed
(*RawNode).Ready
's behavior in #10892 in a problematic way.Previously,
Ready()
would create and immediately "accept" a Ready(i.e. commit the app to actually handling it). In #10892, Ready() became
a pure read-only operation and the "accepting" was moved to
Advance(rd)
. As a result it was illegal to use the RawNode in certainways while the Ready was being handled. Failure to do so would result in
dropped messages (and perhaps worse). For example, with the following
operations
rd := rawNode.Ready()
rawNode.Step(someMsg)
rawNode.Advance(rd)
someMsg
would be dropped, becauseAdvance()
would clear out theoutgoing messages thinking that they had all been handled by the client.
I mistakenly assumed that this restriction had existed prior, but this
is incorrect.
I noticed this while trying to pick up the above PR in CockroachDB,
where it caused unit test failures, precisely due to the above example.
This PR reestablishes the previous behavior (result of
Ready()
mustbe handled by the app) and adds a regression test.
While I was there, I carried out a few small clarifying refactors.
Touches cockroachdb/cockroach#39046.