Browse Source

raft: remove configuration

Blake Mizerany 11 years ago
parent
commit
8463421448
3 changed files with 0 additions and 93 deletions
  1. 0 4
      raft/log.go
  2. 0 36
      raft/raft.go
  3. 0 53
      raft/raft_test.go

+ 0 - 4
raft/log.go

@@ -18,10 +18,6 @@ const (
 	defaultCompactThreshold = 10000
 )
 
-func isConfig(e pb.Entry) bool {
-	return e.Type == AddNode || e.Type == RemoveNode
-}
-
 type raftLog struct {
 	ents             []pb.Entry
 	unstable         int64

+ 0 - 36
raft/raft.go

@@ -108,14 +108,6 @@ type raft struct {
 	// the leader id
 	lead int64
 
-	// pending reconfiguration
-	configuring bool
-
-	// 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.
-	promotable bool
-
 	elapsed          int
 	heartbeatTimeout int
 	electionTimeout  int
@@ -289,7 +281,6 @@ func (r *raft) becomeFollower(term int64, lead int64) {
 	r.tick = r.tickElection
 	r.lead = lead
 	r.state = stateFollower
-	r.configuring = false
 }
 
 func (r *raft) becomeCandidate() {
@@ -314,13 +305,6 @@ func (r *raft) becomeLeader() {
 	r.tick = r.tickElection
 	r.lead = r.id
 	r.state = stateLeader
-
-	for _, e := range r.raftLog.entries(r.raftLog.committed + 1) {
-		if isConfig(e) {
-			r.configuring = true
-		}
-	}
-
 	r.appendEntry(pb.Entry{Type: Normal, Data: nil})
 }
 
@@ -386,19 +370,6 @@ func (r *raft) handleSnapshot(m pb.Message) {
 	}
 }
 
-func (r *raft) addNode(id int64) {
-	r.setProgress(id, 0, r.raftLog.lastIndex()+1)
-	r.configuring = false
-	if id == r.id {
-		r.promotable = true
-	}
-}
-
-func (r *raft) removeNode(id int64) {
-	r.delProgress(id)
-	r.configuring = false
-}
-
 type stepFunc func(r *raft, m pb.Message)
 
 func stepLeader(r *raft, m pb.Message) {
@@ -410,12 +381,6 @@ func stepLeader(r *raft, m pb.Message) {
 			panic("unexpected length(entries) of a msgProp")
 		}
 		e := m.Entries[0]
-		if isConfig(e) {
-			if r.configuring {
-				panic("pending conf")
-			}
-			r.configuring = true
-		}
 		r.appendEntry(e)
 		r.bcastAppend()
 	case msgAppResp:
@@ -505,7 +470,6 @@ func (r *raft) restore(s pb.Snapshot) bool {
 			r.setProgress(n, 0, r.raftLog.lastIndex()+1)
 		}
 	}
-	r.configuring = false
 	return true
 }
 

+ 0 - 53
raft/raft_test.go

@@ -628,59 +628,6 @@ func TestStateTransition(t *testing.T) {
 	}
 }
 
-func TestConf(t *testing.T) {
-	sm := newRaft(0, []int64{0}, 0, 0)
-	sm.becomeCandidate()
-	sm.becomeLeader()
-
-	sm.Step(pb.Message{From: 0, To: 0, Type: msgProp, Entries: []pb.Entry{{Type: AddNode}}})
-	if sm.raftLog.lastIndex() != 2 {
-		t.Errorf("lastindex = %d, want %d", sm.raftLog.lastIndex(), 1)
-	}
-	if !sm.configuring {
-		t.Errorf("pendingConf = %v, want %v", sm.configuring, true)
-	}
-	if sm.raftLog.ents[2].Type != AddNode {
-		t.Errorf("type = %d, want %d", sm.raftLog.ents[1].Type, AddNode)
-	}
-
-	// deny the second configuration change request if there is a pending one
-	paniced := false
-	defer func() { recover(); paniced = true }()
-	sm.Step(pb.Message{From: 0, To: 0, Type: msgProp, Entries: []pb.Entry{{Type: AddNode}}})
-	if !paniced {
-		t.Errorf("expected panic")
-	}
-	if sm.raftLog.lastIndex() != 2 {
-		t.Errorf("lastindex = %d, want %d", sm.raftLog.lastIndex(), 1)
-	}
-}
-
-// Ensures that the new leader sets the pendingConf flag correctly according to
-// the uncommitted log entries
-func TestConfChangeLeader(t *testing.T) {
-	tests := []struct {
-		et       int64
-		wPending bool
-	}{
-		{Normal, false},
-		{AddNode, true},
-		{RemoveNode, true},
-	}
-
-	for i, tt := range tests {
-		sm := newRaft(0, []int64{0}, 0, 0)
-		sm.raftLog = &raftLog{ents: []pb.Entry{{}, {Type: tt.et}}}
-
-		sm.becomeCandidate()
-		sm.becomeLeader()
-
-		if sm.configuring != tt.wPending {
-			t.Errorf("#%d: pendingConf = %v, want %v", i, sm.configuring, tt.wPending)
-		}
-	}
-}
-
 func TestAllServerStepdown(t *testing.T) {
 	tests := []struct {
 		state stateType