Skip to content

Conversation

@xe-nvdk
Copy link
Member

@xe-nvdk xe-nvdk commented Dec 18, 2025

Previously, if segment deletion failed partway through (e.g., disk error), some segments would be deleted but an error would be returned. This could leave the system in an inconsistent state where some segments were gone but the log still referenced them.

This fix implements a mark-then-delete approach:

  1. Mark all segments as deleted first (removes them from read path)
  2. Then attempt to delete the actual files
  3. If file deletion fails, segments are still marked deleted
  4. Remaining files can be cleaned up on next cleanup cycle

Changes:

  • Add deleted flag to segment struct
  • Add MarkDeleted() and IsDeleted() methods to segment
  • Add deleteSegments() helper to deleteCleaner that implements mark-then-delete pattern
  • Refactor applyMessagesLimit, applyBytesLimit, and applyAgeLimit to use the new helper
  • Continue deleting remaining segments even if one fails
  • Add tests for mark-then-delete behavior

Fixes the TODO comments at lines 107-108, 145-146, and 173-175 in delete_cleaner.go.

Previously, if segment deletion failed partway through (e.g., disk error),
some segments would be deleted but an error would be returned. This could
leave the system in an inconsistent state where some segments were gone
but the log still referenced them.

This fix implements a mark-then-delete approach:
1. Mark all segments as deleted first (removes them from read path)
2. Then attempt to delete the actual files
3. If file deletion fails, segments are still marked deleted
4. Remaining files can be cleaned up on next cleanup cycle

Changes:
- Add `deleted` flag to segment struct
- Add `MarkDeleted()` and `IsDeleted()` methods to segment
- Add `deleteSegments()` helper to deleteCleaner that implements
  mark-then-delete pattern
- Refactor `applyMessagesLimit`, `applyBytesLimit`, and `applyAgeLimit`
  to use the new helper
- Continue deleting remaining segments even if one fails
- Add tests for mark-then-delete behavior

Fixes the TODO comments at lines 107-108, 145-146, and 173-175 in
delete_cleaner.go.
@xe-nvdk xe-nvdk merged commit 0e7ab3b into master Dec 18, 2025
1 check passed
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.

2 participants