From 0f50188652fc6353e1a47ae8bca8255c91bdc13c Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Sat, 23 Aug 2014 16:31:58 -0700 Subject: [PATCH] raft: remove clearState --- raft2/raft.go | 14 ++++---------- raft2/raft_test.go | 35 ----------------------------------- 2 files changed, 4 insertions(+), 45 deletions(-) diff --git a/raft2/raft.go b/raft2/raft.go index 10277de2c..8b844b35f 100644 --- a/raft2/raft.go +++ b/raft2/raft.go @@ -150,8 +150,6 @@ type raft struct { // pending reconfiguration pendingConf bool - unstableState State - // promotable indicates whether state machine could be promoted. // New machine has to wait until it has been added to the cluster, or it // may become the leader of the cluster without it. @@ -556,21 +554,17 @@ func (sm *raft) deleteIns(id int64) { sm.saveState() } -// saveState saves the state to sm.unstableState +// saveState saves the state to sm.State // When there is a term change, vote change or configuration change, raft // must call saveState. func (sm *raft) saveState() { sm.setState(sm.Vote, sm.Term, sm.raftLog.committed) } -func (sm *raft) clearState() { - sm.setState(0, 0, 0) -} - func (sm *raft) setState(vote, term, commit int64) { - sm.unstableState.Vote = vote - sm.unstableState.Term = term - sm.unstableState.Commit = commit + sm.Vote = vote + sm.Term = term + sm.Commit = commit } func (sm *raft) loadEnts(ents []Entry) { diff --git a/raft2/raft_test.go b/raft2/raft_test.go index 97d03b182..8a0c14dc6 100644 --- a/raft2/raft_test.go +++ b/raft2/raft_test.go @@ -898,41 +898,6 @@ func TestSlowNodeRestore(t *testing.T) { } } -func TestUnstableState(t *testing.T) { - sm := newStateMachine(0, []int64{0}) - w := State{} - - sm.setVote(1) - w.Vote = 1 - if !reflect.DeepEqual(sm.unstableState, w) { - t.Errorf("unstableState = %v, want %v", sm.unstableState, w) - } - sm.clearState() - - sm.setTerm(1) - w.Term = 1 - if !reflect.DeepEqual(sm.unstableState, w) { - t.Errorf("unstableState = %v, want %v", sm.unstableState, w) - } - sm.clearState() - - sm.raftLog.committed = 1 - sm.addIns(1, 0, 0) - w.Commit = 1 - if !reflect.DeepEqual(sm.unstableState, w) { - t.Errorf("unstableState = %v, want %v", sm.unstableState, w) - } - sm.clearState() - - sm.raftLog.committed = 2 - sm.deleteIns(1) - w.Commit = 2 - if !reflect.DeepEqual(sm.unstableState, w) { - t.Errorf("unstableState = %v, want %v", sm.unstableState, w) - } - sm.clearState() -} - func ents(terms ...int64) *raft { ents := []Entry{{}} for _, term := range terms {