Commit eb6bfc6
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 eb6bfc6
3 files changed
+27
-5
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 | | |
| |||
| 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 | + | |
1340 | 1347 | | |
1341 | 1348 | | |
1342 | 1349 | | |
| |||
1345 | 1352 | | |
1346 | 1353 | | |
1347 | 1354 | | |
| 1355 | + | |
| 1356 | + | |
1348 | 1357 | | |
1349 | 1358 | | |
1350 | 1359 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
952 | 952 | | |
953 | 953 | | |
954 | 954 | | |
| 955 | + | |
955 | 956 | | |
956 | 957 | | |
957 | 958 | | |
| |||
0 commit comments