@@ -599,6 +599,10 @@ func (r *raft) sendAppend(to uint64) {
599
599
// argument controls whether messages with no entries will be sent
600
600
// ("empty" messages are useful to convey updated Commit indexes, but
601
601
// are undesirable when we're sending multiple messages in a batch).
602
+ //
603
+ // TODO(pav-kv): make invocation of maybeSendAppend stateless. The Progress
604
+ // struct contains all the state necessary for deciding whether to send a
605
+ // message.
602
606
func (r * raft ) maybeSendAppend (to uint64 , sendIfEmpty bool ) bool {
603
607
pr := r .trk .Progress [to ]
604
608
if pr .IsPaused () {
@@ -640,7 +644,8 @@ func (r *raft) maybeSendAppend(to uint64, sendIfEmpty bool) bool {
640
644
Entries : ents ,
641
645
Commit : r .raftLog .committed ,
642
646
})
643
- pr .UpdateOnEntriesSend (len (ents ), uint64 (payloadsSize (ents )))
647
+ pr .SentEntries (len (ents ), uint64 (payloadsSize (ents )))
648
+ pr .SentCommit (r .raftLog .committed )
644
649
return true
645
650
}
646
651
@@ -675,21 +680,21 @@ func (r *raft) maybeSendSnapshot(to uint64, pr *tracker.Progress) bool {
675
680
676
681
// sendHeartbeat sends a heartbeat RPC to the given peer.
677
682
func (r * raft ) sendHeartbeat (to uint64 , ctx []byte ) {
683
+ pr := r .trk .Progress [to ]
678
684
// Attach the commit as min(to.matched, r.committed).
679
685
// When the leader sends out heartbeat message,
680
686
// the receiver(follower) might not be matched with the leader
681
687
// or it might not have all the committed entries.
682
688
// The leader MUST NOT forward the follower's commit to
683
689
// an unmatched index.
684
- commit := min (r . trk . Progress [ to ] .Match , r .raftLog .committed )
685
- m := pb.Message {
690
+ commit := min (pr .Match , r .raftLog .committed )
691
+ r . send ( pb.Message {
686
692
To : to ,
687
693
Type : pb .MsgHeartbeat ,
688
694
Commit : commit ,
689
695
Context : ctx ,
690
- }
691
-
692
- r .send (m )
696
+ })
697
+ pr .SentCommit (commit )
693
698
}
694
699
695
700
// bcastAppend sends RPC, with entries to all peers that are not up-to-date
@@ -1480,7 +1485,6 @@ func stepLeader(r *raft, m pb.Message) error {
1480
1485
r .sendAppend (m .From )
1481
1486
}
1482
1487
} else {
1483
- oldPaused := pr .IsPaused ()
1484
1488
// We want to update our tracking if the response updates our
1485
1489
// matched index or if the response can move a probing peer back
1486
1490
// into StateReplicate (see heartbeat_rep_recovers_from_probing.txt
@@ -1517,9 +1521,11 @@ func stepLeader(r *raft, m pb.Message) error {
1517
1521
// to respond to pending read index requests
1518
1522
releasePendingReadIndexMessages (r )
1519
1523
r .bcastAppend ()
1520
- } else if oldPaused {
1521
- // If we were paused before, this node may be missing the
1522
- // latest commit index, so send it.
1524
+ } else if r .id != m .From && pr .CanBumpCommit (r .raftLog .committed ) {
1525
+ // This node may be missing the latest commit index, so send it.
1526
+ // NB: this is not strictly necessary because the periodic heartbeat
1527
+ // messages deliver commit indices too. However, a message sent now
1528
+ // may arrive earlier than the next heartbeat fires.
1523
1529
r .sendAppend (m .From )
1524
1530
}
1525
1531
// We've updated flow control information above, which may
0 commit comments