Skip to content

[#1772] Fix weekly retention across daylight-saving changes - #1773

Open
Shgit29 wants to merge 1 commit into
pgmoneta:mainfrom
Shgit29:investigate/functional-review
Open

Shgit29 wants to merge 1 commit into
pgmoneta:mainfrom
Shgit29:investigate/functional-review

Conversation

@Shgit29

@Shgit29 Shgit29 commented Nov 30, 2026

Copy link
Copy Markdown

Fixes #1772.

Weekly retention promises Monday backups, but fixed 86400-second steps can cross local midnight when a daylight-saving offset changes. For US Eastern at 2025-03-10 00:30 with two retained weeks, the previous target becomes February 24 instead of March 3. This can leave the intended Monday backup eligible for deletion even after #1506's accumulated-offset fix.

Calendar normalization at noon avoids the midnight ambiguity, while tm_isdst = -1 lets libc determine the target date's offset. Only the resulting calendar date is matched; noon is not a backup-time cutoff. Daily retention and the latest-valid-backup safeguard remain unchanged.

The tests include the private marker's source with a test-local clock and renamed workflow factory. This avoids adding a public API solely for testing or interposing the production clock.

Validation against upstream 9a83b075:

  • Existing nine-case harness: 5/9 pass before, 9/9 after.
  • MCTF regression module: 9/13 pass before, 13/13 after, covering DST, UTC, month/year boundaries, multiple weeks, daily cutoff and latest-valid protection.
  • Full Debug build, clang-format 21 and diff checks pass; the final module run also passes with ASan/UBSan and leak detection enabled.

These are isolated function-level tests using synthetic backup metadata and a controlled clock, not a full PostgreSQL integration run. The upstream baseline uses unchanged source with the test clock shim and the clean upstream library. No real backups were deleted. The changes have been personally understood and tested before submission.

@ecleon26
ecleon26 self-requested a review December 1, 2026 06:33

@ecleon26 ecleon26 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Shgit29 The fix in wf_retention.c looks ok.

Don't #include a .c file in the test suite, and don't #define time. Either drop test_retention_calendar.c, or expose what you need through a proper function in a header.

Rebase, and squash

Comment on lines +50 to +55
/* Exercise the private marker with a controlled clock without adding a public
* API or interposing time() for other tests or the shared library. */
#define time retention_test_time
#define pgmoneta_create_retention retention_test_create_workflow
#include "../../src/libpgmoneta/wf_retention.c"
#undef pgmoneta_create_retention

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove. We don't include source files from src/ in the tests

@Shgit29

Shgit29 commented Dec 2, 2026

Copy link
Copy Markdown
Author

Alright, I am fixing it.

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 backup retention selects incorrect dates across daylight-saving transitions

2 participants