Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit index may be smaller than snapshot index #1092

Closed
Brokenice0415 opened this issue Mar 21, 2024 · 1 comment
Closed

Commit index may be smaller than snapshot index #1092

Brokenice0415 opened this issue Mar 21, 2024 · 1 comment

Comments

@Brokenice0415
Copy link

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
@killme2008
Copy link
Contributor

@Brokenice0415 Looks possible, but it doesn't seem to have any substantial impact, as it will eventually catch up.

fengjiachun added a commit that referenced this issue Jun 17, 2024
* fix: readIndex may return wrong value when single node group resetarts, #1049

* fix: init lastCommittedIndex in ballot box with last snapshot index if exists, #1092

* chore: format code

* chore: style

* chore: update jraft-extension/java-log-storage-impl/src/main/java/com/alipay/sofa/jraft/storage/HybridLogStorage.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: apply suggestion

Co-authored-by: Jeremyhi <[email protected]>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Jeremyhi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants