Skip to content

Fix weekly retention keeping the wrong weeks - #1506

Merged
Jubilee101 merged 1 commit into
pgmoneta:mainfrom
Pranav-error:fix-weekly-retention-drift
Oct 30, 2026
Merged

Jubilee101 merged 1 commit into
pgmoneta:mainfrom
Pranav-error:fix-weekly-retention-drift

Conversation

@Pranav-error

Copy link
Copy Markdown
Collaborator

Fixes #1505.

Problem

The retention_weeks loop in mark_retention() (src/libpgmoneta/wf_retention.c) computed each week's target Monday by subtracting j weeks from tmp_time, but tmp_time had already been decremented (and wound back to a Monday) by the previous iterations. The offset accumulated 0, 1, 3, 6, 10 … weeks back instead of 0, 1, 2, 3, 4 …, so from the third week onward the code probed the wrong Mondays. Weekly backups the operator intended to keep matched none of those windows and were deleted.

Target Mondays, base = Thu 2026-10-22:

week before after
0 2026-10-19 2026-10-19
1 2026-10-12 2026-10-12
2 2026-09-28 2026-10-05
3 2026-09-07 2026-09-28
4 2026-08-10 2026-09-21
5 2026-07-06 2026-09-14

Fix

Subtract from the stable base t instead of the mutated tmp_time, matching how the retention_months and retention_years loops step from a fixed reference. One line.

The retention_weeks loop in mark_retention() computed each week's target
Monday by subtracting j weeks from tmp_time, but tmp_time had already been
decremented by the previous iterations (and wound back to a Monday). The
offset therefore accumulated (0, 1, 3, 6, 10 ... weeks back) instead of
stepping one week at a time, so from the third week onward the code probed
the wrong Mondays. Weekly backups the operator intended to keep matched none
of those windows and were deleted.

Subtract from the stable base t, matching how the months and years loops
step from a fixed reference.
Copilot AI balanced review requested due to automatic review settings October 23, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Jubilee101

Copy link
Copy Markdown
Member

Yikes, merged, thanks for your contribution~

Yes, retention is very hard to test...

@Jubilee101
Jubilee101 merged commit ec233a8 into pgmoneta:main Oct 30, 2026
10 checks 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.

Weekly retention keeps the wrong weeks (drifts after the second week)

3 participants