mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: remove clearState
This commit is contained in:
parent
3823b74208
commit
0f50188652
@ -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) {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user