Skip to content

Fix restoring a lightweight snapshot from Azure when the source disk has a key prefix - #122697

Merged
hanfei1991 merged 9 commits into
masterfrom
garrettthomaskth/azure-snapshot-reader-namespace-prefix
Oct 6, 2026
Merged

hanfei1991 merged 9 commits into
masterfrom
garrettthomaskth/azure-snapshot-reader-namespace-prefix

Conversation

@garrettthomaskth

@garrettthomaskth garrettthomaskth commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Fix container existence check during RESTORE of a lightweight snapshot from Azure Blob Storage by parsing the saved namespace into container name and prefix.

Why

A lightweight snapshot manifest records the source disk's endpoint and object namespace, and for an Azure disk whose endpoint has a path below the container e.g. https://<account>.blob.core.windows.net/<container>/data/) that namespace is <container>/data/. On RESTORE the Azure snapshot reader used the recorded namespace verbatim as the container name, so its container-existence check checked https://<account>.blob.core.windows.net/<container>/data/. Azure rejects a container-level request on a URL with extra path segments with 400 InvalidUri, so every such restore failed before reading a single blob.

What

The Azure snapshot reader creator now delegates to makeSnapshotSourceConnectionParams (BackupIO_AzureBlobStorage), which splits the recorded namespace at the first / into the container name and a blob prefix, so blob reads and native copies resolve to <container>/<prefix>/<key> and a namespace without a / behaves exactly as before. It marks the container as existing, since the snapshot was taken from it and the existence check was the failing request, and it works on a copy of the backup's connection params instead of mutating them. With connection-string auth the recorded endpoint cannot be applied, so the helper compares it with the connection string's blob endpoint and throws BAD_ARGUMENTS when they name different accounts instead of silently reading from the backup's account, and because the split happens on the read side it also repairs restores of snapshots taken before this fix.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/122697]

Version info

  • Merged into: 26.10.1.1680-master (included in 26.10 and later)
  • Backported to: 26.9.13.4, 26.8.20.5, 26.7.24.5

…has a key prefix

The snapshot manifest records the source disk's object namespace, which
for Azure is `<container>/<prefix>` when the disk endpoint has a path
below the container (`AzureObjectStorage::getObjectsNamespace`), while
S3 records only the bucket. The Azure `snapshot_reader_creator` used that
namespace verbatim as a container name, so the reader's container-level
existence check went to `.../<container>/<prefix>/?restype=container`
and Azure rejected it with `400 InvalidUri`.

Split the namespace into `container_name` and `endpoint.prefix`, mark the
container as existing, and keep a connection-string account URL as is.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7505357]

Summary: ✅


AI Review

Summary

This PR moves Azure lightweight-snapshot restores onto makeSnapshotSourceConnectionParams, so the recorded namespace is split back into container + prefix instead of being used verbatim as a container name. That fixes the original InvalidUri case for host-style endpoints, but the helper still reuses the backup endpoint-shape flags after swapping in the snapshot's fully materialized service URL, so path-style Azure endpoints still build the wrong container URL and the promised restore fix remains incomplete.

Findings
❌ Blockers
  • [src/Backups/BackupIO_AzureBlobStorage.cpp:120] makeSnapshotSourceConnectionParams starts from the backup's Endpoint and only overwrites storage_account_url, container_name, and prefix. For non-connection-string auth that preserves account_name + add_account_name_to_url from the backup location even though service_url is already the snapshot source's final service endpoint (the value recorded in the manifest comes from getServiceEndpoint). As a result, any path-style source URL such as https://proxy/account is turned into https://proxy/account/account/<container> when createForContainer later calls Endpoint::getContainerEndpoint, so same-account restores still fail for supported path-style and mixed-shape endpoint combinations.
    Suggested fix: rebuild connection_params.endpoint from service_url instead of inheriting the backup endpoint shape. At minimum, derive whether the account name is already materialized in service_url and clear/reset account_name / add_account_name_to_url accordingly before constructing the reader; then add regression coverage for path-style source endpoints (and the mixed path-style-backup / host-style-source case) in the Cloud-side test suite.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: rebuild the snapshot reader endpoint shape from the recorded service_url instead of reusing the backup endpoint flags, and cover the affected path-style restore shape with a focused regression test.

LLVM Coverage Report

Measured on commit 7505357.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 28, 2026
Move the namespace split out of the Azure backup engine's snapshot reader
creator into `makeSnapshotSourceConnectionParams` in
`BackupIO_AzureBlobStorage`, and cover it with a gtest: a prefixed
namespace is split into container and prefix, a plain container namespace
is unchanged, the backup's own connection params are not mutated, and a
connection-string account URL is kept.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-backup Backup/restore infrastructure and backup formats. label Sep 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 750535778 with master 503013e8c (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 16 s compile time in total, 8 of them have a recent master baseline.

Job report

With connection-string auth `createForContainer` builds the client from
the connection string and ignores `storage_account_url`, so the recorded
`original_endpoint` cannot be applied; leaving it unused would silently
read the backup's account instead of the snapshot's. Compare the recorded
endpoint with the connection string's blob endpoint (SDK-canonical,
trailing slashes ignored) and throw `BAD_ARGUMENTS` when they name
different accounts.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@hanfei1991 hanfei1991 self-assigned this Sep 29, 2026
@hanfei1991
hanfei1991 marked this pull request as ready for review September 29, 2026 14:35
Review: the lightweight-snapshot code path it covers is used only in Cloud,
so the test stays in the Cloud repo (sync PR) instead.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 32 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 4d0965fe-ec8e-4185-8575-38d9dbc24653
  • MIRAI run: 6e9d3110-26ad-4918-9ae8-65eb43f70499
  • PR check IDs:
    • clickbench_3369226_1791211453
    • clickbench_3369232_1791211453
    • clickbench_3369238_1791211453
    • tpch_adapted_1_official_3369249_1791211453
    • tpch_adapted_1_official_3369260_1791211453
    • tpch_adapted_1_official_3369296_1791211453

…ction string

Review: the same account is reachable through several hosts (a private link
alias, Azurite by IP or by host name), so comparing the manifest endpoint with
the connection string's blob endpoint as URLs rejected valid restores. Compare
the account names instead: the connection string's AccountName (or the account
its blob endpoint names) against the account the manifest endpoint names, the
first host label for `<account>.blob.<suffix>` and `<account>.privatelink.blob.<suffix>`
hosts or the first path segment of a path-style endpoint. A URL that does not
reveal its account, such as a custom domain, is let through and a wrong account
fails at the first read.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…pshot endpoints that reveal none

storageAccountOfURL took any non-empty path as a path-style account name, so a host-style endpoint
that carries a path, e.g. https://acct.blob.core.windows.net/container/data/, named `container` rather
than `acct`, and a restore from the backup's own account was rejected as a cross-account one. The host
is now consulted first (`<account>.blob|dfs.<suffix>` and the privatelink aliases), and the first path
segment is only taken as the account when the host names none, which is how Azurite endpoints look.

With connection-string auth an endpoint that does not reveal its account (a custom domain) was let
through on the assumption that a wrong account fails at the first read. It does not: the container is
marked as existing, so nothing probes the source, and another account with the same container and key
layout would be restored from silently. Such an endpoint is now rejected with BAD_ARGUMENTS as well.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
save-my-heart pushed a commit to save-my-heart/ClickHouse that referenced this pull request Oct 1, 2026
The worker arm's `INSERT INTO t05288_dst ... SETTINGS ast_fuzzer_runs = 5`
makes the server run fuzzed copies of it, and the copies write into
`t05288_dst` too. In the failing run one copy became
`... NATURAL INNER JOIN numbers(1048577)`, a cross join, and wrote
161 million rows with `id < 2000` in the 10 seconds a fuzzed query may
run. The `source_rows_written` check then scanned
`t05288_dst WHERE id < 2000` and failed under the CI profile's
`max_rows_to_read = 20000000` with `Code: 158 ... Limit for rows
(controlled by 'max_rows_to_read' setting) exceeded, max rows:
20.00 million, current rows: 48.80 million (TOO_MANY_ROWS)`.

Read the statement's own `QueryFinish` row in `system.query_log` instead
and assert that its `written_rows` equals the source row count. Fuzzed
copies run as separate internal queries (`is_internal = 1`) that never
log `QueryFinish`, so what they write no longer affects the check.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122697&sha=aa88a04fe7cd944d2f7401c635b3a45e8b576bac&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29
Failed on: ClickHouse#122697
Related: ClickHouse#115786

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review: a `storage_account_url` is recorded verbatim and may be a proxy whose
path prefix is not an account, so the first path segment of an arbitrary URL
proves nothing. Take it only when the host is an IPv4 address or a bare name
(Azurite, localhost); any other host that is not an Azure one reveals no
account and the connection-string check rejects it as unverifiable, instead of
reporting a mismatch against a made-up account. An emulator reached through a
dotted host name is rejected the same way; by IP or by a bare name it still
compares by account.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The connection-string branch tried to prove that the connection string's own
endpoint is equivalent to the recorded one (URL equality, then account names,
then host and path rules), and every rule had a shape it got wrong: host
aliases, hosts that reveal no account, proxy path prefixes, service paths that
CreateFromConnectionString() drops. Stop proving equivalence instead:
CreateFromConnectionString() takes the endpoint from the connection string
alone, so point the connection string at the recorded endpoint by replacing
its BlobEndpoint and let the key or SAS it carries authorise the reads there,
or fail with Azure's refusal if it belongs to another account. That is what
every other auth method and the S3 reader already do through
storage_account_url.

The recorded endpoint is reduced to a service URL first: query parameters (a
SAS of the source disk) are dropped, and an endpoint recorded as a connection
string (a source disk configured with one) is reduced to its blob endpoint.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
AzureBlobStorage::ConnectionParams makeSnapshotSourceConnectionParams(
const AzureBlobStorage::ConnectionParams & backup_connection_params, const String & endpoint, const String & blob_namespace)
{
auto connection_params = backup_connection_params;

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.

Because this starts from backup_connection_params, it also inherits the backup location's endpoint.add_account_name_to_url flag. That breaks a supported mixed-shape restore: if the backup is opened through a path-style endpoint (so this flag is true) but the snapshot was taken from a host-style source like https://acct.blob.core.windows.net, line 128 swaps in the host-style service_url and createForContainer() still appends /acct from the backup params. The source client then targets https://acct.blob.core.windows.net/acct/<container> instead of https://acct.blob.core.windows.net/<container>, so a same-account restore still fails.

Please rebuild the endpoint shape from service_url here — at minimum reset add_account_name_to_url after repointing the endpoint, and cover the path-style-backup / host-style-source combination with a regression test.

@hanfei1991 hanfei1991 added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-bugfix Pull request with bugfix, not backported by default labels Oct 5, 2026
{

#if CLICKHOUSE_CLOUD
/// Connection params for reading the objects a lightweight snapshot references, built from the endpoint

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.

Could we make the comment a bit shorter?

@hanfei1991
hanfei1991 added this pull request to the merge queue Oct 6, 2026
Merged via the queue into master with commit b0d7197 Oct 6, 2026
149 checks passed
@hanfei1991
hanfei1991 deleted the garrettthomaskth/azure-snapshot-reader-namespace-prefix branch October 6, 2026 15:27
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 6, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 6, 2026
hanfei1991 added a commit that referenced this pull request Oct 6, 2026
Cherry pick #122697 to 26.9: Fix restoring a lightweight snapshot from Azure when the source disk has a key prefix
robot-clickhouse added a commit that referenced this pull request Oct 6, 2026
…zure when the source disk has a key prefix
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 6, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 6, 2026
Backport #122697 to 26.8: Fix restoring a lightweight snapshot from Azure when the source disk has a key prefix
clickhouse-gh Bot added a commit that referenced this pull request Oct 6, 2026
Backport #122697 to 26.7: Fix restoring a lightweight snapshot from Azure when the source disk has a key prefix
clickhouse-gh Bot added a commit that referenced this pull request Oct 6, 2026
Backport #122697 to 26.9: Fix restoring a lightweight snapshot from Azure when the source disk has a key prefix
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 7, 2026
…hot from Azure when the source disk has a key prefix
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
…hot from Azure when the source disk has a key prefix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-backup Backup/restore infrastructure and backup formats. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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 v26.6-must-backport v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants