Fix WAL handling on consensus snapshot#7577
Merged
Conversation
0dd1629 to
1cf5b47
Compare
16403e4 to
0f274c5
Compare
ffuugoo
reviewed
Nov 21, 2025
KShivendu
reviewed
Nov 21, 2025
ffuugoo
approved these changes
Nov 24, 2025
3 tasks
timvisee
added a commit
that referenced
this pull request
Nov 25, 2025
* After clearing WAL, flush segment * Add debug log when WAL is cleared * Clear WAL on consensus snapshot after writing state, truncate on start * Apply consensus snapshot offset * Fix off by one error * Tweak debug assertion message * Change WAL reconciliation condition, and fully clear WAL in this case * Add debug assertion to prove Raft index and snapshot index are equal * Add documentation to resolve bot nit * Return error on WAL clear failure * Fix typo * Remove unused truncate functions
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix how we handle WAL clearing when we apply a consensus snapshot.
The main problem this tries to solve is the following: in this function, we clear the WAL before we persist the new consensus state from the snapshot. If we crash in between, we only clear the WAL while keeping old consensus state. This will cause a crash loop on startup.
To fix the problem we flip the order. We now clear the WAL after persisting the new consensus state. On startup we truncate any extra entries from the WAL if we failed to clear it.
Needs some more testing before we apply this change.
This needs fixes in WAL crate here: qdrant/wal#99
Applying qdrant/wal#99 also fixes WAL CRC issues that pop up like this log line:
Testing
Testing this change is not easy, and I don't see how I can write a nice automated test for it. I tested this PR including qdrant/wal#99.
What I did is this:
QDRANT__CLUSTER__CONSENSUS__COMPACT_WAL_ENTRIES=5to enable aggressive consensus WAL compactionDELETE /cluster/peer/1at least 5 times to trigger WAL compactionqdrant/lib/storage/src/content_manager/consensus_manager.rs
Lines 557 to 563 in 1b6e525
b. or with this PR: add panic in between these two statements to simulate crash at the right time:
qdrant/lib/storage/src/content_manager/consensus_manager.rs
Lines 581 to 593 in 0f274c5
b. or after this PR: start and continue fine, and notice a log line like this:
Tasks
waldependency: Bumpwaldependency to fix flush problems #7587All Submissions:
devbranch. Did you create your branch fromdev?Changes to Core Features: