[log] Follower fetch offset need truncate to leaderEndOffsetSnapshot if we found duplicated batch or out of sequence batch #731
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Linked issue: close #704
This pr is aims to address the issue where a
DuplicateSequenceExceptionorOutOfOrderSequenceExceptionmay occur when the follower fetches data from the leader for sync. The root cause of this problem lies in our current approach of updating thefollower's HW (HighWatermark)before updating theleader's HW. This update mechanism may lead to the issues illustrated in the diagram below:As in case 1, for example. In this scenario, when the leader, follower1, and follower2 are all offline, follower1 has written batch1 (WriterId=1, batchSequence=10), but the leader did not write this batch. When the tabletServer recover, follower2 is elected as the new leader. At this point, another writer, such as writer2 or writer3, quickly writes new batches and closes the gap with follower1. If the client then writes batch1, when follower1 pulls the updates, a
DuplicateSequenceExceptionwill occur.To fix this error, we introduce a variable named
LeaderEndOffsetSnapshotto remember the endOffset snapshot when the replica become leader. If follower encounterDuplicateSequenceException, it need to truncate to leader'sLeaderEndOffsetSnapshot, by this way, it can be continue to fetch data from leader.Brief change log
Tests
API and Format
Documentation