diff --git a/node.go b/node.go index 9c53aed2..53663281 100644 --- a/node.go +++ b/node.go @@ -466,7 +466,7 @@ func (n *node) ProposeConfChange(ctx context.Context, cc pb.ConfChangeI) error { if err != nil { return err } - return n.Step(ctx, msg) + return n.stepWait(ctx, msg) } func (n *node) step(ctx context.Context, m pb.Message) error { diff --git a/raft.go b/raft.go index d1048294..2edf9f77 100644 --- a/raft.go +++ b/raft.go @@ -1229,7 +1229,7 @@ func stepLeader(r *raft, m pb.Message) error { if refused != "" { r.logger.Infof("%x ignoring conf change %v at config %s: %s", r.id, cc, r.prs.Config, refused) - m.Entries[i] = pb.Entry{Type: pb.EntryNormal} + return ErrProposalDropped } else { r.pendingConfIndex = r.raftLog.lastIndex() + uint64(i) + 1 } diff --git a/raft_test.go b/raft_test.go index 5637c4a4..cdcada60 100644 --- a/raft_test.go +++ b/raft_test.go @@ -3283,24 +3283,17 @@ func TestStepConfig(t *testing.T) { } // TestStepIgnoreConfig tests that if raft step the second msgProp in -// EntryConfChange type when the first one is uncommitted, the node will set -// the proposal to noop and keep its original state. +// EntryConfChange type when the first one is uncommitted, the node will drop second msgProp and return ErrProposalDropped. func TestStepIgnoreConfig(t *testing.T) { // a raft that cannot make progress r := newTestRaft(1, 10, 1, newTestMemoryStorage(withPeers(1, 2))) r.becomeCandidate() r.becomeLeader() r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Type: pb.EntryConfChange}}}) - index := r.raftLog.lastIndex() pendingConfIndex := r.pendingConfIndex - r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Type: pb.EntryConfChange}}}) - wents := []pb.Entry{{Type: pb.EntryNormal, Term: 1, Index: 3, Data: nil}} - ents, err := r.raftLog.entries(index+1, noLimit) - if err != nil { - t.Fatalf("unexpected error %v", err) - } - if !reflect.DeepEqual(ents, wents) { - t.Errorf("ents = %+v, want %+v", ents, wents) + err := r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Type: pb.EntryConfChange}}}) + if err != ErrProposalDropped { + t.Fatalf("Expected %v, got %v", ErrProposalDropped, err) } if r.pendingConfIndex != pendingConfIndex { t.Errorf("pendingConfIndex = %d, want %d", r.pendingConfIndex, pendingConfIndex)