|
|
@@ -686,27 +686,18 @@ func getIDs(lg *zap.Logger, snap *raftpb.Snapshot, ents []raftpb.Entry) []uint64
|
|
|
// If `self` is not inside the given ids, it creates a Raft entry to add a
|
|
|
// default member with the given `self`.
|
|
|
func createConfigChangeEnts(lg *zap.Logger, ids []uint64, self uint64, term, index uint64) []raftpb.Entry {
|
|
|
- ents := make([]raftpb.Entry, 0)
|
|
|
- next := index + 1
|
|
|
found := false
|
|
|
for _, id := range ids {
|
|
|
if id == self {
|
|
|
found = true
|
|
|
- continue
|
|
|
- }
|
|
|
- cc := &raftpb.ConfChange{
|
|
|
- Type: raftpb.ConfChangeRemoveNode,
|
|
|
- NodeID: id,
|
|
|
}
|
|
|
- e := raftpb.Entry{
|
|
|
- Type: raftpb.EntryConfChange,
|
|
|
- Data: pbutil.MustMarshal(cc),
|
|
|
- Term: term,
|
|
|
- Index: next,
|
|
|
- }
|
|
|
- ents = append(ents, e)
|
|
|
- next++
|
|
|
}
|
|
|
+
|
|
|
+ var ents []raftpb.Entry
|
|
|
+ next := index + 1
|
|
|
+
|
|
|
+ // NB: always add self first, then remove other nodes. Raft will panic if the
|
|
|
+ // set of voters ever becomes empty.
|
|
|
if !found {
|
|
|
m := membership.Member{
|
|
|
ID: types.ID(self),
|
|
|
@@ -732,6 +723,26 @@ func createConfigChangeEnts(lg *zap.Logger, ids []uint64, self uint64, term, ind
|
|
|
Index: next,
|
|
|
}
|
|
|
ents = append(ents, e)
|
|
|
+ next++
|
|
|
}
|
|
|
+
|
|
|
+ for _, id := range ids {
|
|
|
+ if id == self {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ cc := &raftpb.ConfChange{
|
|
|
+ Type: raftpb.ConfChangeRemoveNode,
|
|
|
+ NodeID: id,
|
|
|
+ }
|
|
|
+ e := raftpb.Entry{
|
|
|
+ Type: raftpb.EntryConfChange,
|
|
|
+ Data: pbutil.MustMarshal(cc),
|
|
|
+ Term: term,
|
|
|
+ Index: next,
|
|
|
+ }
|
|
|
+ ents = append(ents, e)
|
|
|
+ next++
|
|
|
+ }
|
|
|
+
|
|
|
return ents
|
|
|
}
|