Repository navigation
Conversation
Adds a table-level setting that, when enabled, makes BACKUP include the table's DDL but skip its data; RESTORE recreates the table empty. Useful for tables whose data can be regenerated from a source table (e.g. materialized-view targets), to reduce backup size. Fixes ClickHouse#111827
|
Workflow [PR], commit [eacd418] Summary: ✅
AI ReviewSummaryThis PR adds Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit eacd418.
Changed lines: Changed C/C++ lines covered: 365/434 (84.10%) · Uncovered code |
|
Asked here: #111827 (comment), hold on... |
- exclude_data_from_backup: table data is skipped during BACKUP, DDL is kept - exclude_from_backup: table is skipped entirely (no DDL, no data) - shouldBackupTableData() now derives the skip decision from the Keeper-snapshotted ASTCreateQuery/settings_changes instead of the live storage object, fixing a race where a lagging DatabaseReplicated replica could upload data despite Keeper already having exclude_data_from_backup=1 - Added integration test coverage for both settings, including a replicated-database test exercising a not-yet-synced replica performing the backup Closes: ClickHouse#111827
|
@alexey-milovidov Pushed commit 8c5b33d with both requested changes:
Test coverage added:
All changes pass locally (manual verification + the Let me know if you'd prefer different naming or scope for |
…ca path The previous version of test_table_in_replicated_database_with_exclude_data_from_backup_not_synced did not actually test what it claimed to: - ALTER TABLE ... MODIFY SETTING on a Replicated database is synchronous by default, so node2 had already applied the setting before the BACKUP ran. - RESTORE DATABASE ... ON CLUSTER without replica_num_in_backup makes each host restore its own (already-correct) replica slice, so asserting on node1 never exercised node2's potentially-stale backup slice. Fixed by: - Freezing node2's DDL worker with the database_replicated_stop_entry_execution failpoint before the ALTER, so node2 genuinely never applies the setting change locally. - Running the ALTER with distributed_ddl_task_timeout=0 so it doesn't wait on the frozen node2. - Restoring explicitly with replica_num_in_backup=2 to inspect node2's (stale-replica) backup slice directly. Addresses AI review bot feedback on commit 8c5b33d.
Round 3 review finding: StorageMaterializedView::backupData() delegates directly to the inner target table's backupData(), completely bypassing shouldBackupTableData() (which only lives in BackupEntriesCollector.cpp's normal table-scan path). This meant setting exclude_data_from_backup or exclude_from_backup on a MaterializedView's hidden .inner.<uuid> table had zero effect on backup. Fix: add an early-return settings check as the first statement in both StorageMergeTree::backupData() and StorageReplicatedMergeTree::backupData() (the two actual entry points StorageMaterializedView delegates to), rather than patching StorageMaterializedView.cpp itself. This is more general: it covers any direct caller of these functions, not just the MaterializedView delegation path. Added new integration test test_exclude_data_from_backup_materialized_view_inner_table: creates a MaterializedView with an implicit .inner_id.<uuid> target, flips exclude_data_from_backup on the inner table directly via ALTER TABLE `.inner_id.<uuid>` MODIFY SETTING, then verifies BACKUP/RESTORE of the outer view genuinely omits the inner data. All 4 tests in the file (3 existing + 1 new) pass locally.
|
@alexey-milovidov The bot's Round 4 review on 9df7287 flagged two issues, and 1. The 9df7287 fix reintroduces the Keeper-snapshot staleness race for delegated A real fix means either (a) collecting inner tables' CREATE queries during 2. Given the scope this has grown to, I'd rather ask than guess: would you prefer I (a) expand this PR to properly fix both issues (snapshot-carrying for delegated Happy to do either — just don't want to guess at the architecture and end up |
|
@jkartseva Since you've picked this up — flagging that this PR is currently The bot's latest review confirms option (a)'s inner-table issue is still Happy to implement either direction — just need a decision before I put |
# Conflicts: # src/Storages/StorageReplicatedMergeTree.cpp
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 48/50 (96.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes55 object files changed (+85.07 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units787 translation units recompiled, 5324 s compile time in total, 787 of them have a recent master baseline. |
|
Both Stress test failures on commit 74fea46 look unrelated to this PR's changes (which only touch Stress test (amd_debug) — Stress test (arm_debug) — Could someone with rerun permissions please re-trigger these two jobs? Happy to investigate further if either reproduces again. |
This reverts commit f54199b.
…backups" This reverts commit 72d0e29, applied manually instead of via git revert: the automatic 3-way merge picked up an overly broad conflict hunk spanning unrelated later tests due to the number of intervening commits touching this file, so the function was removed by exact line-range instead.
backup_entries() uses re.findall() but the import was missing, caught by the style-check ruff job (F821 undefined name 're').
| /// Only the reserved `.inner*` families can be told from the name. This filter is all a database | ||
| /// engine gets, and it is called with a name and nothing else - for a `Replicated` database while | ||
| /// walking the Keeper metadata listing, before any table definition has been read - so the inner | ||
| /// tables which take a definition to recognise are dropped from the result below instead. |
There was a problem hiding this comment.
This "dropped from the result below instead" step never happens for standalone MaterializedPostgreSQL. BackupUtils::isInnerTable() now only matches .inner*, but StorageMaterializedPostgreSQL::createNestedIfNeeded() creates a real <outer_uuid>_nested ReplacingMergeTree. So BACKUP DATABASE default EXCEPT TABLES pg still backs up the hidden nested table as a normal user table, BACKUP DATABASE default EXCEPT DATA FROM TABLE default.pg still uploads its data, and EXCEPT DATA FROM TABLE \_nested`is accepted instead of rejected. Please restore a post-enumeration classification step keyed by the outer table / UUID before selection andcheckTableCanHaveDataExcluded()`.
…table internal" This reverts commit 1459e05.
jkartseva
left a comment
There was a problem hiding this comment.
Almost ready to merge – please clean up and update the PR description.
This reverts commit b9f8450.
…f-scope test
- tests/integration/test_exclude_data_from_backup/test.py: drop unused
'import re' (ruff F401, fixes style check failure)
- src/Backups/BackupEntriesCollector.{h,cpp}: remove
isTableNamedByExceptDataClause(), which has no callers
- tests/integration/test_exclude_data_from_backup/test.py: remove
test_backup_ordinary_table_whose_name_looks_like_a_nested_table,
which belongs with the MaterializedPostgreSQL nested-table
classification work being extracted into a separate PR
jkartseva
left a comment
There was a problem hiding this comment.
Comments could be shorter, rest LGTM
One conflict, in `ErrorCodes.cpp`. Master rewrote that file - the `constexpr ErrorCode END` bound is gone, replaced by `sorted_codes` and `ErrorRegistry` - while this branch still carried `END = 1020` -> `1021`. That bump was left over from the error code this branch no longer declares: `INNER_TABLE_NOT_ALLOWED_IN_BACKUP_EXCLUSION` is not in the tree any more, so nothing occupies 1021 and nothing needs the bound raised. Took master's version, which drops `src/Common/ErrorCodes.cpp` from this branch entirely. Co-Authored-By: Claude Opus 5 <[email protected]>
46842f3
Closes: #111827
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added
EXCEPT DATA FROM TABLE/EXCEPT DATA FROM TABLESclauses toBACKUPqueries, so a table's definition can be backed up without its rows, for any storage engine that implementsbackupData.Description
Implements #111827 using a query-grammar clause instead of a table setting, per
review feedback:
EXCEPT DATA FROM TABLE t/EXCEPT DATA FROM TABLES t1, t2lets
BACKUPskip a table's rows while still including its definition. For atable that
RESTOREcan recreate, that restores as an empty table. Useful fortables whose data can be regenerated from a source table (e.g. materialized-view
targets), to reduce backup size.
This replaces an earlier, abandoned approach that used a MergeTree-only
setting (
exclude_data_from_backup/exclude_from_backup). That approachdidn't cover non-MergeTree engines (
StorageLog,StorageStripeLog,StorageMemory,StorageKeeperMap) and duplicated backup-policy logicacross engine implementations. The setting never shipped to
origin/master,so it was removed outright with no deprecation needed.
EXCEPT DATA FROM TABLE/EXCEPT DATA FROM TABLES, parsed inParserBackupQuery.cpp(parseExceptDataTables()) forTABLE,TEMPORARY_TABLE,DATABASE, andALLbackup element types, withformatting support in
ASTBackupQuery.cpp.BackupEntriesCollectorpopulates a per-databaseexcept_data_table_namesset from the parsed grammar and drives the data-inclusion decision entirely
from that set (
shouldBackupTableData(),isTableDataExcluded()) — notable setting involved.
StorageMaterializedViewandStorageTimeSeriescheckisTableDataExcluded()on their outer table name before backing up theirinner tables, so exclusion propagates correctly to delegated storage.
EXCEPT DATA FROM TABLE. Directlyspecifying an inner table name (e.g. a materialized view's
.inner_id.<uuid>table) is rejected withBAD_ARGUMENTS, thrown fromBackupEntriesCollector::gatherDatabaseMetadata(). Manually verified thisis live (not dead code) by backtick-quoting the inner table name to bypass
the parser's identifier check and confirming the query is rejected as
expected.
EXCEPT TABLES tandEXCEPT DATA FROM TABLES tcan coexist in the samequery — full exclusion wins, no error/conflict. Covered by
test_except_data_coexists_with_except_tables.BACKUPwrites, not whetherRESTOREcan recreatethe table. A standalone
MaterializedPostgreSQLtable cannot be recreated byRESTOREat all — with or without the clause — because it would startreplicating from the live PostgreSQL source as soon as it was created, so the
storage factory rejects it before the table exists. That restriction predates
this pull request. The documentation now says so and describes the supported
flow (a restore under a different name into a
ReplacingMergeTreecreatedbeforehand), instead of promising an empty restored table for every engine.
Covered by
test_except_data_from_materialized_postgresql_restore_into_replacing_mergetree,which asserts the excluded restore leaves the target empty while a control half
restoring the unexcluded backup into the same shape gets its rows.
Added
tests/integration/test_exclude_data_from_backup/test.pycovering:single-table and database-level multi-table exclusion,
ALL-levelexclusion, coexistence with
EXCEPT TABLES, non-MergeTree engines,materialized-view inner-table propagation, rejection of inner table names
specified directly, and a baseline confirming normal backup still
includes data with no exclusion given. All 42 tests pass locally.
Removed
test_table_in_replicated_database_with_exclude_data_from_backup_not_syncedfrom
test_backup_restore_on_cluster, which tested a replica-sync racecondition specific to the old per-table setting mechanism. That race cannot
occur with the grammar-based approach: there's no replicated setting to
propagate, and each node parses the same
BACKUPquery independently.Out of scope for this PR, tracked separately per review: the
partition-support validation rework for lagging
DatabaseReplicatedreplicas, and the
MaterializedPostgreSQLnested-table classification fix(recognising a standalone
MaterializedPostgreSQLtable's<uuid>_nestedtable as inner, so it isn't leaked as an ordinary table by
EXCEPT TABLES/EXCEPT DATA FROM TABLE). Both were reverted out of this branch andwill land as follow-up PRs.
Workflow [PR]
Sync PR [sync-upstream/pr/111895]
Version info
26.10.1.751-master(included in26.10and later)