Skip to content

Commit 0dc89b4

Browse files
committed
fix: normalize from and gate fallback on self
1 parent dea4510 commit 0dc89b4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

raft.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,8 +1787,15 @@ func stepLeader(r *raft, m pb.Message) error {
17871787
bucket = make(map[string]pb.Entry)
17881788
r.proposalCache[m.Index] = bucket
17891789
}
1790+
1791+
// Local self-proposals come in with From=None (0); treat as leader.
1792+
from := m.From
1793+
if from == None {
1794+
from = r.id
1795+
}
1796+
17901797
// Leader-preferred caching: our own payload must win to preserve Header.ID.
1791-
if m.From == r.id {
1798+
if from == r.id {
17921799
bucket[cid] = e
17931800
} else {
17941801
if _, ok := bucket[cid]; !ok {
@@ -1797,10 +1804,10 @@ func stepLeader(r *raft, m pb.Message) error {
17971804
}
17981805

17991806
// classic-fallback when mixed cluster can't produce fast-vote CQ.
1800-
// If this is the next index k and we haven't installed a leader-approved entry yet,
1807+
// If this is OUR fast-prop for the next index k and we haven't installed a leader-approved entry yet,
18011808
// pick this payload and replicate classically. First-wins policy is fine.
18021809
k := r.raftLog.committed + 1
1803-
if m.Index == k && !r.hasLeaderApprovedAt(k) {
1810+
if from == r.id && m.Index == k && !r.hasLeaderApprovedAt(k) {
18041811
// Materialize leader-approved entry from the cached payload.
18051812
chosen := bucket[cid]
18061813
setOrigin(&chosen, pb.EntryOriginLeader) // leader canon

0 commit comments

Comments
 (0)