diff --git a/raft/raft.go b/raft/raft.go index 6375abd2edcf..020aff296f2f 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -573,6 +573,11 @@ func (r *raft) advance(rd Ready) { if len(rd.Entries) > 0 { e := rd.Entries[len(rd.Entries)-1] r.raftLog.stableTo(e.Index, e.Term) + // If this is a single-voter configuration we need to simulate the leader + // sending an MsgAppResp to itself. + if r.id == r.lead && r.prs.IsSingleton() && r.prs.Progress[r.id].MaybeUpdate(e.Index) { + r.maybeCommit() + } } if !IsEmptySnap(rd.Snapshot) { r.raftLog.stableSnapTo(rd.Snapshot.Metadata.Index) @@ -635,9 +640,6 @@ func (r *raft) appendEntry(es ...pb.Entry) (accepted bool) { } // use latest "last" index after truncate/append li = r.raftLog.append(es...) - r.prs.Progress[r.id].MaybeUpdate(li) - // Regardless of maybeCommit's return, our caller will call bcastAppend. - r.maybeCommit() return true } diff --git a/raft/testdata/single_node.txt b/raft/testdata/single_node.txt index 112b32c04041..3b6e4f4c1dd9 100644 --- a/raft/testdata/single_node.txt +++ b/raft/testdata/single_node.txt @@ -20,8 +20,11 @@ stabilize > 1 handling Ready Ready MustSync=true: Lead:1 State:StateLeader - HardState Term:1 Vote:1 Commit:4 + HardState Term:1 Vote:1 Commit:3 Entries: 1/4 EntryNormal "" +> 1 handling Ready + Ready MustSync=false: + HardState Term:1 Vote:1 Commit:4 CommittedEntries: 1/4 EntryNormal ""