Repository navigation
Fix RESTORE of tables on read-only storage that provides their data (backup_metadata_only) - #113574
Conversation
RESTORE of a backup containing a table whose storage policy has no writable disk (e.g. Cloud example datasets on read-only plain_rewritable disks) failed with "Could not reserve ... because all disk volumes are readonly. (READONLY)" or, if the recreated table had already discovered its parts from the disk, with CANNOT_RESTORE_TABLE "already contains some data". Restoring data into such a table can only fail, and the data is expected to be already present on the shared read-only storage, so `RestorerFromBackup` now skips the data restore for tables whose storage policy is fully read-only (mirrors `shouldBackupTableData` on the backup side). `IStoragePolicy::isReadOnly` mirrors the volume filter in `StoragePolicy::reserve`: a policy where every volume is read-only cannot satisfy any reservation. Closes: ClickHouse/clickhouse-private#35541 Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [866f0f1] Summary: ✅ AI ReviewSummaryThe PR adds the storage policy option Findings
Tests
Final Verdict |
`shouldRestoreTableData` skips the data phase for a table on a fully read-only storage policy: no write can succeed there and the parts are already present on the shared read-only storage. But skipping bypasses `IStorage::restoreDataFromBackup`, where the engine applies the partition filter, so a partition-filtered RESTORE would silently expose the whole dataset instead of the requested subset. Fail closed: throw `CANNOT_RESTORE_TABLE` when a partition filter is given for a table on a read-only storage policy, since the filter cannot be honored. The unfiltered case still skips the data phase as before. Add a regression test that backs up a read-only `table_disk` table, checks that an unfiltered RESTORE recreates it and discovers the parts from the disk, and that a `RESTORE ... AS ... PARTITIONS 1` fails with `CANNOT_RESTORE_TABLE`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
c8e8ec3 to
8530d7b
Compare
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes14 object files changed (+88.23 KiB total), 0 added.
719 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 units359 translation units recompiled, 3840 s compile time in total, 359 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes RESTORE failing for tables whose storage policy has no writable disks by detecting fully read-only policies and skipping the data-restore phase (while still restoring table structure). This matches the expected behavior for shared/static datasets where data is already present on read-only storage.
Changes:
- Add
IStoragePolicy::isReadOnlyand implement it inStoragePolicy. - Teach
RestorerFromBackupto skip restoring table data when the table’s storage policy is fully read-only; reject partition-filtered restores in that case. - Add a regression test covering successful restore and the “fail closed” behavior for partition-filtered restores.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Disks/IStoragePolicy.h |
Adds a new interface method to detect fully read-only policies. |
src/Disks/StoragePolicy.h |
Declares StoragePolicy::isReadOnly. |
src/Disks/StoragePolicy.cpp |
Implements read-only policy detection based on volume writability. |
src/Backups/RestorerFromBackup.h |
Declares RestorerFromBackup::shouldRestoreTableData helper. |
src/Backups/RestorerFromBackup.cpp |
Skips data restore for fully read-only storage policies; throws on partition-filtered restores to avoid silently restoring extra data. |
tests/queries/0_stateless/04627_restore_table_on_readonly_disk.sh |
New regression test reproducing the failure and validating the new behavior. |
tests/queries/0_stateless/04627_restore_table_on_readonly_disk.reference |
Expected output for the new test. |
pamarcos
left a comment
There was a problem hiding this comment.
The CI is failing on existing tests, so for sure we need to do something. I think those tests failing come from #83051 which introduced them to preserve fail-closed behavior.
From GPT-5.6 Sol:
The skip needs explicit metadata-only/provenance semantics, such as the backup_metadata_only storage-policy property proposed in the linked issue, rather than inference from runtime writability.
Minimum required actions:
- Replace generic policy->isReadOnly() inference with explicit provenance/metadata-only semantics.
- Preserve fail-closed behavior for arbitrary read-only targets.
- Apply the decision at delegated leaf storage and cover that path.
…kip-data-on-readonly-disks
…torage policy A storage policy marked `<backup_metadata_only>` provides the data of its tables itself, e.g. a shared read-only dataset such as the ClickHouse Cloud example datasets. `BACKUP` stores only the definitions of such tables, and `RESTORE` recreates them without restoring data and keeps their UUIDs from the backup, so that they find their data on the storage, which is kept under a path derived from the UUID. `RESTORE` of specific partitions of such a table fails, because the table shows all the data of its storage. This replaces skipping the data of a table on any fully read-only policy: being read-only doesn't mean the storage holds the data of the backup, and a disk can turn read-only at runtime, so `RESTORE` onto other read-only storage keeps failing with `READONLY` (`test_backup_restore_s3_plain`). The decision is made by `MergeTreeData` in `backupData` and `restoreDataFromBackup`, so a table backed up and restored through another one, e.g. the inner table of a materialized view, is covered too. Related: ClickHouse/clickhouse-private#35541 Co-Authored-By: Claude Opus 5.5 <[email protected]>
backup_metadata_only storage policy option for shared read-only datasets
…ackup_metadata_only` `ATTACH MATERIALIZED VIEW ... TO INNER UUID` doesn't attach the inner table, so attach it first; spell out `index_granularity` in the attached definitions, as `CREATE` adds it and `RESTORE` compares the definitions. Check the contents of the backup in its `.backup` manifest, as the files in the backup are named by checksums with `data_file_name_generator = checksum`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| { | ||
| auto uses = [&](const ASTStorage * storage) | ||
| { | ||
| if (!storage || !storage->settings) |
There was a problem hiding this comment.
This only recognizes an explicit SETTINGS storage_policy = ... clause. The later skip path is decided from the table's resolved getStoragePolicy(), so a table that inherits a backup_metadata_only policy from defaults still takes the else branch in createTable, gets a fresh UUID, and then MergeTreeData::restoreDataFromBackup skips copying parts anyway. On Atomic databases the recreated table now points at a new {uuid} directory and comes back empty even though the backup was treated as metadata-only.
The UUID-preservation decision needs to use the same resolved target policy/defaults as table creation, not just peek into the raw AST settings.
…gines `BACKUP` leaves out the data of a table on a storage policy marked `backup_metadata_only` in `BackupEntriesCollector::shouldBackupTableData`, next to `structure_only` and `EXCEPT DATA FROM TABLE`, and `RESTORE` skips it in `RestorerFromBackup`, before the engine checks that the table is empty. A materialized view and a `TimeSeries` table back up and restore the data of their inner tables, so the decision looks at those; a table whose inner tables are only partly on such policies is rejected. The `MergeTree` engines are unchanged. Also: - reject `backup_metadata_only` on a policy with a writable volume, as `BACKUP` would leave out the data written to it; - keep the UUID of a table restored onto such a policy only for the `MergeTree` family, and also when the policy comes from the default `storage_policy` of the server; - fail `RESTORE` if such a table doesn't have its UUID from the backup, e.g. an existing table restored with `create_table = 'must-exist'`, as it would not see the data. Co-Authored-By: Claude Opus 5.5 <[email protected]>
backup_metadata_only storage policy option for shared read-only datasetsRESTORE of tables on read-only storage that provides their data (backup_metadata_only)
…parsing its definition `RESTORE` decides whether a table keeps its UUID from the backup before the table is created, so it can't ask the storage for its policy. A table engine can now register `get_storage_policy_fn` in `StorageFactory::StorageFeatures`, which returns the storage policy a table created from a definition would use. The `MergeTree` family resolves it the way it creates a table, from the `storage_policy` setting or the default one of the engine, and the backup code no longer knows engine names or `MergeTree` settings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…etadata_only` `BACKUP` of specific partitions of a table on a storage policy marked `backup_metadata_only` backed up only its definition, which is restored with all the data of the storage, so refuse it. `RESTORE` of such a table without a UUID, e.g. in an `Ordinary` database, skipped its data although the table finds it under a path derived from its name, which `RESTORE ... AS` or a restore into another database changes, so refuse it too. #113574 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #113574 to 26.10: Fix `RESTORE` of tables on read-only storage that provides their data (`backup_metadata_only`)
`RestorerFromBackup::createTable` asks `BackupUtils::isCreatedOnBackupMetadataOnlyStoragePolicy` whether the definition from the backup puts its data on a `backup_metadata_only` storage policy. That check resolved the policy with `Context::getStoragePolicy`, which throws `UNKNOWN_POLICY` when the policy is not configured on this host, and it runs before `CREATE ... IF NOT EXISTS` - a no-op for a table that already exists, which never resolved the policy itself. So restoring into a pre-created table failed on any host that does not configure the policy named in the backup, for every plain `MergeTree`-family table with an explicit `storage_policy`, whether or not `backup_metadata_only` is configured anywhere. That is the common case of restoring a backup into a cluster with a different storage configuration. An unconfigured policy cannot be `backup_metadata_only`, so the check now answers `false` through the new non-throwing `Context::tryGetStoragePolicy` instead of throwing. A `CREATE` that does run still reports the unknown policy itself, which the test pins as well. Closes: ClickHouse#127098 Caused by: ClickHouse#113574 Co-Authored-By: Claude Opus 5 <[email protected]>
Same shape as the `26.9` backport. `26.8` does not have the per-element partition scopes (`TableParams::elements`, `anyElementNamedPartitions`, `partitionsWithData`) or `EXCEPT DATA FROM TABLE` (`isTableDataExcluded`); both are in the base the cherry-pick was taken from, so they are not part of what #113574 changes. The three conflicts in `BackupEntriesCollector.cpp` keep `26.8`'s structure and apply only the two additions of #113574: refusing a partition-scoped backup of a table on a `backup_metadata_only` policy, and skipping such a table's data in `shouldBackupTableData`. `RestorerFromBackup.cpp` conflicts only because `26.8` has no `WORKLOAD`/`RESOURCE` carrier tables, and the incoming side equals the base apart from a blank line, so #113574 changes nothing there. Nothing outside the conflict references the two helpers. Co-Authored-By: Claude Opus 5 <[email protected]>
`RestorerFromBackup::createTable` asks `BackupUtils::isCreatedOnBackupMetadataOnlyStoragePolicy` whether the definition from the backup puts its data on a `backup_metadata_only` storage policy. That check resolved the policy with `Context::getStoragePolicy`, which throws `UNKNOWN_POLICY` when the policy is not configured on this host, and it runs before `CREATE ... IF NOT EXISTS` - a no-op for a table that already exists, which never resolved the policy itself. So restoring into a pre-created table failed on any host that does not configure the policy named in the backup, for every plain `MergeTree`-family table with an explicit `storage_policy`, whether or not `backup_metadata_only` is configured anywhere. That is the common case of restoring a backup into a cluster with a different storage configuration. An unconfigured policy cannot be `backup_metadata_only`, so the check now answers `false` through the new non-throwing `Context::tryGetStoragePolicy` instead of throwing. A `CREATE` that does run still reports the unknown policy itself, which the test pins as well. Closes: #127098 Caused by: #113574 Co-Authored-By: Claude Opus 5 <[email protected]> (cherry picked from commit 1b266fd)
`26.9` does not have the per-element partition scopes (`TableParams::elements`, `anyElementNamedPartitions`, `partitionsWithData`) or `EXCEPT DATA FROM TABLE` (`isTableDataExcluded`); both are in the base the cherry-pick was taken from, so they are not part of what #113574 changes. The three conflicts in `BackupEntriesCollector.cpp` keep `26.9`'s structure and apply only the two additions of #113574: refusing a partition-scoped backup of a table on a `backup_metadata_only` policy, and skipping such a table's data in `shouldBackupTableData`. Co-Authored-By: Claude Opus 5 <[email protected]>
`RestorerFromBackup::createTable` asks `BackupUtils::isCreatedOnBackupMetadataOnlyStoragePolicy` whether the definition from the backup puts its data on a `backup_metadata_only` storage policy. That check resolved the policy with `Context::getStoragePolicy`, which throws `UNKNOWN_POLICY` when the policy is not configured on this host, and it runs before `CREATE ... IF NOT EXISTS` - a no-op for a table that already exists, which never resolved the policy itself. So restoring into a pre-created table failed on any host that does not configure the policy named in the backup, for every plain `MergeTree`-family table with an explicit `storage_policy`, whether or not `backup_metadata_only` is configured anywhere. That is the common case of restoring a backup into a cluster with a different storage configuration. An unconfigured policy cannot be `backup_metadata_only`, so the check now answers `false` through the new non-throwing `Context::tryGetStoragePolicy` instead of throwing. A `CREATE` that does run still reports the unknown policy itself, which the test pins as well. Closes: #127098 Caused by: #113574 Co-Authored-By: Claude Opus 5 <[email protected]> (cherry picked from commit 1b266fd)
…e that provides their data (`backup_metadata_only`)
…e that provides their data (`backup_metadata_only`)
Backport #113574 to 26.9: Fix `RESTORE` of tables on read-only storage that provides their data (`backup_metadata_only`)
Backport #113574 to 26.8: Fix `RESTORE` of tables on read-only storage that provides their data (`backup_metadata_only`)
…e that provides their data (`backup_metadata_only`)
…e that provides their data (`backup_metadata_only`)
Related: https://github.com/ClickHouse/clickhouse-private/issues/35541
Related: #83051
A table on a fully read-only storage policy, such as a ClickHouse Cloud example dataset, can be backed up but not restored: writing its parts fails with
READONLY(Could not reserve ... because all disk volumes are readonly), and the wholeRESTOREfails.To fix it, a storage policy can be marked
<backup_metadata_only>true</backup_metadata_only>, meaning that the storage itself provides the data of its tables. All volumes of such a policy must be read-only; this is checked when the policy is created and again whenever it is used, because a reload of the configuration can make a disk writable and keep the old policy. For tables on such a policy:BACKUPstores only their definitions.BACKUPof specific partitions fails, because the backup can't limit what the restored table shows. On a replica of aReplicateddatabase that hasn't created the table yet, this is decided from the table's definition;RESTORErecreates them without restoring data and keeps their UUIDs from the backup, because the data is on the storage under a path derived from the UUID. A table keeps its UUID if its definition in the backup setsstorage_policyexplicitly to such a policy and its engine is of the plainMergeTreefamily, also withstructure_only, as the data comes from the storage anyway.RESTOREfails if another table already has that UUID, e.g.RESTORE ... ASnext to the source table (the error doesn't name the other table, which the user may not be allowed to see);RESTOREof specific partitions fails, because the table shows all the data of its storage;RESTOREfails if the table ends up with a UUID different from the one in the backup, as it would not see the data. For example, an existing table restored withcreate_table = 'must-exist', or a table restored into a database that doesn't give tables UUIDs (Ordinary).Only tables of the plain
MergeTreefamily are supported. For the following on such a policy, the flag is ignored with a warning in the log, and their data is backed up and restored as without it (soRESTOREonto the read-only storage fails withREADONLY, as before):MergeTreetable:RESTOREcreates aReplicatedMergeTreetable in a mode that refuses the existing parts it finds, and aSharedMergeTreetable sees only the parts listed in Keeper. For a table known only by its definition (on a replica of aReplicateddatabase that hasn't created it yet), the engine is told by itssupports_replicationfeature;TimeSeriestable with an inner table on such a policy.An
Aliasof such a table is backed up and restored like anyAlias.Like a backup made with
structure_onlyorEXCEPT DATA, such a backup doesn't record that the data was omitted. So restoring a table onto a policy not markedbackup_metadata_only, e.g. withRESTORE ... SETTINGS storage_policy = ..., gives an empty table.The decision is made in the backup code (
BackupEntriesCollector::shouldBackupTableData,RestorerFromBackup), not in the engines.An earlier version of this PR skipped the data of any table on a fully read-only policy. That was replaced by the explicit flag: being read-only doesn't mean the storage holds the data of the backup, and a disk can turn read-only at runtime, so
RESTOREonto any other read-only storage keeps failing withREADONLY, as #83051 expects (test_backup_restore_s3_plain).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
RESTOREfailing withREADONLYfor a backup containing a table on read-only storage that provides the table's data itself, such as a shared example dataset. Such storage can now be marked with the storage policy optionbackup_metadata_only:BACKUPstores only the definitions of its tables, andRESTORErecreates them with their UUIDs from the backup without restoring data.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/113574]
Version info
26.11.1.378-master(included in26.11and later)26.10.2.54,26.9.26.13,26.8.35.12