Repository navigation
Make a decision to skip backup of the target RMV table based on snapshot - #103384
Conversation
`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
|
Workflow [PR], commit [cfdb6aa] Summary: ✅ AI ReviewSummaryThis 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
ClickHouse Rules
Final Verdict
|
There was a problem hiding this comment.
Probably we could avoid getting any storages from DatabaseCatalog at this point and always use snapshot.
There was a problem hiding this comment.
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);
}
}
There was a problem hiding this comment.
Yes, this one I missed.
|
|
||
| table_infos.clear(); | ||
|
|
||
| /// Collect target tables of refreshable materialized views that use the REPLACE |
There was a problem hiding this comment.
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.
This reverts commit 154397c.
LLVM Coverage Report
Changed lines: 84.62% (33/39) · Uncovered code |
Cherry pick #103384 to 26.3: Make a decision to skip backup of the target RMV table based on snapshot
…t RMV table based on snapshot
Cherry pick #103384 to 26.4: Make a decision to skip backup of the target RMV table based on snapshot
…t RMV table based on snapshot
Backport #103384 to 26.3: Make a decision to skip backup of the target RMV table based on snapshot
Backport #103384 to 26.4: Make a decision to skip backup of the target RMV table based on snapshot
… the target RMV table based on snapshot
…3384 Backport ClickHouse#103384 to 26.4: Make a decision to skip backup of the target RMV table based on snapshot
BackupEntriesCollector::shouldBackupTableDataused to rely onDatabaseCatalog::instance().getReferentialDependentsto 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
TablesDependencyGraphingatherTablesMetadataover the tables being backed up (same pattern asDatabaseReplicated) and pass it throughshouldBackupTableDatatoBackupUtils::isTargetForReplaceRefreshableMaterializedView, which now uses the graph'sgetDependentsinstead of the global catalog.Without this change, this #93658 seems useless.
Changelog category (leave one):
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
Version info
26.4.3.7,26.3.11.8