Browse Source

raft: add RemovedNodes to SoftState

Yicheng Qin 11 years ago
parent
commit
eb2dd1892f
3 changed files with 8 additions and 6 deletions
  1. 5 4
      raft/node.go
  2. 2 1
      raft/node_test.go
  3. 1 1
      raft/raft.go

+ 5 - 4
raft/node.go

@@ -19,10 +19,11 @@ var (
 // SoftState provides state that is useful for logging and debugging.
 // The state is volatile and does not need to be persisted to the WAL.
 type SoftState struct {
-	Lead       uint64
-	RaftState  StateType
-	Nodes      []uint64
-	ShouldStop bool
+	Lead         uint64
+	RaftState    StateType
+	Nodes        []uint64
+	RemovedNodes []uint64
+	ShouldStop   bool
 }
 
 func (a *SoftState) equal(b *SoftState) bool {

+ 2 - 1
raft/node_test.go

@@ -156,7 +156,7 @@ func TestNode(t *testing.T) {
 	}
 	wants := []Ready{
 		{
-			SoftState: &SoftState{Lead: 1, Nodes: []uint64{1}, RaftState: StateLeader},
+			SoftState: &SoftState{Lead: 1, Nodes: []uint64{1}, RemovedNodes: []uint64{}, RaftState: StateLeader},
 			HardState: raftpb.HardState{Term: 1, Commit: 2},
 			Entries: []raftpb.Entry{
 				{},
@@ -281,6 +281,7 @@ func TestSoftStateEqual(t *testing.T) {
 		{&SoftState{RaftState: StateLeader}, false},
 		{&SoftState{ShouldStop: true}, false},
 		{&SoftState{Nodes: []uint64{1, 2}}, false},
+		{&SoftState{RemovedNodes: []uint64{1, 2}}, false},
 	}
 	for i, tt := range tests {
 		if g := tt.st.equal(&SoftState{}); g != tt.we {

+ 1 - 1
raft/raft.go

@@ -128,7 +128,7 @@ func (r *raft) hasLeader() bool { return r.lead != None }
 func (r *raft) shouldStop() bool { return r.removed[r.id] }
 
 func (r *raft) softState() *SoftState {
-	return &SoftState{Lead: r.lead, RaftState: r.state, Nodes: r.nodes(), ShouldStop: r.shouldStop()}
+	return &SoftState{Lead: r.lead, RaftState: r.state, Nodes: r.nodes(), RemovedNodes: r.removedNodes(), ShouldStop: r.shouldStop()}
 }
 
 func (r *raft) String() string {