Commit 2584c41
committed
raft: advance commit index safely
This change makes the commit index advancement in handleHeartbeat safe.
Previously, a follower would attempt to update the commit index to
whichever was sent in the MsgHeartbeat message. Out-of-bound indices
would crash the node.
It is always safe to advance a commit index if the follower's log is "in
sync" with the leader, i.e. when its log is guaranteed to be a prefix of
the leader's log. This becomes true when the first MsgApp append message
succeeds.
At the moment, the leader will never send a commit index that exceeds
the follower's log size. However, this may change in future. This change
is a defence-in-depth.
Signed-off-by: Pavel Kalinnikov <[email protected]>1 parent 026484c commit 2584c41
1 file changed
+13
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
378 | 383 | | |
379 | 384 | | |
380 | 385 | | |
| |||
763 | 768 | | |
764 | 769 | | |
765 | 770 | | |
| 771 | + | |
766 | 772 | | |
767 | 773 | | |
768 | 774 | | |
| |||
908 | 914 | | |
909 | 915 | | |
910 | 916 | | |
| 917 | + | |
911 | 918 | | |
912 | 919 | | |
913 | 920 | | |
| |||
1735 | 1742 | | |
1736 | 1743 | | |
1737 | 1744 | | |
| 1745 | + | |
1738 | 1746 | | |
1739 | 1747 | | |
1740 | 1748 | | |
| |||
1770 | 1778 | | |
1771 | 1779 | | |
1772 | 1780 | | |
1773 | | - | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
1774 | 1786 | | |
1775 | 1787 | | |
1776 | 1788 | | |
| |||
0 commit comments