fix: delete idx file before txn to prevent dangling idx on crash#920
Merged
mattisonchao merged 1 commit intomainfrom Feb 27, 2026
Merged
fix: delete idx file before txn to prevent dangling idx on crash#920mattisonchao merged 1 commit intomainfrom
mattisonchao merged 1 commit intomainfrom
Conversation
When deleting WAL segments, the txn file is used by listAllSegments() to discover segments on restart. By deleting the idx file first, a crash between the two deletions will still allow the segment to be rediscovered and cleaned up on the next trim pass. Previously the order was txn-first, idx-second, which could leave a permanently dangling idx file if a crash occurred mid-deletion. Closes #618 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
readOnlySegment.Delete()andreadWriteSegment.Delete()to remove the.idxfile before the.txnfilelistAllSegments()discovers segments by scanning for.txnfiles, so.txnmust be the last file deleted — if a crash occurs after.idxis removed but before.txn, the segment will be rediscovered on restart and cleaned up on the next trim pass.txnfirst,.idxsecond) could leave a permanently dangling.idxfile that would never be cleaned upCloses #618
Test plan