Repository navigation
Support BACKUP/RESTORE for WORKLOAD and RESOURCE entities - #108431
Conversation
Implement backupData/restoreDataFromBackup for system.workloads and system.resources so that CREATE WORKLOAD and CREATE RESOURCE definitions are included in BACKUP and recreated on RESTORE, mirroring how UDFs (system.functions) are backed up. Backup writes one <name>.sql file per entity. Restore parses the files and recreates entities in dependency order (resources and parent workloads first) using CREATE-IF-NOT-EXISTS semantics. ON CLUSTER backups deduplicate writers via new replicated coordination, analogous to ReplicatedSQLObjects for UDFs. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [5ee1e3c] Summary: ✅
AI ReviewSummaryThis PR adds Findings❌ Blockers
Tests
Final VerdictRequest changes. The direct access-control and ordering fixes look good, but Keeper-backed workload backup/restore still is not reliable under normal watch lag, so the new replicated support should not merge in its current form. LLVM Coverage ReportMeasured on commit 5ee1e3c.
Changed lines: Changed C/C++ lines covered: 246/261 (94.25%) · Uncovered code |
Context::getWorkloadEntityStorage() was renamed to getWorkloadEntityStoragePtr() (returning a shared_ptr) on master. Update the backupData/restoreDataFromBackup hooks in system.workloads and system.resources accordingly. Co-Authored-By: Claude Opus 4.8 <[email protected]>
WorkloadEntityStorageBase::backup() iterated getAllEntities(), which includes entities provided through the server configuration (the chained WorkloadEntityConfigStorage). Config-defined entities must not be backed up: the configuration is backed up and restored separately together with all its entities, and re-creating them from a backup would persist them as SQL entities, which is not equivalent. Iterate local_entities (this storage's own SQL-defined entities) instead. Add tests: - 04409_backup_restore_workloads_and_resources (stateless): round-trips workloads and resources through BACKUP/RESTORE and checks the definitions are preserved. - test_backup_restore_workload_entities (integration): verifies a backup contains only SQL-defined entities, never config-defined ones, and that restore recreates the SQL entities without duplicating or converting the config-defined ones. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@groeneai, the CI failures on this PR are unrelated to its changes (this PR only touches the Backups subsystem and
|
|
Investigated all 4. None touch the code this PR changes (Backups + 1. 2. 3. 4. |
|
Follow-up on the Mechanism: #107461 (merged Jun 18) enabled disk spill at a 300 MiB threshold in Fix is already up and approved: #107968 raises |
- RestorerFromBackup: require CREATE WORKLOAD / CREATE RESOURCE access when restoring system.workloads / system.resources (only CREATE_FUNCTION was special-cased before), so RESTORE no longer bypasses these privileges. - RestoreCoordination: acquire restore ownership once per replication id instead of per entity type, so one replica restores both system.workloads and system.resources together and a workload's FOR <resource> reference stays valid. Record current_host_index in the coordination node so a host that loses the Keeper response can recover ownership on retry. - WorkloadEntityStorageBase: key the restore accumulator and the task-added guard by restore id, so concurrent restores no longer mix entities or drop one another's restore task. Co-Authored-By: Claude Opus 4.8 <[email protected]>
WORKLOAD and RESOURCE entities are intertwined (a workload references resources via SETTINGS ... FOR <resource> and workloads form a hierarchy), so they are always restored together. Add a single RESTORE setting create_workloads_and_resources (modes: create / if-not-exists / replace, default if-not-exists) that governs how RESTORE handles entities that already exist, mirroring create_function for UDFs. The mode maps to throw_if_exists / replace_if_exists and is applied uniformly to both system tables. Extends the stateless test 04409 to cover all three modes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
@groeneai, the new CI failures on head 1. Stress test (arm_release) — 2. Performance Comparison (arm_release, master_head, 3/6) — cascades from the same STID Please investigate STID |
|
Confirmed, both reds are unrelated to this PR. STID Fix already in progress: #109114 (it skips the runtime filter when a join input header has a duplicate column name; a runtime filter is a pure optimization, so results are unchanged). It Closes #109215 (the The Performance Comparison (arm_release, master_head, 3/6) red shares the same root cause (the same JoinStep logical error surfacing during its benchmark queries), so it is not PR-caused either. |
…ad-resource-backup
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 108/220 (49.09%) · Uncovered code |
…o workload-resource-backup # Conflicts: # docs/en/operations/workload-scheduling.md
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds BACKUP/RESTORE support for SQL-defined workloads and resources (new backup coordination classes, restore settings, and access checks) plus a docs section. None of that code runs during a ClickBench SELECT. The only flagged query, Q28 (+5.1%), was already borderline with the two tests disagreeing and sits on an intrinsically noisy history, so this is run-to-run variance rather than a real effect of the change. No plausible performance impact from this PR; no action needed. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
jkartseva
left a comment
There was a problem hiding this comment.
LGTM; Are you planning to include backups of workloads and resources to the Cloud? If so, we might need an operator change.
Yes, we definitely need it. |
- Warn at backup when a backed-up workload references a config-defined entity (parent workload or FOR resource): such config entities are not included in the backup, so a restore on a server that lacks them in its configuration would fail. - Use map::extract instead of find + swap + erase in restoreEntitiesAccumulatedFromBackup. - Drop the unused WorkloadEntityType forward declaration in IRestoreCoordination.h. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…backed up The warning was evaluated once over the whole snapshot before the entity_type filter, so e.g. BACKUP TABLE system.resources still scanned workloads and logged a spurious warning about a workload's references even though no workloads were being backed up. Move it into the per-type loop so it runs only over the entities selected for the current backup() call. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Reading a Disk(...) backup requires the READ ON DISK source grant, so the limited users that exercise the WORKLOAD / RESOURCE restore access checks could not read the backup and their restores failed with ACCESS_DENIED. Grant READ ON DISK up front so the checks isolate the CREATE / DROP WORKLOAD / RESOURCE privileges under test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The only red, |
|
Confirmed unrelated to your changes: all 29 files here sit under I cannot re-run it for you, though: Two things worth knowing before you retry, because a plain re-run is not a reliable route to green right now:
So expect roughly a 1-in-6 chance of the retry landing on the same abort while this lasts. |
|
@groeneai check support for incremental backups and snapshot |
|
Acknowledged. I'm checking both arms against master: incremental ( |
|
I read "snapshot" both ways it could be meant, so there are three arms below. Measured on
Incremental. With nothing changed between the full backup and the incremental, the incremental writes zero Across an evolving set I get exactly the expected split. Base holds Snapshot, the mode. PR: #119975 adds the incremental test to Two axes I left alone rather than fold in. Incremental x cc @serxa |
PR ClickHouse#108431 added BACKUP/RESTORE for SQL-defined WORKLOAD and RESOURCE entities, and @fm4v asked whether that support holds for incremental backups. It does, but nothing exercised it: base_backup and entity-storage backup were disjoint axes in the test suite. All eight incremental tests in test_backup_restore_new back up test.table, base_backup appears nowhere in test_backup_restore_on_cluster/, and no test for access entities, UDFs, workloads or resources did full then incremental then restore-from-incremental. That last case is the consequential one. WorkloadEntityStorageBase::restore enumerates entities with backup->listFiles(), so had an incremental's manifest omitted files deduplicated into the base, a RESTORE would have silently recreated fewer workloads and resources than existed. Measured on master: the manifest carries a <file> element for every file, each with <use_base>, and restoring the incremental alone returns the complete set. The new test walks one evolving entity set across a base and an incremental so that a single flow carries all three checkBaseBackupForFile outcomes plus deletion: a resource created after the base (HasNothing), a workload dropped after it, a workload extended by one setting (HasPrefix, since BackupEntryFromMemory allows a partial checksum and formatWithSecretsOneLine appends), and a resource left untouched (HasFull). The exact-list oracle on the incremental's contents proves in one assertion that only the changed workload and the new resource carry bytes. Carrier three gets its own byte-exact assertion because the restored create_query reads the same whether prefix reuse engaged or the whole definition was rewritten. Verified by mutating each carrier out in turn and confirming the targeted assertion reddens, and by removing the drops to confirm the arming assertions are load-bearing. Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support
BACKUP/RESTOREforWORKLOADandRESOURCEentities. SQL-definedCREATE WORKLOAD/CREATE RESOURCEdefinitions are now included when backing upsystem.workloads/system.resourcesand are recreated on restore, includingON CLUSTER.Documentation entry for user-facing changes
Summary
Implements the
backupData/restoreDataFromBackuphooks forsystem.workloadsandsystem.resources, soWORKLOADandRESOURCEDDL is covered byBACKUP/RESTORE(mirroring how UDFs insystem.functionsare handled). Closes #74879.Details
<escaped_name>.sqlfile per SQL-defined entity. Config-defined entities are excluded — they live in the read-only configuration storage and are expected to be restored together with the configuration. Bothsystem.workloadsandsystem.resourcesare served from a single consistent snapshot of the storage taken once per backup operation, so a concurrent DDL cannot split an interdependent workload/resource pair across the two calls. On replicated /ON CLUSTERbackups a single writer per replication id is elected viaBackupCoordinationReplicatedWorkloadEntities..sqlfiles, accumulates both entity types, and recreates them in dependency order (resources and parent workloads first). A restored definition whose kind does not match the system table being restored is rejected, so the table-based access gate cannot be bypassed.system.workloadsandsystem.resourcesare expected to be backed up and restored together: a restored workload that references a resource neither in the backup nor already on the server is rejected with a clear error. Thecreate_workloads_and_resourcessetting selects how an already-existing entity is handled:if not exists(default),create(fail if it exists), orreplace(overwrite). Restore requiresCREATE WORKLOAD/CREATE RESOURCE, and additionallyDROP WORKLOAD/DROP RESOURCEinreplacemode.Testing
04409_backup_restore_workloads_and_resources: single-node round-trip, access-privilege enforcement (includingDROPinreplacemode and thestructure_only/restore_table_dataedge cases), and all threecreate_workloads_and_resourcesmodes.test_backup_restore_workload_entities: single-node round-trip, a two-node Keeper-backedON CLUSTERround-trip, exclusion of config-defined entities from backups, rejection of a kind-mismatched definition, and rejection of a workloads-only restore whose referenced resource is missing.Workflow [PR]
Sync PR [sync-upstream/pr/108431]
Version info
26.9.1.1185(included in26.9and later)