Skip to content

[#1770] Handle backup catalog scan failures - #1771

Open
Shgit29 wants to merge 1 commit into
pgmoneta:mainfrom
Shgit29:fix/catalog-scan-errors
Open

Shgit29 wants to merge 1 commit into
pgmoneta:mainfrom
Shgit29:fix/catalog-scan-errors

Conversation

@Shgit29

@Shgit29 Shgit29 commented Nov 30, 2026

Copy link
Copy Markdown

Fixes #1770.

A failed catalog scan does not establish that there are no backups. Treating it as an empty catalog lets WAL cleanup proceed without knowing which WAL existing backups still need. Cleanup should stop on that error; a successfully scanned empty catalog should retain its existing behavior.

Validation against upstream 9a83b075:

  • Fresh upstream and feature Debug builds passed.
  • All three new catalog tests fail against the unchanged upstream library and pass against the fixed library, including preservation of a synthetic WAL file after an unreadable-catalog scan.
  • Existing delete_wal (5 tests) and backup_identifier (4 tests) pass on both versions using isolated private-configuration fixtures.
  • The new catalog module passes with ASan/UBSan and leak detection enabled. Formatting and diff checks pass.

These are isolated filesystem/function-level tests; the full PostgreSQL integration suite was not run. No production backups or real PostgreSQL WAL were used. The changes have been personally understood and tested before submission.

@ecleon26

ecleon26 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

add yourself in Authors @Shgit29

@ecleon26
ecleon26 self-requested a review December 1, 2026 06:40
Comment thread src/libpgmoneta/info.c
*backups = NULL;

pgmoneta_get_directories(directory, &number_of_dirs, &dirs);
if (pgmoneta_get_directories(directory, &number_of_dirs, &dirs))

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.

This fails for a server that doesn't have a backup yet. Something like

if (!pgmoneta_exists(directory))
{
return 0;
}

Comment thread test/testcases/test_delete_wal.c Outdated

backup_dir = pgmoneta_get_server_backup(PRIMARY_SERVER);
MCTF_ASSERT_PTR_NONNULL(backup_dir, cleanup);
MCTF_ASSERT_INT_EQ(pgmoneta_mkdir(backup_dir), 0, cleanup);

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. The test was correct - no backup directory means no backups

Comment thread test/testcases/test_info_catalog.c Outdated
Comment on lines +55 to +56
MCTF_ASSERT_INT_EQ(pgmoneta_load_infos(missing, &count, &backups), 1, cleanup);
MCTF_ASSERT_INT_EQ(count, 0, cleanup);

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.

Should be 0

@ecleon26

ecleon26 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

@Shgit29 A missing backup directory isn't an error, it is created by the first backup. With this change a server without backups fails list-backup, verify, keep, delete and so on

Only fail when the directory exists and can't be read

@Shgit29
Shgit29 force-pushed the fix/catalog-scan-errors branch from 1b89851 to e78caa6 Compare December 1, 2026 15:58
@Shgit29

Shgit29 commented Dec 1, 2026 •

Copy link
Copy Markdown
Author

@ecleon26 Thanks for clarifying. I overlooked that the backup directory is only created during the first backup.

I've updated the implementation to distinguish a missing directory from an actual scan failure, reverted the changes to the original WAL test, corrected the missing-directory assertion, and updated AUTHORS and the acknowledgement file.

All 18 relevant test cases pass.

@Shgit29
Shgit29 requested a review from ecleon26 December 1, 2026 16:07
@ecleon26

ecleon26 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

@Shgit29 Please, rebase

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.

Backup catalog scan failures are incorrectly treated as an empty catalog

2 participants