Skip to content

fix: infer log rotation start index from oldest file on startup#18789

Open
glyh wants to merge 7 commits intocompatiblefrom
lyh/proper-infer-of-log-rotation-index
Open

fix: infer log rotation start index from oldest file on startup#18789
glyh wants to merge 7 commits intocompatiblefrom
lyh/proper-infer-of-log-rotation-index

Conversation

@glyh
Copy link
Copy Markdown
Member

@glyh glyh commented Apr 20, 2026

This PR fixes log rotation resume behavior for Dumb_logrotate.

Before this change, after daemon restart rotation always resumed at index .0, which could overwrite newer rotated logs first.

Now startup infers the next rotation index by scanning existing rotated files (<log>.0..N) and selecting the oldest file (or the first missing slot). Rotation remains round-robin; we only changed the starting point after restart.

Also included:

  • changelog entry: changes/18789.md
  • new test coverage: src/lib/logger/test/logger_test.ml (resumes rotation from oldest log)

Validation:

  • dune test src/lib/logger/ passes (2 tests).

Instead of always starting curr_index at 0, scan existing rotated log
files and pick the oldest (by mtime) or first empty slot. This ensures
round-robin overwrites the oldest log rather than blindly starting from
index 0 on each restart.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
glyh and others added 2 commits April 20, 2026 23:20
@glyh glyh force-pushed the lyh/proper-infer-of-log-rotation-index branch from 7ac008e to 70adba0 Compare April 20, 2026 15:20
@glyh
Copy link
Copy Markdown
Member Author

glyh commented Apr 20, 2026

!ci-build-me

@glyh glyh requested a review from georgeee April 20, 2026 15:20
@glyh glyh marked this pull request as ready for review April 20, 2026 15:22
@glyh glyh added the bugfix label Apr 21, 2026
georgeee and others added 3 commits April 21, 2026 12:35
Replace access+stat with a single Option.try_with wrapping stat,
eliminating the race window where a file could disappear between
the existence check and the mtime read.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace imperative for loop and usage of special float constants
with List.init to build mtime option list, List.findi to locate the
first empty slot, and List.min_elt to find the oldest existing file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use Fun.protect instead of try/with for guaranteed temp dir removal
- Extract with_temp_dir helper to avoid duplicating cleanup code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@georgeee
Copy link
Copy Markdown
Member

!ci-build-me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

2 participants