Skip to content

Commit

Permalink
raft: do not panic when removing all the nodes from cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed May 16, 2016
1 parent deb21d3 commit 910781e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ func (r *raft) addNode(id uint64) {
func (r *raft) removeNode(id uint64) {
r.delProgress(id)
r.pendingConf = false

// do not try to commit or abort transferring if there is no nodes in the cluster.
if len(r.prs) == 0 {
return
}

// The quorum size is now smaller, so see if any pending entries can
// be committed.
if r.maybeCommit() {
Expand Down
7 changes: 7 additions & 0 deletions raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,13 @@ func TestRemoveNode(t *testing.T) {
if g := r.nodes(); !reflect.DeepEqual(g, w) {
t.Errorf("nodes = %v, want %v", g, w)
}

// remove all nodes from cluster
r.removeNode(1)
w = []uint64{}
if g := r.nodes(); !reflect.DeepEqual(g, w) {
t.Errorf("nodes = %v, want %v", g, w)
}
}

func TestPromotable(t *testing.T) {
Expand Down

0 comments on commit 910781e

Please sign in to comment.