Skip to content

Use offset in performSinglepartUpload for Azure - #114975

Merged
alexey-milovidov merged 8 commits into
masterfrom
Fix_azure_use_offset
Sep 5, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
Fix_azure_use_offset

Conversation

@SmitaRKulkarni

@SmitaRKulkarni SmitaRKulkarni commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

Incremental backups to Azure Blob Storage wrote the wrong bytes for every file that is only partially copied.

performSinglepartUpload in copyAzureBlobStorageFile.cpp read from position 0 instead of offset, so it uploaded the beginning of each file instead of the tail. Restoring such a backup silently dropped all data written after the base backup.

copyAzureBlobStorageFile also lost its src_offset parameter, so that a range can no longer be dropped on the floor: its native-copy branch calls CopyFromUri / StartCopyFromUri, which carry no byte range and always transfer the whole source blob. Consequently BackupWriterAzureBlobStorage::copyFileFromDisk now takes the native copy only when the request covers the entire source and copies a range through buffers, exactly like BackupWriterS3::copyFileFromDisk. This guard is a consequence of the narrowed interface rather than a reproduced bug: BackupImpl dispatches only immutable-file entries to copyFileFromDisk, and those never have a partial base_size today, so no current backup path reached the native copy with a range. The data loss above is reproduced by the incremental Log table tests, which go through the ranged buffered upload.

Closes: #103193

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fixed incremental backups to Azure Blob Storage storing the beginning of each file instead of its tail. Restoring such a backup silently dropped all the data written after the base backup.


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

Version info

  • Backported to: 26.8.3.46, 26.7.7.32, 26.6.5.57, 26.3.32.11

@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2b0e5b7]

Summary: ✅


AI Review

Summary

The PR fixes incremental Azure backup range uploads by honoring offset in performSinglepartUpload, narrows copyAzureBlobStorageFile to whole-blob semantics so callers cannot silently request a ranged native copy, and adds focused integration coverage for the buffered incremental-backup paths that reproduced the data-loss bug. I did not find any remaining correctness, compatibility, or testing gaps in the current diff.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 2b0e5b7.

Metric Baseline Current Δ
Lines 88.70% 88.80% +0.10%
Functions 92.10% 92.10% +0.00%
Branches 81.10% 81.10% +0.00%

Changed lines: Changed C/C++ lines covered: 52/57 (91.23%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Aug 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2b0e5b729 with master 9b2537d77 (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

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Aug 28, 2026
`BackupWriterAzureBlobStorage::copyFileFromDisk` forwards `start_pos` and
`length` into `copyAzureBlobStorageFile`, but the native-copy branch of that
helper calls `CopyFromUri` / `StartCopyFromUri`, which carry no byte range and
always transfer the entire source blob. The requested range was therefore
silently ignored whenever `allow_azure_native_copy` was on, so an incremental
backup could store a whole file where only its tail belongs, and restoring it
would reconstruct the wrong bytes.

Guard the native copy the same way `BackupWriterS3::copyFileFromDisk` does: it
is used only when the request covers the entire source, measured with
`getEncryptedFileSize` for an encrypted source. `start_pos != 0` alone is not a
sound test, because a prefix `[0, length)` of a bigger file is a range too.
Ranged copies fall back to `BackupWriterDefault::copyFileFromDisk`, which reads
through buffers and honors the range.

To make the trap unrepeatable, `copyAzureBlobStorageFile` loses its `src_offset`
parameter: it now copies a whole blob, like `copyS3File`, and callers that need
a range use `copyDataToAzureBlobStorageFile` instead.

The new integration test reaches the native copy with a non-zero `start_pos`. A
`Log` data file on an Azure disk normally gets one object per `INSERT`, and a
multi-object source is already excluded from the native copy, so the table is
truncated and refilled by a single `INSERT` with `max_block_size = 1`: every row
lands in its own compressed block, the first block stays byte-identical to the
one the base backup holds, and the whole file is a single blob.
An Azure disk hands out random blob paths, so by default `BackupFileInfo` takes
the checksum of a file from its remote path (`canCalculateChecksumFromRemotePath`)
and cannot compute a prefix checksum at all, which leaves `base_size` at 0 and
makes every incremental backup copy whole files. The test therefore has to ask
for content checksums with `allow_checksums_from_remote_paths = 0`, otherwise it
never reaches the ranged copy it is meant to cover.

Verified against Azurite with a 26.7 server, which has neither fix: the restored
table comes back with one row instead of two. Disabling the native copy and
forcing the multipart upload -- the offset-correct path in that build -- restores
both rows, which is the route the fix now takes for a ranged copy.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Follow-up on my previous reply, after reproducing this against Azurite with a 26.7 server (neither fix present) — the bug is real and it loses data, but the route to it is narrower than the report says, and the test needed one more setting to reach it.

There is a second gate besides the multi-object one. BackupEntryWithChecksumCalculation::canCalculateChecksumFromRemotePath takes the checksum of a file from its remote path when areBlobPathsRandom(), which is exactly what an Azure disk does. A checksum derived from a remote path has no prefix form, so calculateNewEntryChecksumsIfNeeded yields no prefix_checksum, the HasPrefix branch in BackupFileInfo never matches, and base_size stays 0 — every file is copied whole. So with the default allow_checksums_from_remote_paths = 1, an incremental backup from an Azure disk never asks for a range in the first place.

With allow_checksums_from_remote_paths = 0 it does, and then the corruption is exactly as described. Reproduced end to end:

CREATE TABLE t (key UInt64, data String) ENGINE = Log SETTINGS storage_policy='blob_native_policy';
INSERT INTO t SELECT number, 'aaa' FROM numbers(1);   -- max_block_size = 1
BACKUP TABLE t TO AzureBlobStorage(...,'base_bk') SETTINGS allow_checksums_from_remote_paths = 0;
TRUNCATE TABLE t;
INSERT INTO t SELECT number, 'aaa' FROM numbers(2);   -- max_block_size = 1, still one blob
BACKUP TABLE t TO AzureBlobStorage(...,'incr_bk')
    SETTINGS base_backup = AzureBlobStorage(...,'base_bk'), allow_checksums_from_remote_paths = 0;
RESTORE TABLE t AS t_restored FROM AzureBlobStorage(...,'incr_bk');

data.bin is size = 60, base_size = 30, one object, so copyFileFromDisk reaches the native copy with start_pos = 30 and CopyFromUri uploads all 60 bytes. SELECT * FROM t_restored then returns a single row where the original has two — silent data loss. Repeating the incremental backup with allow_azure_native_copy = 0 and azure_max_single_part_upload_size = 1, i.e. the one upload path that already honored the offset in that build, restores both rows. That is the route the fix now takes for a ranged copy.

test_incremental_backup_restore_on_log_with_native_copy was updated in eea1615 to pass allow_checksums_from_remote_paths = 0 on both backups; without it the test still passes on unfixed code, because base_size never becomes non-zero.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114975&sha=42581e0c27fdd48645f31bdb01747e2c06d8d98b&name_0=PR&name_1=Docker%20keeper%20image and provide a fix in a separate PR. If the fix is already in progress, link it here.

It is unrelated to this pull request, which does not touch the Docker images: Docker keeper image failed while pulling the docker.io/library/ubuntu:22.04 and docker.io/library/alpine:latest base images, with failed to copy: httpReadSeeker: failed open: unexpected status from GET request to https://docker-images-prod.s3.dualstack.us-east-1.amazonaws.com/... 400 Bad Request. This is a Docker Hub registry error, and it hits many pull requests at once — 24 failures across 20 pull requests on 2026-08-26, and single ones on most days since — so the image build likely needs a retry around the base-image metadata fetch rather than a change here.

@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed unrelated to this pull request. Only the head-arm64 leg of Docker keeper image failed; every other variant, and all of Docker server image, passed on the same commit.

The retry is already in place and it declined this failure. From docker_keeper_image/job.log:

[2026-08-31 03:55:12] ERROR: failed to build: failed to solve: alpine: failed to resolve source metadata for docker.io/library/alpine:latest: failed to copy: httpReadSeeker: failed open: unexpected status from GET request to https://docker-images-prod.s3.dualstack.us-east-1.amazonaws.com/...: 400 Bad Request
[2026-08-31 03:55:12] Retry 1/2: command failed, exit code: 1
[2026-08-31 03:55:12] No retryable errors found, stopping retries

BUILDX_RETRY_ERRORS in ci/jobs/docker_server.py carries unexpected status from HEAD request but not the GET form of the same containerd blob fetch, and its status codes are 429 and 5xx only, so nothing in the list matches a 400 on httpReadSeeker: failed open.

It is per-request, as you read it. The amd64 leg of this same job resolved docker.io/library/ubuntu:22.04 and docker.io/library/alpine:latest in 1.3s each at 03:38:03, 78 seconds before the arm64 leg started. buildx then retried the fetch internally for 15m40s before reporting, and each invocation is bounded at 2700s in this job, so a second attempt still fits inside the existing bound.

Sending a separate PR that adds the missing signature. Both Docker image jobs share the list, so the server image leg is covered too.

@groeneai

Copy link
Copy Markdown
Collaborator

Fix PR: #117301

Rather than adding the GET spelling, I dropped the method from the token entirely. The phrase comes from one containerd format string, unexpected status from %s request to %s: %s, so the method is an interpolated field: the new token has the old one as a prefix, which makes it a strict superset and leaves nothing that was retried before unretried. Both Docker image jobs and both buildx invocations read the same list, so one edit covers them.

One correction to the breadth figure. Of the 24 Docker keeper image failures on 2026-08-26, 23 carry Failed to fetch, which is the apt-mirror class and already handled; only 1 carries this signature. Its own footprint over 45 days is 6 job runs across both image jobs and three workflows, with none on master.

@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

This PR only changes Azure blob-storage backup copy code (dropping the unused offset argument from copyAzureBlobStorageFile and routing partial-range copies through a buffered upload). None of that runs during a TPC-H query. The single flagged Q17 "improvement" (-34.0%, median 100 -> 66 ms) is on a query the deterministic history flags as noisy, and with the base run's measurements themselves being highly variable, this is run-to-run variance rather than a real speedup — downgraded to not_sure. No query-execution regressions or improvements are attributable to this change.

clickbench

🟢 No significant changes

tpch_adapted_1_official

⚠️ 1 inconclusive

Flagged queries (1 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 17 not_sure 100 66 -34.0% <0.0001 PR only changes Azure blob-storage backup copy plumbing (copyAzureBlobStorageFile offset handling); it does not touch the TPC-H Q17 SELECT execution path, so this -34.0% shift on a noisy query is variance, not a PR effect.

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.

Debug info
  • StressHouse run: b30395a5-053a-40b4-ab8e-1012a282c74d
  • MIRAI run: b19a8d93-ae40-4fad-b735-8607131c86a9
  • PR check IDs:
    • clickbench_1260451_1788577696
    • clickbench_1260457_1788577696
    • clickbench_1260463_1788577696
    • tpch_adapted_1_official_1260474_1788577696
    • tpch_adapted_1_official_1260487_1788577696
    • tpch_adapted_1_official_1260522_1788577696

pull Bot pushed a commit to Lobinson1/ClickHouse that referenced this pull request Sep 3, 2026
…quest method

`Docker keeper image` failed resolving its two base images from Docker Hub with
`httpReadSeeker: failed open: unexpected status from GET request to ...: 400 Bad
Request`, and the retry did not fire: `No retryable errors found, stopping
retries`, `command failed after 1/2 attempt(s)`.

`BUILDX_RETRY_ERRORS` carried `unexpected status from HEAD request`, and its
status-code entries are 429/5xx only, so nothing matched a 400 on a GET. The
method is an interpolated field of a single containerd format string,
`unexpected status from %s request to %s: %s`, so the entry only ever covered
whichever method happened to be observed when it was written. Dropping the
method from the token makes it a strict superset of the entry it replaces: the
removed string contains the new one as a prefix, so every stderr line retried
before is still retried.

A second attempt would have worked. The failing leg died at metadata resolution
after 951 s, while `head-alpine-arm64`, same platform and same two base images,
resolved both fresh in 0.6 s each only 9 s later. So this was one invocation
stuck on one poisoned request pair, and the 400 was transient, which is also why
a status-code allowlist is unsound for this failure mode.

The token accepts a permanent 4xx too. That is bounded by `BUILDX_RETRIES = 2`,
it is already the status quo for HEAD, and `buildx_timeout` already divides the
remaining job budget by 2 attempts, so a second attempt consumes budget the model
already reserves. Neither the attempt count nor the timeout divisor changes here.

Validated by replaying the captured stderr through `Shell.run`: master's list
matches 0 of its 17 runtime tokens and stops at 1/2 attempts, byte-identical to
the CI log, while the new token matches 3 lines and reaches 2/2. Changing only
GET to HEAD in that same capture makes master's own unmodified list retry it,
which isolates the request method as the whole defect. Genuine permanent buildx
failures, including a live capture, still fail fast on the first attempt.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114975&sha=42581e0c27fdd48645f31bdb01747e2c06d8d98b&name_0=PR&name_1=Docker%20keeper%20image
PR: ClickHouse#114975
Related: ClickHouse#114975 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
The comment claimed the test reaches the native-copy branch of
`BackupWriterAzureBlobStorage::copyFileFromDisk` with a partial range.
It does not: a `Log` table backs its data files with
`BackupEntryFromAppendOnlyFile`, and `BackupImpl` hands only
immutable-file entries to `copyFileFromDisk`, so the incremental
backup goes through `copyDataToFile`, i.e. the ranged buffered
upload fixed in `performSinglepartUpload`. The whole-object guard in
`copyFileFromDisk` is required because `copyAzureBlobStorageFile`
no longer carries an offset, but no backup entry with a partial
range is dispatched to it today.

Addresses the AI review thread on this test.
@clickhouse-gh clickhouse-gh Bot added the comp-backup Backup/restore infrastructure and backup formats. label Sep 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 5, 2026
Merged via the queue into master with commit 957fccf Sep 5, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the Fix_azure_use_offset branch September 5, 2026 11:45
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 5, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 5, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Sep 5, 2026
Cherry pick #114975 to 26.3: Use offset in performSinglepartUpload for Azure
@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 Sep 5, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 5, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 5, 2026
Backport #114975 to 26.8: Use offset in performSinglepartUpload for Azure
alexey-milovidov added a commit that referenced this pull request Sep 5, 2026
…-buffer-overflows

Conflicts in `BackupIO_AzureBlobStorage.cpp` and `copyAzureBlobStorageFile.h`:
master (#114975) removed the `src_offset` parameter of `copyAzureBlobStorageFile` and made
`BackupWriterAzureBlobStorage::copyFileFromDisk` take the Azure native copy only for whole-object
copies, which is exactly the change requested by the AI review on this branch; keep master's
version of both and thread this branch's `src_etag` argument through it.
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 5, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 5, 2026
Backport #114975 to 26.6: Use offset in performSinglepartUpload for Azure
alexey-milovidov added a commit that referenced this pull request Sep 5, 2026
Backport #114975 to 26.3: Use offset in performSinglepartUpload for Azure
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 5, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 5, 2026
Backport #114975 to 26.7: Use offset in performSinglepartUpload for Azure
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-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

performSinglepartUpload ignores offset member, uploading wrong data for incremental Azure backups

6 participants