fix: remove recycled log files leaked by unclean shutdown - #408
Conversation
`purge_to` keeps the recycled append files under their original `.raftlog` name on disk (rename only happens in `SinglePipe::drop`). If the process exits without running `Drop` (SIGKILL / OOM / panic=abort), those files are re-scanned as regular append files on restart and form a hole before the active range. The hole check removed them from the in-memory list but never deleted the physical files, so they leaked on disk forever and the leak accumulated across unclean restarts. Now the invalid files drained by the hole check are also deleted from disk. Recycled (reserved) files are still skipped, matching the existing metadata-cleanup behavior. Signed-off-by: waterWang <waterWang@users.noreply.github.com>
|
Hi @waterWang. Thanks for your PR. I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Welcome @waterWang! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe append-file scan now deletes leaked non-recycled files that precede sequence holes. A new engine test simulates an unclean shutdown with recycled logs and verifies that restart removes the leaked files. ChangesRecycled log cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: 🔵 Low · up to The PR removes abandoned log files during restart, but malformed or duplicate filenames could make cleanup target the wrong canonical path, and filesystem deletion failures can leave stale files while startup continues. The change is mergeable with explicit owner awareness of these bounded recovery risks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Linked Issues checkExplanation The changes address issue ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Connor1996, LykxSassinator The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
Thx |
|
@waterWang: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
| // range, but only the metadata (not the log file) was cleaned before. | ||
| let invalid_files = files.drain(..invalid_idx).collect::<Vec<_>>(); | ||
| if !is_recycled_file { | ||
| // Collect the paths first so the file handles (and thus the files) |
There was a problem hiding this comment.
Why skip recycled files here? Don't .reserved files leak the same way?
|
@Manphil: adding LGTM is restricted to approvers and reviewers in OWNERS files. DetailsIn response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Fix #407.
Problem
When a
raft-engineprocess exits without runningSinglePipe::drop(SIGKILL, OOM kill,panic=abort), recycled append files keep their original.raftlogname on disk (purge_tointentionally does not rename them; only shutdown renames them to.raftlog.reserved). On restart they are re-scanned as regular append files, the hole check drops them from the file list (files.drain(..invalid_idx)), but the physical files are never deleted — they become unreachable and leak on disk forever, accumulating across unclean restarts.Fix
When the hole check drains the invalid file prefix, also delete the corresponding physical log files (for the append/rewrite queues). Recycled/reserved files keep the existing no-delete behavior. Handles are closed before deletion so the fix also works on Windows.
Test
test_remove_recycled_files_left_by_unclean_shutdown(insrc/engine.rs): writes data, purges to populate the recycle pool, performs a clean reopen, then simulates an unclean shutdown by renaming the.raftlog.reservedfiles back to plain.raftlogfiles (reproducing the leaked on-disk state). After reopening, it asserts that every plain.raftlogfile on disk belongs to the active span — i.e. no leaked files remain.Summary by CodeRabbit