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: fix read index request for #7331 #7332

Merged
merged 1 commit into from
Feb 17, 2017
Merged

raft: fix read index request for #7331 #7332

merged 1 commit into from
Feb 17, 2017

Conversation

hhkbp2
Copy link
Contributor

@hhkbp2 hhkbp2 commented Feb 15, 2017

Hi,

This PR tries to fix issue #7331 . It follows the raft thesis 6.4 to reject read only request when a new leader has not committed any log entry at its term.

@@ -823,6 +823,11 @@ func stepLeader(r *raft, m pb.Message) {
return
case pb.MsgReadIndex:
if r.quorum() > 1 {
if r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(r.raftLog.committed)) != r.Term {
// Reject read only request when this leader has not committed any log entry at its term.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we drop the message here directly, how do we know it outside?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's usual to drop message like this. E.g. Requests like proposes are usually dropped in raft. And it's possible the a MsgReadIndex is lost due to network issue when follower forwards it to leader.
There should be a timeout/retry of requests outside this module.

@codecov-io
Copy link

codecov-io commented Feb 15, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@4608210). Click here to learn what that means.
The diff coverage is 0%.

@@           Coverage Diff            @@
##             master   #7332   +/-   ##
========================================
  Coverage          ?   64.9%           
========================================
  Files             ?     230           
  Lines             ?   20723           
  Branches          ?       0           
========================================
  Hits              ?   13450           
  Misses            ?    6281           
  Partials          ?     992
Impacted Files Coverage Δ
raft/raft.go 91.43% <ø> (ø)

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 4608210...0f1550c. Read the comment docs.

@xiang90
Copy link
Contributor

xiang90 commented Feb 15, 2017

@hhkbp2 Good fix. Can you add a test for it?

@hhkbp2
Copy link
Contributor Author

hhkbp2 commented Feb 16, 2017

@xiang90 A test case is added.

// Force peer a to become leader.
nt.send(pb.Message{From: 1, To: 1, Type: pb.MsgHup})
if a.state != StateLeader {
t.Fatalf("state = %, want %s", a.state, StateLeader)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix print format?

@xiang90
Copy link
Contributor

xiang90 commented Feb 17, 2017

One minor issue. LGTM after fixing it.

@xiang90
Copy link
Contributor

xiang90 commented Feb 17, 2017

@hhkbp2 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants