raft: drop nodes in softState

This commit is contained in:
Xiang Li 2014-12-08 21:17:04 -08:00
parent 29d7a2a558
commit a5efbf826d
5 changed files with 14 additions and 28 deletions

View File

@ -395,7 +395,7 @@ func (s *EtcdServer) run() {
// snapi indicates the index of the last submitted snapshot request
snapi := snap.Metadata.Index
appliedi := snap.Metadata.Index
confState := &snap.Metadata.ConfState
confState := snap.Metadata.ConfState
defer func() {
s.node.Stop()
@ -458,7 +458,7 @@ func (s *EtcdServer) run() {
ents = rd.CommittedEntries[appliedi+1-firsti:]
}
if len(ents) > 0 {
if appliedi, shouldstop = s.apply(ents, confState); shouldstop {
if appliedi, shouldstop = s.apply(ents, &confState); shouldstop {
return
}
}
@ -468,7 +468,7 @@ func (s *EtcdServer) run() {
if appliedi-snapi > s.snapCount {
log.Printf("etcdserver: start to snapshot (applied: %d, lastsnap: %d)", appliedi, snapi)
s.snapshot(appliedi, confState)
s.snapshot(appliedi, &confState)
snapi = appliedi
}
case <-syncC:
@ -784,7 +784,7 @@ func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.Con
s.node.ApplyConfChange(cc)
return false, err
}
confState = s.node.ApplyConfChange(cc)
*confState = *s.node.ApplyConfChange(cc)
switch cc.Type {
case raftpb.ConfChangeAddNode:
m := new(Member)

View File

@ -509,7 +509,7 @@ func TestApplyConfChangeShouldStop(t *testing.T) {
NodeID: 2,
}
// remove non-local member
shouldStop, err := srv.applyConfChange(cc, nil)
shouldStop, err := srv.applyConfChange(cc, &raftpb.ConfState{})
if err != nil {
t.Fatalf("unexpected error %v", err)
}
@ -519,7 +519,7 @@ func TestApplyConfChangeShouldStop(t *testing.T) {
// remove local member
cc.NodeID = 1
shouldStop, err = srv.applyConfChange(cc, nil)
shouldStop, err = srv.applyConfChange(cc, &raftpb.ConfState{})
if err != nil {
t.Fatalf("unexpected error %v", err)
}
@ -1095,10 +1095,7 @@ func TestApplySnapshotAndCommittedEntries(t *testing.T) {
func TestAddMember(t *testing.T) {
n := newNodeConfChangeCommitterRecorder()
n.readyc <- raft.Ready{
SoftState: &raft.SoftState{
RaftState: raft.StateLeader,
Nodes: []uint64{2345, 3456},
},
SoftState: &raft.SoftState{RaftState: raft.StateLeader},
}
cl := newTestCluster(nil)
cl.SetStore(store.New())
@ -1132,10 +1129,7 @@ func TestAddMember(t *testing.T) {
func TestRemoveMember(t *testing.T) {
n := newNodeConfChangeCommitterRecorder()
n.readyc <- raft.Ready{
SoftState: &raft.SoftState{
RaftState: raft.StateLeader,
Nodes: []uint64{1234, 2345, 3456},
},
SoftState: &raft.SoftState{RaftState: raft.StateLeader},
}
cl := newTestCluster(nil)
cl.SetStore(store.New())
@ -1169,10 +1163,7 @@ func TestRemoveMember(t *testing.T) {
func TestUpdateMember(t *testing.T) {
n := newNodeConfChangeCommitterRecorder()
n.readyc <- raft.Ready{
SoftState: &raft.SoftState{
RaftState: raft.StateLeader,
Nodes: []uint64{1234, 2345, 3456},
},
SoftState: &raft.SoftState{RaftState: raft.StateLeader},
}
cl := newTestCluster(nil)
cl.SetStore(store.New())
@ -1579,7 +1570,7 @@ func (n *nodeRecorder) Ready() <-chan raft.Ready { return nil }
func (n *nodeRecorder) Advance() {}
func (n *nodeRecorder) ApplyConfChange(conf raftpb.ConfChange) *raftpb.ConfState {
n.record(action{name: "ApplyConfChange", params: []interface{}{conf}})
return nil
return &raftpb.ConfState{}
}
func (n *nodeRecorder) Stop() {
n.record(action{name: "Stop"})
@ -1643,7 +1634,7 @@ func (n *nodeConfChangeCommitterRecorder) Ready() <-chan raft.Ready {
}
func (n *nodeConfChangeCommitterRecorder) ApplyConfChange(conf raftpb.ConfChange) *raftpb.ConfState {
n.record(action{name: "ApplyConfChange:" + conf.Type.String()})
return nil
return &raftpb.ConfState{}
}
type waitWithResponse struct {

View File

@ -19,7 +19,6 @@ package raft
import (
"errors"
"log"
"reflect"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
pb "github.com/coreos/etcd/raft/raftpb"
@ -37,11 +36,10 @@ var (
type SoftState struct {
Lead uint64
RaftState StateType
Nodes []uint64
}
func (a *SoftState) equal(b *SoftState) bool {
return reflect.DeepEqual(a, b)
return a.Lead == b.Lead && a.RaftState == b.RaftState
}
// Ready encapsulates the entries and messages that are ready to read,

View File

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

View File

@ -175,9 +175,7 @@ func (r *raft) hasLeader() bool { return r.lead != None }
func (r *raft) leader() uint64 { return r.lead }
func (r *raft) softState() *SoftState {
return &SoftState{Lead: r.lead, RaftState: r.state, Nodes: r.nodes()}
}
func (r *raft) softState() *SoftState { return &SoftState{Lead: r.lead, RaftState: r.state} }
func (r *raft) q() int { return len(r.prs)/2 + 1 }