Skip to content
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

raft: require app to consume result from Ready() #10920

Merged
merged 1 commit into from
Jul 24, 2019
Merged

Conversation

tbg
Copy link
Contributor

@tbg tbg commented Jul 23, 2019

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 certain
ways while the Ready was being handled. Failure to do so would result in
dropped messages (and perhaps worse). For example, with the following
operations

  1. rd := rawNode.Ready()
  2. rawNode.Step(someMsg)
  3. rawNode.Advance(rd)

someMsg would be dropped, because Advance() would clear out the
outgoing 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() must
be 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.

I changed `(*RawNode).Ready`'s behavior in etcd-io#10892 in a problematic way.
Previously, `Ready()` would create and immediately "accept" a Ready
(i.e. commit the app to actually handling it). In etcd-io#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 certain
ways while the Ready was being handled. Failure to do so would result in
dropped messages (and perhaps worse). For example, with the following
operations

1. `rd := rawNode.Ready()`
2. `rawNode.Step(someMsg)`
3. `rawNode.Advance(rd)`

`someMsg` would be dropped, because `Advance()` would clear out the
outgoing 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()` must
be handled by the app) and adds a regression test.

While I was there, I carried out a few small clarifying refactors.
@tbg tbg requested a review from bdarnell July 23, 2019 20:57
@codecov-io
Copy link

Codecov Report

Merging #10920 into master will increase coverage by 0.2%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #10920     +/-   ##
=========================================
+ Coverage   62.79%   62.99%   +0.2%     
=========================================
  Files         400      400             
  Lines       37689    37687      -2     
=========================================
+ Hits        23665    23741     +76     
+ Misses      12415    12345     -70     
+ Partials     1609     1601      -8
Impacted Files Coverage Δ
raft/node.go 89.51% <100%> (ø) ⬆️
raft/rawnode.go 71.91% <100%> (-0.62%) ⬇️
proxy/httpproxy/director.go 61.42% <0%> (-18.58%) ⬇️
clientv3/balancer/grpc1.7-health.go 4.94% <0%> (-11.05%) ⬇️
clientv3/naming/grpc.go 68.42% <0%> (-7.02%) ⬇️
clientv3/leasing/cache.go 87.22% <0%> (-4.45%) ⬇️
proxy/grpcproxy/watcher.go 89.79% <0%> (-4.09%) ⬇️
etcdserver/api/v3rpc/lease.go 69.31% <0%> (-3.41%) ⬇️
auth/options.go 47.5% <0%> (-2.5%) ⬇️
auth/store.go 62.22% <0%> (-1.8%) ⬇️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a91f4e4...721127d. Read the comment docs.

@tbg tbg merged commit d137fa9 into etcd-io:master Jul 24, 2019
@tbg tbg deleted the rawnode-ready branch July 24, 2019 09:47
@tbg
Copy link
Contributor Author

tbg commented Jul 24, 2019

Thanks @bdarnell.

absolute8511 added a commit to youzan/ZanRedisDB that referenced this pull request Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants