Skip to content

fix: delete idx file before txn to prevent dangling idx on crash#920

Merged
mattisonchao merged 1 commit intomainfrom
fix/delete-idx-before-txn
Feb 27, 2026
Merged

fix: delete idx file before txn to prevent dangling idx on crash#920
mattisonchao merged 1 commit intomainfrom
fix/delete-idx-before-txn

Conversation

@mattisonchao
Copy link
Copy Markdown
Member

@mattisonchao mattisonchao commented Feb 27, 2026

Summary

  • Swap deletion order in readOnlySegment.Delete() and readWriteSegment.Delete() to remove the .idx file before the .txn file
  • listAllSegments() discovers segments by scanning for .txn files, so .txn must be the last file deleted — if a crash occurs after .idx is removed but before .txn, the segment will be rediscovered on restart and cleaned up on the next trim pass
  • The previous order (.txn first, .idx second) could leave a permanently dangling .idx file that would never be cleaned up

Closes #618

Test plan

  • Existing WAL tests pass
  • Verify no dangling idx files after crash during segment trimming

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>
@mattisonchao mattisonchao self-assigned this Feb 27, 2026
@mattisonchao mattisonchao merged commit a610fa8 into main Feb 27, 2026
9 checks passed
@mattisonchao mattisonchao deleted the fix/delete-idx-before-txn branch February 27, 2026 07:04
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.

Bug: There may be dangling idx file when trim segments failed

1 participant