Commit f64d156
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 is always true if the term of last entry in the
log matches the leader team, otherwise this guarantee is established
when the first MsgApp append message from the leader 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 f64d156
2 files changed
+31
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
378 | 384 | | |
379 | 385 | | |
380 | 386 | | |
| |||
763 | 769 | | |
764 | 770 | | |
765 | 771 | | |
| 772 | + | |
766 | 773 | | |
767 | 774 | | |
768 | 775 | | |
| |||
866 | 873 | | |
867 | 874 | | |
868 | 875 | | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
869 | 880 | | |
870 | 881 | | |
871 | 882 | | |
| |||
908 | 919 | | |
909 | 920 | | |
910 | 921 | | |
| 922 | + | |
911 | 923 | | |
912 | 924 | | |
913 | 925 | | |
| |||
1735 | 1747 | | |
1736 | 1748 | | |
1737 | 1749 | | |
| 1750 | + | |
1738 | 1751 | | |
1739 | 1752 | | |
1740 | 1753 | | |
| |||
1770 | 1783 | | |
1771 | 1784 | | |
1772 | 1785 | | |
1773 | | - | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
1774 | 1791 | | |
1775 | 1792 | | |
1776 | 1793 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1332 | 1332 | | |
1333 | 1333 | | |
1334 | 1334 | | |
1335 | | - | |
1336 | | - | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
1337 | 1338 | | |
1338 | | - | |
1339 | | - | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
1340 | 1348 | | |
1341 | 1349 | | |
1342 | 1350 | | |
1343 | 1351 | | |
1344 | | - | |
| 1352 | + | |
1345 | 1353 | | |
1346 | 1354 | | |
1347 | 1355 | | |
| |||
0 commit comments