mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Pre-apply the bootstrapping ConfChange entries.
This eliminates the need to fake an ApplyConfChange call before Campaign in tests. Fixes #1856.
This commit is contained in:
parent
6bfa5d409e
commit
3d91faf85a
12
raft/node.go
12
raft/node.go
@ -150,6 +150,18 @@ func StartNode(id uint64, peers []Peer, election, heartbeat int, storage Storage
|
||||
// TODO(bdarnell): These entries are still unstable; do we need to preserve
|
||||
// the invariant that committed < unstable?
|
||||
r.raftLog.committed = r.raftLog.lastIndex()
|
||||
// Now apply them, mainly so that the application can call Campaign
|
||||
// immediately after StartNode in tests. Note that these nodes will
|
||||
// be added to raft twice: here and when the application's Ready
|
||||
// loop calls ApplyConfChange. The calls to addNode must come after
|
||||
// all calls to raftLog.append so progress.next is set after these
|
||||
// bootstrapping entries (it is an error if we try to append these
|
||||
// entries since they have already been committed).
|
||||
// We do not set raftLog.applied so the application will be able
|
||||
// to observe all conf changes via Ready.CommittedEntries.
|
||||
for _, peer := range peers {
|
||||
r.addNode(peer.ID)
|
||||
}
|
||||
|
||||
go n.run(r)
|
||||
return &n
|
||||
|
@ -324,7 +324,6 @@ func TestNodeStart(t *testing.T) {
|
||||
}
|
||||
storage := NewMemoryStorage()
|
||||
n := StartNode(1, []Peer{{ID: 1}}, 10, 1, storage)
|
||||
n.ApplyConfChange(cc)
|
||||
n.Campaign(ctx)
|
||||
g := <-n.Ready()
|
||||
if !reflect.DeepEqual(g, wants[0]) {
|
||||
@ -421,7 +420,6 @@ func TestNodeAdvance(t *testing.T) {
|
||||
|
||||
storage := NewMemoryStorage()
|
||||
n := StartNode(1, []Peer{{ID: 1}}, 10, 1, storage)
|
||||
n.ApplyConfChange(raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 1})
|
||||
n.Campaign(ctx)
|
||||
<-n.Ready()
|
||||
n.Propose(ctx, []byte("foo"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user