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

Fixed an issue where the old leader's log could not be synced with the new one due to the absence of a previous LogEntry #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arodionov
Copy link

@arodionov arodionov commented Jun 4, 2024

According to the Raft protocol, before a new LogEntry can be added to the follower log, we should check that the previous LogEntry exists and has the same term number as the leader's entry.

If an old leader's log contains a snapshot and only unreplicated entries, the new leader can't verify the previous LogEntry on the old leader, since this entry is already snapshotted and not present in a RaftLog :

LogEntry prevEntry = log.getLogEntry(request.getPreviousLogIndex());

return that prevEntry is null, if prevLogIndex <= snapshotIndex.

As a result, an old leader's log can't be synchronised with a new leader's log.

As a fix, we should add a check if snapshotIndex is large or equal to previousLogIndex, and use the snapshot term in this case.

…e new one due to the absence of a previous LogEntry

If an old leader's log contains a snapshot and only unreplicated entries, it can't be synchronized with a new leader's log.
This happens because the new leader can't verify the previous LogEntry of the old leader since this entry is already snapshotted.
As a fix, we should add a check if `snapshotIndex` is large or equal to `previousLogIndex`, and use snapshot term in this case.
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

Successfully merging this pull request may close these issues.

None yet

1 participant