Repository navigation
Cherry pick #113574 to 26.9: Fix RESTORE of tables on read-only storage that provides their data (backup_metadata_only) - #127092
Merged
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]>
`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]>
…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]>
…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]>
…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]>
…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]>
…adata_only` table `RESTORE` skips the data of a table on a storage policy marked `backup_metadata_only` and checks that the table has its UUID from the backup, as the data is on the storage under a path derived from it. For a materialized view or a `TimeSeries` table the data is kept by its inner tables, so an existing view restored with `create_table = 'must-exist'` with the UUID of the backup but another inner table passed the check and showed the data of its inner table. Now the UUID of every table keeping the data is compared with the one it has in the backup. #113574 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…red table A storage policy marked `backup_metadata_only` is read-only, so it can't be the default policy of tables, which have to be written: only an explicit `storage_policy` setting can put a table on it. The engines with that setting are the ones whose settings have it, which `StorageFeatures::has_builtin_setting_fn` already tells, so `get_storage_policy_fn` and the resolver of the `MergeTree` family are removed, and `StorageFactory` is unchanged. #113574 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Nikolai Ovchinnikov <[email protected]>
…as keeping data `getDataStorages` counted every table that isn't a view as keeping its data, but `Alias` keeps none and reports the storage policy of its target. So an `Alias` of a table on a policy marked `backup_metadata_only` was taken for a table whose data is on the storage: `RESTORE` gave it a new UUID like any `Alias`, then refused it because the UUID differed from the one in the backup. Of the tables that keep data, only `MergeTreeData` keeps it on a storage policy, so only those count now, which also leaves out `Distributed` and the `StorageProxy` wrappers. Also from the review: rename `isCreatedOnBackupMetadataOnlyStoragePolicy` to `isAnyCreatedOnBackupMetadataOnlyStoragePolicy`, check the parts of the storage definition it uses explicitly, and name the partition condition in `BackupEntriesCollector::gatherTablesMetadata` in snake case and use it for both checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eTreeData` The style check `storage_casts` rejected the `dynamic_cast` to `MergeTreeData`: a lazily loaded table is reached through `StorageTableProxy`, so the cast fails for it, and the proxy reports no storage policy either. Use `castStorage` with `DeferredTable::Load` and keep the loaded table, since backing up or restoring the table loads it anyway. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…w as keeping its data The previous change counted only `MergeTreeData` tables, also among inner tables. So a `TimeSeries` table with its tags in `Memory` and its other inner tables on a policy marked `backup_metadata_only` was taken for a table whose data the storage provides: `BACKUP` left out its data, including the tags, and `RESTORE` restored it without them. An inner table keeps data of the table whatever its engine, so every inner table counts, and one on no marked policy makes `BACKUP` and `RESTORE` fail with `NOT_IMPLEMENTED`, as for any mix. Only a standalone table has to be a `MergeTreeData`, which still leaves out `Alias`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…policy from its definition A `Replicated` database gives only the definition of a table that is not created on the replica yet, with no storage, and the check that refuses a backup of some partitions of a table on a storage policy marked `backup_metadata_only` was skipped then: `BACKUP TABLE ... PARTITIONS` on such a replica succeeded, and restoring the backup showed all the partitions on the storage. Without a storage, decide from the definition, as `RESTORE` does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…xed table Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n a `backup_metadata_only` policy Support a storage policy marked `backup_metadata_only` only for tables that keep their data themselves, which is all that shared read-only datasets need. A materialized view or a `TimeSeries` table with an inner table on such a policy makes `BACKUP` and `RESTORE` fail with `NOT_IMPLEMENTED`, unless the backup leaves out its data anyway (`structure_only`, `EXCEPT DATA`). This drops looking through views at their inner tables, the pairs of UUIDs of the inner tables, and the handling of views with inner tables on different policies. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…only when it is used A reload of the configuration can make a disk writable while keeping the policy: the policy built from the new configuration fails the check, so the old one stays, marked `backup_metadata_only` over a writable disk, and `BACKUP` would leave out the data written to it. `StoragePolicy::isBackupMetadataOnly` now checks the volumes again and throws `INVALID_CONFIG_PARAMETER` if one of them is writable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`RESTORE` creates a `ReplicatedMergeTree` table in a mode that refuses the existing parts it finds in its directory, so such a table on a policy marked `backup_metadata_only` couldn't be restored from a backup of its definition. `BACKUP` and `RESTORE` of it now fail with `NOT_IMPLEMENTED`, unless the data is left out anyway. Also tests that a disk made writable by a reload of the configuration fails the backup, and renames the test file to `test_backup_metadata_only.py`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…icy for a backup The check whether a table is on a `backup_metadata_only` policy runs for every table backed up or restored, and it used `castStorage` with `DeferredTable::Load`, which also calls `getNested` on a `StorageTableFunctionProxy` and so runs the table function: a table defined as `AS file(...)` with a missing file failed the whole `BACKUP` and `RESTORE` with `CANNOT_EXTRACT_TABLE_STRUCTURE`. Load only a lazily loaded table (`resolveStorageProxyLoading`), and look through the other proxies without loading them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`RESTORE` keeps the UUID of a table on a `backup_metadata_only` policy and refuses it if another table already has that UUID. The other table can be in any database, including one the restoring user may not see, so the error doesn't name it anymore. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… also for tables known by their definition Only a `StorageMergeTree` reopens the parts it finds on the storage: `RESTORE` creates a `ReplicatedMergeTree` table in a mode that refuses them, and a `SharedMergeTree` table sees only the parts listed in Keeper, so it would be restored empty. Every other `MergeTreeData` on such a policy is refused with `NOT_IMPLEMENTED`, not only `ReplicatedMergeTree`. A `Replicated` database may give only the definition of a table not created on the replica yet, and `BACKUP` decides from the definition then: an engine named `Replicated...` or `Shared...` is refused, as the features of the engines don't tell them apart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ort, instead of refusing them `BACKUP` and `RESTORE` refused a replicated or shared `MergeTree` table, a materialized view or a `TimeSeries` table on a storage policy marked `backup_metadata_only` with `NOT_IMPLEMENTED`, so one such table failed a backup of its whole database, and a `structure_only` backup of it couldn't be restored at all. Now the flag is ignored for such a table with a warning, and its data is backed up and restored as without the flag. For a table known only by its definition, the UUID is kept only for the plain `MergeTree` family. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on` feature, not their names `isCreatedOnBackupMetadataOnlyStoragePolicy` keeps the UUID only for the plain `MergeTree` family, and told the replicated and shared engines from it by the prefixes of their names. They are all registered with the feature `supports_replication`, and the plain engines without it, which also covers any engine added later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e accepts `isCreatedOnBackupMetadataOnlyStoragePolicy` accepted any engine that declares `storage_policy` as a builtin setting. `Log`, `TinyLog` and `StripeLog` register `StorageLogSettings::hasBuiltin`, which answers true for it, so they passed a check that `isDataOnBackupMetadataOnlyStoragePolicy` refuses: the latter reaches the flag only through `castStorage<MergeTreeData>`. The two then disagreed about the same table. Backing up a `Log` table on a marked policy and restoring it under another name while the source exists made `createTable` keep the source UUID, and the restore failed with `another table already has this UUID`. These engines never take the data-skip path, so they want the ordinary path, including a new UUID for the copy. Identify the family by the settings the engine declares instead. Only `registerStorageMergeTree` registers `MergeTreeSettings::hasBuiltin`, and it shares one `StorageFeatures` across the whole family, so the comparison matches the `MergeTree` engines and nothing else. `supports_replication` continues to separate the plain engines from the replicated and shared ones, as before. Covered by a `Log` structure-only restore under another name while its source still exists, which asserts the copy gets its own UUID. Co-Authored-By: Claude Opus 5 <[email protected]>
…kip-data-on-readonly-disks
- Restore a table on such a policy with a new UUID when the restore leaves out table data: with the UUID from the backup it would find all the data of the storage, which `structure_only` asks it not to restore, and it would collide with the source table. Tested. - Decide the engine of a table known only by its definition before resolving its storage policy, which throws when the policy is not configured on this host. A `Replicated` database gives only the definition of a table not created on this replica yet, and for a `ReplicatedMergeTree` the other replicas provide the data, policy or no policy. - Take the storage or the definition inside `isDataOnBackupMetadataOnlyStoragePolicy` instead of choosing between the two predicates at each call site. - Take the target table of a view out of the `if` that tests it. - Say in `StoragePolicy::isBackupMetadataOnly` why the read-only check cannot be left to where a policy is built. Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
…kip-data-on-readonly-disks
…a-on-readonly-disks Fix `RESTORE` of tables on read-only storage that provides their data (`backup_metadata_only`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #113574
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job