From b4dd519a636e02c94a0a418ddccd7380bcd3644c Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 27 May 2015 13:30:08 -0700 Subject: [PATCH] raft: fix raft node start bug raft node should set initial prev hard state to empty. Or it will not send the first hard coded state to application until the state changes again. This commit fixs the issue. It introduce a small overhead, that the same tate might send to application twice when restarting. But this is fine. --- raft/node.go | 2 +- raft/node_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/raft/node.go b/raft/node.go index 177b6d5fb..5e983e86d 100644 --- a/raft/node.go +++ b/raft/node.go @@ -233,7 +233,7 @@ func (n *node) run(r *raft) { lead := None prevSoftSt := r.softState() - prevHardSt := r.HardState + prevHardSt := emptyState for { if advancec != nil { diff --git a/raft/node_test.go b/raft/node_test.go index 4da225396..518759eae 100644 --- a/raft/node_test.go +++ b/raft/node_test.go @@ -354,7 +354,7 @@ func TestNodeRestart(t *testing.T) { st := raftpb.HardState{Term: 1, Commit: 1} want := Ready{ - HardState: emptyState, + HardState: st, // commit up to index commit index in st CommittedEntries: entries[:st.Commit], } @@ -389,7 +389,7 @@ func TestNodeRestartFromSnapshot(t *testing.T) { st := raftpb.HardState{Term: 1, Commit: 3} want := Ready{ - HardState: emptyState, + HardState: st, // commit up to index commit index in st CommittedEntries: entries, }