Commit index may be smaller than snapshot index
Brokenice0415 opened this issue · 1 comments
Brokenice0415 commented
Describe the bug
There will be a period of time when commit index may be smaller than snapshot index.
Steps to reproduce
Here is a possible trace.
0 become leader
0 commit = 56
0 send AE {57, 58, 59} to 2
2 reply 0, append {57, 58, 59}, update commit 56
0 add {60}
0 send AE {60} to 2
0 receive 2's reply, update commit 59
0 set snapshot_59
0 crash
2 receive 0, append {60}
2 become leader, add {61}
0 restart, commit reset to 0
2 send AE {61} to 0
0 update commit 56
# now 0's commit index 56 is smaller than snapshot index 59.
Possible solution
Since logs compacted by snapshot must have been committed, we can initialize the lastCommitIndex
in BallotBox
with the snapshot index (if exists) instead of 0.
Environment
- SOFAJRaft version: master branch up to 19ed179
- JVM version (e.g.
java -version
): 17.0.10