Skip to content

Add factory-owned backup destination identity - #110610

Merged
pamarcos merged 7 commits into
masterfrom
backup-destination-identity-v2
Jul 23, 2026
Merged

pamarcos merged 7 commits into
masterfrom
backup-destination-identity-v2

Conversation

@pamarcos

@pamarcos pamarcos commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

Adds BackupFactory::getDestinationIdentity, with engine-specific identity callbacks
registered alongside backup creators. S3, AzureBlobStorage, File, and Disk share
their effective destination resolution between creation and identity generation, while
Memory and Null reject persistent identity.

The identity has a versioned, length-prefixed envelope and excludes authentication data.
BackupInfo::freezeNamedCollection retains the resolved collection snapshot so identity
generation and later backup creation observe the same destination.

This replaces the duplicated backup-engine parser from the earlier attempt with a smaller
factory-owned design. It remains infrastructure-only and has no production callers yet.

Related: #109083

Validated by building src/unit_tests_dbms, running all focused BackupInfo tests 60 times,
and running both repository style checks.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Not for changelog.

Documentation entry:

  • Documentation is not required because this is internal infrastructure with no callers.

Version info

  • Merged into: 26.7.1.1377 (included in 26.7 and later)

Add `BackupFactory::getDestinationIdentity` and register engine-specific identity callbacks alongside backup creators. Share effective destination resolution for `S3`, `AzureBlobStorage`, `File`, and `Disk`, while rejecting non-persistent engines.

Freeze named collections in `BackupInfo` so identity generation and later backup creation observe the same resolved collection. Encode identities with a versioned, length-prefixed envelope and exclude credentials.
@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [91ed1b4]

Summary: ✅


AI Review

Summary

This PR adds factory-owned backup destination identities and freezes named collections so identity generation and backup creation can share the same resolved backup location. The overall design is reasonable, but the Azure blob_path identity normalization is still looser than the actual backup I/O path handling, so it can assign different identities to locators that write to the same blobs.

Findings

⚠️ Majors

  • [src/Backups/registerBackupEngineAzureBlobStorage.cpp:203] Azure blob_path currently goes through stripOneTrailingSlash, but the reader and writer build object keys with std::filesystem::path(blob_path) / file_name, which collapses repeated separators anywhere in the prefix. As a result, locators such as ... 'backup' and ... 'backup//' hit the same blobs but get different destination identities. Suggested fix: normalize blob_path with the same std::filesystem::path rules the Azure I/O layer uses before hashing it into the identity, and update the Azure identity test that currently expects backup// to differ.
Final Verdict

Changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a factory-owned, versioned backup destination identity API (BackupFactory::getDestinationIdentity) with per-engine identity callbacks, intended to provide a deterministic, credential-free identity for effective backup destinations (including named-collection resolution via BackupInfo::freezeNamedCollection).

Changes:

  • Added BackupFactory::getDestinationIdentity and extended engine registration to include an engine-specific destination-identity callback.
  • Refactored File/Disk, S3, and AzureBlobStorage engines to share destination-resolution logic between backup creation and identity generation; Memory/Null explicitly reject persistent identity.
  • Added unit tests covering identity canonicalization, credential exclusion, and named-collection freezing behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Backups/tests/gtest_backup_info.cpp Adds tests for destination identity behavior, redaction, and named-collection freezing.
src/Backups/registerBackupEnginesFileAndDisk.cpp Centralizes local destination resolution and adds identity components for File/Disk.
src/Backups/registerBackupEngineS3.cpp Centralizes S3 destination resolution and adds S3 identity generation.
src/Backups/registerBackupEngineAzureBlobStorage.cpp Centralizes Azure destination resolution, adds identity generation, and validates certain endpoint forms.
src/Backups/BackupIO_Null.cpp Registers Null identity callback that rejects persistent identity.
src/Backups/BackupIO_Memory.cpp Registers Memory identity callback that rejects persistent identity.
src/Backups/BackupInfo.h Adds frozen_named_collection and declares freezeNamedCollection.
src/Backups/BackupInfo.cpp Implements freezeNamedCollection and uses the frozen snapshot in getNamedCollection.
src/Backups/BackupFactory.h Adds destination identity API and extends engine registration to include identity callbacks.
src/Backups/BackupFactory.cpp Implements identity envelope formatting and stores engines as {creator, identity_fn}.

Comment thread src/Backups/registerBackupEngineS3.cpp Resolved
@jkartseva jkartseva self-assigned this Jul 16, 2026

@jkartseva jkartseva 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.

Overall, I like the factory-based approach

Comment thread src/Backups/BackupInfo.h

/// Stores a private copy of the resolved named collection so later identity generation
/// and backup creation use the same collection state.
BackupInfo freezeNamedCollection(ContextPtr context) const;

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.

Maybe call it pinNamedCollection / pinned_named_collection instead of frozen? I think it has better semantics.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I preferred freeze here because we resolve the collection and overrides into a detached snapshot. The original collection can still change or be dropped, so pin could imply a lifetime or lease guarantee that we do not provide. What remains stable is the copied snapshot, which I think makes freezeNamedCollection / frozen_named_collection more precise.

This is not the hill I'll die on, though. We can change the name if you still think it makes more sense

/// Returns a versioned, credential-free identity of the effective backup location.
/// Named collections must be frozen first so identity generation and backup creation
/// observe the same collection state.
String getDestinationIdentity(const BackupInfo & backup_info, ContextPtr context) const;

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.

Now that getDestinationIdentity exists,BackupInfo::withoutS3Credentials looks out of place – and tracing it back, it was out of place to begin with: BackupInfo is meant to be engine-agnostic, yet this method is wired specifically for S3 (my fault as a reviewer).
Worth folding the credential classification into the per-engine path so redaction stops being S3-only. Just not in this PR though.

@pamarcos pamarcos Jul 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that credential redaction ultimately belongs in engine-owned code. It is not a mechanical move, though: the current S3 path includes AST evaluation and URL redaction, while an engine-neutral callback also needs correct AzureBlobStorage connection-string, SAS, and account-key handling plus security-focused tests. I will keep that as a separate follow-up so this PR remains focused.

The plan after merging this PR:

  • Add an engine-owned credential-redaction callback in a dedicated PR.
  • Move S3 redaction out of BackupInfo and add proper Azure redaction and security-focused tests.

/// Returns a versioned, credential-free identity of the effective backup location.
/// Named collections must be frozen first so identity generation and backup creation
/// observe the same collection state.
String getDestinationIdentity(const BackupInfo & backup_info, ContextPtr context) const;

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 you think this factory method have potential to evolve beyond the backup-from-snapshot use case? E.g., I would think of base -> incremental backup chain matching. Not in this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, definitely. This is why it's in BackupFactory and delegates the resolution to each engine. The base/incremental chain handling is a plausible use case. e.g. it oculd help compare base-backup destinations, validate retries or derive stable coordination keys without persisting credentials.

Document why `S3` destination identities can remove all valid trailing slashes while `AzureBlobStorage` removes only the slash consumed by path joining.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Use `fmt::format_to` to append framed identity components without a temporary string. Rename the registered callback field to `destination_identity` for consistency with `creator`.
Distinguish the three-argument connection string or URL form from the five-argument `AzureBlobStorage` form, which requires a plain storage account URL.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Comment thread src/Backups/BackupInfo.cpp Resolved
Drop the resolved named collection snapshot when `withoutS3Credentials` rewrites an `S3` locator. The snapshot contains the original overrides and must not remain available behind a redacted locator.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@pamarcos
pamarcos added this pull request to the merge queue Jul 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 21, 2026
@pamarcos
pamarcos added this pull request to the merge queue Jul 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 22, 2026
@pamarcos
pamarcos added this pull request to the merge queue Jul 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 22, 2026
Resolve semantic conflicts with the new ZIP guards in `master` that caused the merge queue's
`Fast test` and `Build (amd_binary)` jobs to fail.

Use the resolved archive fields for `S3`, `AzureBlobStorage`, and object-storage-backed `Disk`
destinations.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Azure Core does not support URL userinfo, while destination identity previously stripped it and
accepted the remaining endpoint. Reject it instead and verify credential-bearing URLs fail without
exposing the secret.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@pamarcos

Copy link
Copy Markdown
Member Author

@groeneai investigate the job that is failing: https://github.com/ClickHouse/ClickHouse/actions/runs/29936566085/job/88994375081

There's an already created issue: #111477
Investigate whether the issue is already fixed and link the PR that addresses that here. If it's not fixed, create a new PR to address it with the simplest and minimum amount of changes possible.

@groeneai

Copy link
Copy Markdown
Collaborator

@pamarcos That job is the chronic plain-rewritable metadata_dropped concurrent-create race, already fixed on master.

Re #111477: it was filed after the merge, but the runs it cites are all on branches predating #111353, i.e. the same pre-fix artifact. No second signature is failing on master, and it tracks the same race as #111289. (Release branch 26.7 still shows it and would need a backport of #111353.)

No separate fix is needed here.

@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 48.00% 86.20% +38.20%
Functions 60.60% 92.00% +31.40%
Branches 36.90% 78.30% +41.40%

Changed lines: Changed C/C++ lines covered: 431/487 (88.50%) · Uncovered code

Full report · Diff report

@pamarcos
pamarcos added this pull request to the merge queue Jul 23, 2026
Merged via the queue into master with commit 7b45d41 Jul 23, 2026
527 of 529 checks passed
@pamarcos
pamarcos deleted the backup-destination-identity-v2 branch July 23, 2026 09:51
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 23, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…on-identity-v2

Add factory-owned backup destination identity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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