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.
Fixes #30102
The deleter previously assumed that every entry in log_root was a valid segment directory. Stray files or broken symlinks would accumulate and prevent cleanup from progressing correctly. This change hardens the deletion logic so that unexpected non-directory entries are removed first, and failures are logged rather than crashing the thread.
Changes
Delete non-directory items in log_root before processing segment directories
Safely handle failures in os.remove, os.listdir, and shutil.rmtree
Preserve normal semantics:
skip locked segments
skip preserved segments
delete earliest eligible directory
Verification
A new test, test_delete_mixed_contents, creates a realistic mixed-state log_root containing:
regular files with segment-style names
random stray logs
broken symlinks
a valid symlink pointing to a real directory tree
nested directories containing files
a real segment directory
Before this change, the test failed due to skipped cleanup and unhandled errors.
After this change, the test passes and cleanup proceeds correctly without crashes.