Skip to content

Add restore_table_data, restore_access_entities, restore_functions settings for RESTORE - #102402

Merged
alexey-milovidov merged 36 commits into
masterfrom
fix-structure-only-restore-users
Aug 17, 2026
Merged

alexey-milovidov merged 36 commits into
masterfrom
fix-structure-only-restore-users

Conversation

@fm4v

@fm4v fm4v commented Apr 10, 2026 •

Copy link
Copy Markdown
Member

Add three new optional restore settings that give granular control over what gets restored:

  • restore_table_data — whether to restore table data (default: true, or false when structure_only=true)
  • restore_access_entities — whether to restore users, roles, settings profiles, row policies, quotas (default: true, or false when structure_only=true)
  • restore_functions — whether to restore user-defined functions (default: true, or false when structure_only=true)

When not explicitly set, these default based on structure_only: all three are true normally, all three are false when structure_only=true. When explicitly set, they override structure_only. This is fully backward compatible.

Example — restore table structure + access entities without table data:

RESTORE ALL FROM backup_name SETTINGS structure_only=true, restore_access_entities=true

Changelog category (leave one):

  • New Feature

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

Add restore_table_data, restore_access_entities, and restore_functions restore settings for granular control over what gets restored. These can override structure_only for individual categories — e.g. structure_only=true, restore_access_entities=true restores table definitions and access entities without table data.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Documented in docs/concepts/features/backup-restore/restore-settings.mdx (registered in the "Backup and restore" navigation group), and in the BACKUP/RESTORE settings table rendered by the backup and restore overview.

Three new optional Bool restore settings: restore_table_data, restore_access_entities, restore_functions. When not set, they follow structure_only. When explicitly set, they override it.

Version info

  • Merged into: 26.8.1.1550 (included in 26.8 and later)

Previously, `structure_only=true` skipped restoring access entities
(users, roles, quotas, settings profiles, row policies) and
user-defined functions. These are structural definitions rather than
table data, so they should be restored even when table data is skipped.

The issue was in two places:
- `loadSystemAccessTables` returned early, preventing access entity
  metadata from being loaded from the backup
- `insertDataToTable` returned early for all tables, including the
  system access tables and system.functions whose "data" is actually
  access entity definitions and UDF definitions
@clickhouse-gh

clickhouse-gh Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f057f36]

Summary: ✅


AI Review

Summary

This PR adds granular RESTORE toggles for table data, access entities, and user-defined functions, and wires them through parsing, execution, access checks, observability, documentation, and focused integration coverage. I did not find any actionable correctness, compatibility, or test-coverage issues in the current diff.

Missing context / blind spots
  • ⚠️ The full CI matrix is still in progress on commit f057f36fc07d7742fcb4543eed4daf843083dba6, so this review is based on code inspection plus the currently completed checks (Style check, Docs check (Mintlify), Fast test, and Build (arm_tidy)).
Final Verdict

✅ No actionable findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.10% +0.00%

Changed lines: Changed C/C++ lines covered: 54/61 (88.52%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 10, 2026
@fm4v
fm4v requested a review from vitlibar April 10, 2026 15:30
Add settings_profiles, row_policies, and quotas to the test so all
five ACL-backed system tables are exercised.
@vitlibar vitlibar self-assigned this Apr 10, 2026
@vitlibar

Copy link
Copy Markdown
Member

I don't quite understand the idea. structure_only was supposed to restore "structure", i.e. only definitions of databases and tables, not the data in these tables. And functions in system.functions can be considered as data, as well as users in system.users. Is there something behind this PR which is not said?

…lity

Keep structure_only behavior unchanged (does not restore access entities
or UDFs). Add a new structure_only_restore_definitions setting that,
when used together with structure_only=true, also restores access
entities (users, roles, settings profiles, row policies, quotas) and
user-defined functions.

The test now verifies both:
- structure_only alone does NOT restore access entities (backward compat)
- structure_only + structure_only_restore_definitions restores them
@fm4v fm4v changed the title Restore access entities and UDFs with structure_only=true Add structure_only_restore_definitions setting for RESTORE Apr 13, 2026
@clickhouse-gh clickhouse-gh Bot added pr-feature Pull request with new product feature and removed pr-bugfix Pull request with bugfix, not backported by default labels Apr 13, 2026
@fm4v

fm4v commented Apr 13, 2026

Copy link
Copy Markdown
Member Author

The use case is to test restores without data, but restore access entities to use them in internal replay tool. To keep backward compatibility, I've added a separate setting structure_only_restore_definitions rather than changing structure_only behavior.

@vitlibar

Copy link
Copy Markdown
Member

The use case is to test restores without data

This can be done in two commands:

RESTORE TABLE system.functions, system.users, system.roles, system.row_policies, system.profiles, system.quotas FROM ...
RESTORE ALL EXCEPT system.functions, system.users, system.roles, system.row_policies, system.profiles, system.quotas FROM ... SETTINGS structure_only=true

@vitlibar

vitlibar commented Apr 14, 2026 •

Copy link
Copy Markdown
Member

To keep backward compatibility, I've added a separate setting structure_only_restore_definitions rather than changing structure_only behavior.

structure_only_restore_definitions sounds quite vague and confusing. Probably we could split it into structure_only_restore_access_entities and structure_only_restore_functions which is better, but still not really good.

Probably the clearest solution would be to add three settings:

restore_table_data
restore_access_entities
restore_functions

and thus make setting structure_only obsolete (so we can remove it from the public interface and handle structure_only=false there as restore_table_data=false, restore_access_entities=false, restore_functions=false)

@alexey-milovidov alexey-milovidov left a comment

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.

Do not merge before fixing "Logical error: '!res.empty()' (STID: 2508-3ea0)"

@fm4v

fm4v commented Apr 14, 2026

Copy link
Copy Markdown
Member Author

This can be done in two commands

It's not configurable in the cloud restores. it's managed by dataplane

Probably the clearest solution would be to add three settings

I don't want to introduce backward incompatibilities because of testing-only setting

@vitlibar

Copy link
Copy Markdown
Member

I don't want to introduce backward incompatibilities because of testing-only setting

Just add 3 settings

restore_table_data
restore_access_entities
restore_functions

and handle structure_only=true as restore_table_data=false, restore_access_entities=false, restore_functions=false. This is not backward-incompatible!

Add restore_table_data, restore_access_entities, restore_functions
settings (optional bools). When not set, they default based on
structure_only (true when structure_only is false, false when it is
true). When explicitly set, they override structure_only.

This allows e.g.:
  RESTORE ... SETTINGS structure_only=true, restore_access_entities=true

to restore table structure + access entities without table data,
while keeping full backward compatibility with structure_only=true.
@fm4v fm4v changed the title Add structure_only_restore_definitions setting for RESTORE Add restore_table_data, restore_access_entities, restore_functions settings for RESTORE Apr 14, 2026
Comment thread src/Backups/RestorerFromBackup.cpp Resolved
…re_only`

The `checkAccessForObjectsFoundInBackup` pre-check was still gating
INSERT privilege on `!structure_only`, but actual data restore now uses
`shouldRestoreTableData`. This made the access validation inconsistent:
`structure_only=true, restore_table_data=true` would skip the INSERT
privilege check but then attempt inserts during execution.
Verify that when `restore_table_data` is explicitly enabled alongside
`structure_only`, table rows are restored while access entities and
UDFs remain absent.
Verify that UDFs are not restored when only restore_table_data is
enabled alongside structure_only.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status update (automated): the previous CI run on 454a742e errored at the infrastructure level — all 10 red jobs (Fast test, all Build (*) variants) show ERROR with 0s duration and no logs, so nothing actually built or ran. Merged the latest master (clean auto-merge, 2cbf44e14be) and pushed to trigger a fresh run; the three changed Backups translation units (RestoreSettings.cpp, RestorerFromBackup.cpp, SettingsFieldOptionalBool.cpp) compile clean against current master. The AI review verdict on the previous head is ✅ no actionable findings. No new review feedback since the last update; the remaining blocker is the human re-review of the CHANGES_REQUESTED from April, which targeted the old design (the Logical error: '!res.empty()' no longer reproduces on the reworked implementation).

Comment thread src/Backups/RestoreSettings.h Resolved
pull Bot pushed a commit to SINHASantos/ClickHouse that referenced this pull request Aug 9, 2026
The test asserts that `MemoryPeak` events with `memory_context = 'Global'`
appear in `system.trace_log`, but such events are sent only when the
server-wide memory usage grows past its previous peak by at least
`total_memory_profiler_step` (4 MiB). When the peak reached during server
startup is higher than anything the test's small queries allocate, no
`MemoryPeak` event can ever be produced and the existing retry loop cannot
help - the test fails with `assert 0 > 0`. Force a new global peak by
allocating an increasing amount of memory (~100 MB more per attempt) inside
the retry loop.

Seen in https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102402&sha=f8b38f834a2e63df6820ad1e750205d84276799a&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%202%2F4%29
of ClickHouse#102402

Co-Authored-By: Claude Fable 5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

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.

🕵 The previously requested !res.empty() fix applied to the superseded design. The current granular-settings implementation gates ACL restore correctly; all outstanding inline feedback is addressed.

@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f057f36fc with master 369e1aafb (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 694.62 MiB 691.61 MiB -3.01 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

19 object files changed (+57.43 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Backups/SettingsFieldOptionalBool.cpp.o new 41.25 KiB +41.25 KiB

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

33 translation units recompiled, 243 s compile time in total, 32 of them have a recent master baseline.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged current master cleanly and pushed the continuation at 741acbc5402a. The complete diff against master remains limited to the granular RESTORE settings, documentation, and focused integration test. All review threads are resolved; CI has been retriggered by this update.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 17, 2026
Merged via the queue into master with commit 98a7694 Aug 17, 2026
181 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-structure-only-restore-users branch August 17, 2026 07:30
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 17, 2026

This branch was successfully deployed

1 active deployment
staging - docs — f057f36f Deployed Aug 16, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants