Skip to content

Make a decision to skip backup of the target RMV table based on snapshot - #103384

Merged
alexey-milovidov merged 5 commits into
masterfrom
backup-rmv-target-dep-graph
Apr 26, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
backup-rmv-target-dep-graph

Conversation

@nikitamikhaylov

@nikitamikhaylov nikitamikhaylov commented Apr 22, 2026 •

Copy link
Copy Markdown
Member

BackupEntriesCollector::shouldBackupTableData used to rely on DatabaseCatalog::instance().getReferentialDependents to decide whether a table is a target of a refreshable materialized view. That lookup is global and those tables could be gone (EXCHANGE query from the RMV kicks in for example).

Build a TablesDependencyGraph in gatherTablesMetadata over the tables being backed up (same pattern as DatabaseReplicated) and pass it through shouldBackupTableData to
BackupUtils::isTargetForReplaceRefreshableMaterializedView, which now uses the graph's getDependents instead of the global catalog.

Without this change, this #93658 seems useless.

Changelog category (leave one):

  • Improvement

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

Improve the resilience of backups when Refreshable Materialized Views are constantly refreshed by making decisions based on the snapshotted tables' state rather than a global one.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Backported to: 26.4.3.7, 26.3.11.8

`BackupEntriesCollector::shouldBackupTableData` used to rely on
`DatabaseCatalog::getReferentialDependents` to decide whether a table is
a target of a refreshable materialized view. That lookup is global, so a
table could be marked as an RMV target (and have its data skipped) even
when the RMV itself was not part of the backup.

Build a `TablesDependencyGraph` in `gatherTablesMetadata` over the
tables being backed up (same pattern as `DatabaseReplicated`) and pass
it through `shouldBackupTableData` to
`BackupUtils::isTargetForReplaceRefreshableMaterializedView`, which now
uses the graph's `getDependents` instead of the global catalog.

Made-with: Cursor
@clickhouse-gh

clickhouse-gh Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cfdb6aa]

Summary: ✅


AI Review

Summary

This PR correctly scopes refreshable materialized-view target detection to the backup snapshot instead of querying global catalog state, which addresses the race described in the PR motivation. The remaining gap is coverage: the change needs a regression test that exercises the snapshot-scoping scenario to prevent future regressions.

Tests
  • ⚠️ Add a regression test for the snapshot-scoping case (e.g., refreshable MV with REPLACE refresh strategy, EXCHANGE/table churn during refresh, and backup scope where MV/target presence differs from global catalog at backup time). The test should verify the skip-data decision is made from the collected snapshot, not current global catalog state.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: add the targeted regression test for snapshot-scoped RMV target handling in backup selection logic.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Apr 22, 2026
@vitlibar vitlibar self-assigned this Apr 22, 2026
Comment thread src/Backups/BackupUtils.cpp Outdated

@vitlibar vitlibar Apr 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably we could avoid getting any storages from DatabaseCatalog at this point and always use snapshot.

@vitlibar vitlibar Apr 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Like this:

void gatherTablesMetadata()
{
    for (...)
    {
           ...
           res_table_info.data_path_in_backup = data_path_in_backup;

           if (const auto * mv = typeid_cast<const StorageMaterializedView *>(storage.get()))
                if (mv->isRefreshable() && !mv->isAppendRefreshStrategy())
                    rmv_replace_target_ids.insert(mv->getTargetTableId());
    }

    for (auto & [table_name, table_info] : table_infos)
    {
        table_info.should_backup_data = shouldBackupTableData(
            table_name, table_info.storage, rmv_replace_target_ids);
    }
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, this one I missed.


table_infos.clear();

/// Collect target tables of refreshable materialized views that use the REPLACE

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.

Could we add a regression test for the snapshot-scoping scenario mentioned in the PR description (for example, when RMV refresh uses EXCHANGE and the RMV itself is not part of the backup scope)?

This logic now decides RMV target skipping from a local snapshot, but the PR currently has no test changes. A targeted integration test here would prevent us from regressing back to global-catalog behavior.

Comment thread src/Common/remapExecutable.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.30% 76.20% -0.10%

Changed lines: 84.62% (33/39) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 26, 2026
Merged via the queue into master with commit c7a219f Apr 26, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the backup-rmv-target-dep-graph branch April 26, 2026 11:43
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 26, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 27, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 7, 2026
@nikitamikhaylov nikitamikhaylov added pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels May 8, 2026
robot-clickhouse added a commit that referenced this pull request May 8, 2026
Cherry pick #103384 to 26.3: Make a decision to skip backup of the target RMV table based on snapshot
robot-clickhouse added a commit that referenced this pull request May 8, 2026
robot-clickhouse added a commit that referenced this pull request May 8, 2026
Cherry pick #103384 to 26.4: Make a decision to skip backup of the target RMV table based on snapshot
robot-clickhouse added a commit that referenced this pull request May 8, 2026
fm4v added a commit that referenced this pull request May 11, 2026
Backport #103384 to 26.3: Make a decision to skip backup of the target RMV table based on snapshot
fm4v added a commit that referenced this pull request May 11, 2026
Backport #103384 to 26.4: Make a decision to skip backup of the target RMV table based on snapshot
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 11, 2026
@jkartseva jkartseva added v26.4-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Jun 11, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 11, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…3384

Backport ClickHouse#103384 to 26.4: Make a decision to skip backup of the target RMV table based on snapshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport v26.2-must-backport v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants