Skip to content

Sync the replicas before the local backup in test_async_backups_to_same_destination - #131921

Merged
fm4v merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test-async-backups-to-same-destination
Nov 19, 2026
Merged

fm4v merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test-async-backups-to-same-destination

Conversation

@groeneai

@groeneai groeneai commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #89141

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix flaky test test_backup_restore_on_cluster/test.py::test_async_backups_to_same_destination.

Description

test_async_backups_to_same_destination[http-False] fails with assert '' == '1\n' after the final RESTORE in Integration tests (arm_binary, 2/5) (1, 2; 17 times on 16 PRs and master since 2025-10). The old issue about it was closed as stale without a fix.

The http-False variant runs BACKUP TABLE tbl TO <dest> ASYNC without ON CLUSTER on node1 and then on node2, right after the INSERT on node1. Such a backup contains only the parts of the local replica, and only one of the two backups gets the destination. In both failing runs node2's backup won and collected the table (num backup entries=1, metadata only) before node2 had fetched all_0_0_0, so the restored table was empty.

The test now runs SYSTEM SYNC REPLICA ON CLUSTER 'cluster' tbl after the insert, as the other tests of this file do. The two backups still race for the destination, and the exactly-one-succeeds and restore checks are unchanged.

Validation with the master debug build: with fetches stopped on node2, node2's backup has one entry and restores an empty table (3/3); running the new line before node2's backup gives 12 entries and restores 1 (3/3). The fixed test passed 50 times per variant (150/150), and the whole test.py passed (49/49).


Workflow [PR]
Sync PR [sync-upstream/pr/131921]

Version info

  • Merged into: 26.11.1.2810-master (included in 26.11 and later)

…me_destination

The `http-False` variant of `test_async_backups_to_same_destination` runs
`BACKUP TABLE tbl TO <dest> ASYNC` without `ON CLUSTER` on node1 and node2
right after the `INSERT` on node1. Such a backup contains only the parts of
the local replica, and only one of the two backups to the same destination
succeeds. When node2's backup won before node2 had fetched `all_0_0_0`, the
successful backup held only the table metadata (`num backup entries=1` in
node2's log), `RESTORE` on node1 created an empty table, and the final check
failed with `assert '' == '1\n'`.

Run `SYSTEM SYNC REPLICA ON CLUSTER 'cluster' tbl` after the insert, as the
other tests of this file do. The two backups still race for the destination.

CI reports:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126329&sha=a56d34954af566916a3978497a004b351f6e2642&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%202%2F5%29
(ClickHouse#126329)
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109453&sha=806162ffe23baed3bee142174285056d8247ab1d&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%202%2F5%29
(ClickHouse#109453)

Related: ClickHouse#89141

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review of the diff (0 findings).

No findings to adjudicate. The review checked that a BACKUP without ON CLUSTER collects only the local replica's visible parts (StorageReplicatedMergeTree::backupData), that SYSTEM SYNC REPLICA pulls the replication log before waiting for the queue (StorageReplicatedMergeTree::waitForProcessingQueue), and that no other non-ON CLUSTER backup in this module runs on a replica that lacks the data.

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261116-073001

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @pamarcos, could you review this? test_async_backups_to_same_destination[http-False] sometimes restores an empty table because node2's local BACKUP (no ON CLUSTER) can win the destination before node2 fetched the inserted part; the test now runs SYSTEM SYNC REPLICA ON CLUSTER after the insert.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With SYSTEM STOP FETCHES tbl on node2, an INSERT on node1 and node2's local BACKUP taking the destination first, RESTORE on node1 returns '' (the CI assertion), 3/3; node2's log shows num backup entries=1.
b Root cause explained? A BACKUP without ON CLUSTER contains only the parts of the local replica. Only one of the two backups to one destination succeeds; when it is node2's and node2 has not fetched all_0_0_0 yet, the backup holds only the metadata, so the restored table is empty. Seen in the server logs of both failing CI jobs.
c Fix matches root cause? Yes. SYSTEM SYNC REPLICA ON CLUSTER 'cluster' tbl after the insert makes both replicas have the part before the backups start (the idiom this file uses at 25+ sites). No widened assertion, no sleep, no tag.
d Test intent preserved / new tests added? Preserved: both ASYNC backups still race for the same destination, and exactly-one-succeeds and the restored content are still asserted for all three variants. Test-only fix, so no new test.
e Both directions demonstrated? Without the line: empty restore 3/3 (above). Same trigger, then the new line before node2's backup: 12 entries, restore 1, 3/3. Fixed test: 150/150 (50 per variant); whole test.py: 49/49.
f Fix is general across code paths? The other non-ON CLUSTER backups in this module run on the node that holds the data or back up system.named_collections; test_backup_restore_new is single-instance. Only this function had the gap.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test synchronization fix). The line runs for all three variants (native/http, with/without ON CLUSTER).
h Backward compatible? (maintainer-approved exception only) N/A (test-only change, no settings or formats).
i Invariants and contracts preserved? The test's contract (one of two concurrent backups succeeds and restores the inserted row) holds whichever node wins; the server code is unchanged.

Session id: cron:clickhouse-impl-slot-6:20261116-065400

@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d3e004a]

Summary: ✅


AI Review

Summary

The PR synchronizes both replicas before test_async_backups_to_same_destination starts competing backups, preventing node2's successful local backup from omitting the inserted row. The backup race, exactly-one-success checks, and restored-data assertion remain intact. No actionable findings. The author's deterministic reproduction and repeated validation support this focused test fix; integration tests were not rerun during this review.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). can be tested Allows running workflows for external contributors labels Nov 16, 2026

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@fm4v
fm4v added this pull request to the merge queue Nov 18, 2026
Merged via the queue into ClickHouse:master with commit d9c002e Nov 19, 2026
570 of 572 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-backup Backup/restore infrastructure and backup formats. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-backup Backup/restore infrastructure and backup formats. pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants