Skip to content

Bound a sequential Azure read by the locally set right bound, not by the response length - #120910

Merged
alexey-milovidov merged 27 commits into
masterfrom
azure-read-bound-locally
Oct 4, 2026
Merged

alexey-milovidov merged 27 commits into
masterfrom
azure-read-bound-locally

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Related: #115706
Related: #120419

The sequential read path of ReadBufferFromAzureBlobStorage trusted the remote endpoint about how much data the current download may deliver: initialize derived total_size from BodyStream::Length, which is the Content-Length chosen by the endpoint. With read_until_position = 100, offset = 0 and a 64-byte reading buffer, an endpoint that answers the 100-byte ranged request with Content-Length = 128 made nextImpl hand out 64 bytes twice and only trip the right-bound check (Attempt to read beyond right offset) on the following call, so 28 bytes from outside the requested range had already escaped into the caller. With a reading buffer larger than the range, all 28 escape in a single call. The layers above (ReadBufferFromRemoteFSGather, AsynchronousBoundedReadBuffer, the caches) lay out the next object of a file, or the next segment, right behind the right bound, so these bytes are delivered under offsets that belong to something else.

The bound of the current download is now derived from read_until_position, which is set locally by the caller, and the Content-Length of the response can only shorten it. The size of the blob from the same response is deliberately not used for this: it comes from the same untrusted place, and an endpoint that answers a ranged request with 200 OK would make it truncate a legitimate read. A read without a right bound keeps its previous behaviour.

setReadUntilPosition also gave up nothing when the caller tightened the bound: it only set read_until_position and dropped initialized, so the bytes that the previous, wider bound allowed to buffer stayed in the working buffer and were still handed out before the right-bound check could fire on the next refill. It now discards them and rewinds offset to the position the caller has read up to, the same way setReadUntilEnd and ReadBufferFromS3::setReadUntilPosition do, so a new bound applies before any further byte is exposed, as supportsRightBoundedReads promises.

src/Disks/tests/gtest_azure_read_buffer.cpp gains regressions that drive nextImpl through setReadUntilPosition against a fake Azure HTTP transport whose response is longer than the requested range, with a reading buffer both smaller and larger than the range, plus the exact and short responses as controls. Without the change the overlong cases fail with Attempt to read beyond right offset (128 > 99).

AzureObjectStorage::readObject sets no right bound of its own, so a whole-object read had its size decided by the response as well. It now passes the size recorded in the metadata, StoredObject::bytes_size, as the bound (UnknownSize is the only "not determined" sentinel; 0 is a genuinely empty object, which is read without a request and whose metadata comes from the properties in readSmallObjectAndGetObjectMetadata). The same size is handed to the buffer as its file_size, so getFileSize reports the size the read is bounded by instead of asking the endpoint with a live GetProperties, which would describe the current generation and make CachedInMemoryReadBufferFromFile throw UNEXPECTED_END_OF_FILE on a blob grown since the listing.

A locally known size is only a correct bound for the generation of the object it was recorded for: a blob replaced with a longer one after the listing would otherwise be silently truncated to the stale size. So, as ReadBufferFromS3 does, every Download is pinned to StoredObject::etag with the If-Match access condition, the ETag of the response is checked against it for endpoints that ignore the condition, and the 412 Precondition Failed is reported as the new AZURE_OBJECT_CHANGED_DURING_READ error, which is not retried. The zero-byte path checks the ETag of the properties instead. A blob listing spells the ETag without the quotes that the ETag header of a download carries, so both spellings are canonicalized to the quoted one (ReadBufferFromAzureBlobStorage::quotedETag) before they are compared or sent as If-Match. An object whose size is listed as zero is read without a download, so its generation is checked on the properties instead, in readObject as well as in readSmallObjectAndGetObjectMetadata.

The pin is controlled for table reads by a new setting, azure_validate_etag_on_read (default on), the Azure counterpart of s3_validate_etag_on_read; it also refreshes the metadata placeholder of azureBlobStorageCluster, which skips the metadata probe. That placeholder is never used as a bound: createReadBuffer passes StoredObject::UnknownSize unless the metadata was really fetched, because the placeholder's size_bytes == 0 would otherwise read every file as empty on the initiator when cluster_table_function_split_granularity = 'bucket'.

This is one of the independent parts of #115706, which was reverted in #120419; it contains only the code related to this defect. The positioned read path, readBigAt, was fixed separately in #119054.

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

Fix a buffer over-read on the sequential read path from Azure Blob Storage: an endpoint that answers a ranged request with more data than was requested could deliver bytes from outside the requested range to the caller. The end of a read is now decided by the locally set right bound, not by the Content-Length of the response, and a read is pinned to the listed generation of the blob with If-Match, so an object replaced during a read fails with AZURE_OBJECT_CHANGED_DURING_READ instead of being truncated (new setting azure_validate_etag_on_read, enabled by default).


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

Version info

  • Merged into: 26.10.1.1483-master (included in 26.10 and later)
  • Backported to: 26.8.17.4, 26.7.22.4, 26.3.42.2

…the response length

`ReadBufferFromAzureBlobStorage::initialize` derived `total_size` from
`BodyStream::Length`, which is the `Content-Length` chosen by the remote endpoint.
With `read_until_position = 100`, `offset = 0` and a 64-byte reading buffer, an
endpoint that answers the 100-byte ranged request with `Content-Length = 128` made
`nextImpl` hand out 64 bytes twice and only trip the right-bound check on the
following call, so 28 bytes from outside the requested range had already escaped into
the caller. With a reading buffer larger than the range, all 28 escape in a single call.

Derive the bound of the current download from `read_until_position`, which is set
locally by the caller, and let the length of the response only shorten it. The size
of the blob from the same response is not used for this: it comes from the same
untrusted place, and an endpoint that answers a ranged request with `200 OK` would
make it truncate a legitimate read.

`src/Disks/tests/gtest_azure_read_buffer.cpp` gains regressions that drive `nextImpl`
through `setReadUntilPosition` against a fake Azure HTTP transport whose response is
longer than the requested range, with a reading buffer both smaller and larger than
the range. Without the change they fail with
`Attempt to read beyond right offset (128 > 99)`.

This is one of the independent parts of
#115706, which was reverted in
#120419. The positioned read path,
`readBigAt`, was fixed separately in
#119054.
@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1d6b7c4]

Summary: ✅


AI Review

Summary

This PR hardens Azure object reads around one invariant: the bytes a caller may observe must be bounded by locally known metadata, not by whatever Content-Length or object generation the endpoint happens to serve. The current head carries that invariant through the sequential reader, whole-object readObject, zero-byte fast paths, page-cache sizing, If-Match/ETag pinning, cluster placeholders, and the lazy-materialization reread gate, and it adds focused regressions at each boundary where earlier rounds found holes. I re-checked the current code against the prior review threads and do not see any remaining correctness, safety, or contract issues in the diff.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 1d6b7c4.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.80% 79.70% -0.10%

Changed lines: Changed C/C++ lines covered: 188/205 (91.71%) · 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 Sep 18, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-azure Azure Blob Storage integration (credentials, multipart, Azure-specific IO). label Sep 18, 2026
alexey-milovidov and others added 3 commits September 19, 2026 21:05
`ReadBufferFromAzureBlobStorage::setReadUntilPosition` only set
`read_until_position` and dropped `initialized`, leaving `working_buffer` and
`offset` alone. The bytes that the previous, wider bound allowed to buffer stayed
in the working buffer, so a caller that tightened the bound after a partial read
still got them: fill 64 bytes for a 100-byte bound, consume 10, call
`setReadUntilPosition(20)`, and `ReadBuffer::read` keeps returning bytes `10..63`
before the `read_until_position < offset` guard fires on the later refill. That
breaks the `supportsRightBoundedReads` contract, which promises that the new
bound applies before any further bytes are exposed.

Give up the buffered bytes and rewind `offset` to the position the caller has read
up to, the same way `setReadUntilEnd` and `ReadBufferFromS3::setReadUntilPosition`
do, so the next `nextImpl` downloads the range under the new bound. Setting the
same bound again is now a no-op instead of a forced re-download.

`src/Disks/tests/gtest_azure_read_buffer.cpp` gains a range-aware fake transport
and regressions that tighten the bound after a partial read (with a well-behaved
and with an overlong endpoint) and check that `eof` is reported exactly at the new
bound, plus a widening case as a control. Without the change the tightening cases
read 54 bytes past the new bound and then throw
`Attempt to read beyond right offset`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failures and provide a fix in a separate PR (if a fix is already in progress, link it here):

Both are unrelated to this PR. The only server-side code it changes is ReadBufferFromAzureBlobStorage, which is instantiated exclusively by the Azure object storage; the remaining file is a gtest that is not linked into the server. file_table_function only runs INSERT INTO FUNCTION file(...) over local files, and timeseries_to_grid_aggregation_functions is pure aggregation — neither can reach the changed code. The raw all-query-metrics.tsv for all six shards also shows 0 changed and 0 unstable queries out of 3487 by the compare.sh thresholds, so only the dashboard's newer heuristic flagged these two, both on short (23ms / 81ms) queries. Likely another instance of #100759.

Build profile diff is the known infrastructure error, tracked by #121048 and #118708.

I have merged master (the branch was 436 commits behind) and pushed ad8643740f4a; unit_tests_dbms builds and all 9 AzureRead* tests pass locally on the merged tree.

@groeneai

Copy link
Copy Markdown
Collaborator

Both rows are covered by an open fix of mine, so no new PR is needed: #121090 ("Perf CI: fail a master_head shard only when its own report also calls the query slower"). I checked that it clears both, on this run's own artifacts.

Measured on d6c583d, from the two shards' all-query-metrics.tsv:

Shard Dashboard row in-tree diff its learned changed_threshold
2/6 file_table_function #24 (+553.8%) 5.538 10.6
6/6 timeseries_to_grid_aggregation_functions #8 (+49.9%) 0.499 0.91

Each query is inside its own bar, which is 1.5x the 0.99 quantile of abs(diff) over a month of earlier master runs of that same query, so neither is in its shard's slower list. For file_table_function the learned bars of the ten measured queries span 0.33 to 10.6 in this run: a 23 ms INSERT INTO FUNCTION file(...) on that runner is expected to move by hundreds of percent. (6/6's report does display six other queries of that test above the display bar, five of them demoted by the confirmation rerun, but not #8.) The dashboard judges one measurement episode against a fixed per-metric minimum and does not use that per-query envelope, and #120927 made its tier the gate, consulted for every measured query rather than for the slower ones.

#121090 restores the conjunction: the dashboard is consulted only for queries the shard's own report published as slower (diff > changed_threshold and diff >= stat_threshold). Replaying that predicate over all six all-query-metrics.tsv of this run gives 0 qualifying slowdowns out of 3487 queries, so both shards skip the gate and pass. It is open with reviewers requested.

One difference from the same ask on #120488: there the learned thresholds were missing (the CIDB fetch for them timed out, and the empty file leaves the bare 0.15/0.25 floors), so that dashboard row did sit in the in-tree slower list and #121090 alone does not clear it. Here the fetch succeeded, which is why the bars above are 10.6 and 0.91 instead of 0.15; the fix for the timeout is a separate change under review on my side and I will link it on #120488.

… range is a bound

`ReadBufferFromAzureBlobStorage` used `0` as the "no bound" sentinel for
`read_until_position`, so `setReadUntilPosition(0)` - the empty range `[0, 0)` -
was taken for an unbounded read: `nextImpl` and `initialize` both tested the
bound for being nonzero, and the reader delivered the contents of the blob
instead of reporting EOF, contradicting `supportsRightBoundedReads`.

The bound is now a `std::optional<size_t>`, which is empty only when the caller
has not set one or has called `setReadUntilEnd`. The single call site that
passed a literal `0` for "no bound", `AzureObjectStorage::readObject`, passes
`std::nullopt`.

Three regressions in `gtest_azure_read_buffer.cpp`: `EmptyRange` (a bound of
zero reports EOF without issuing a download at all), `EmptyRangeThenReadUntilEnd`
(`setReadUntilEnd` still lifts it) and `TightenedToEmptyRangeAfterPartialRead`
(a bound below the current position followed by a `seek`, which
`ReadBuffer::setReadUntilPosition` recommends supporting). All three fail on a
control binary that keeps the old zero sentinel.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai — noted, #121090 covers both performance rows, so nothing to do here on that front.

On the new head ad864374 the only other red is 05227_storage_settings_unknown_name in Stateless tests (amd_debug, parallel) and Stateless tests (arm_binary, parallel). It is unrelated to this PR (nothing here touches SETTINGS handling; the only server code this PR changes is ReadBufferFromAzureBlobStorage) and it is already being fixed by #121163, which is still open, so it cannot be cleared by merging master yet.

I have pushed ccf4cb73, which adopts the AI-Review finding: the right bound is now a std::optional<size_t> instead of using 0 as the "no bound" sentinel, so setReadUntilPosition(0) is honoured as the empty range [0, 0) rather than being taken for an unbounded read. Three new gtest regressions cover it, and all fail on a control binary that keeps the old sentinel.

alexey-milovidov and others added 2 commits September 20, 2026 20:13
…d offset

The endpoint chooses the range it answers a ranged request with. It is
allowed to ignore the requested range and answer `200 OK` with the whole
blob, and a misbehaving one can answer with a different range altogether.
In either case the body was handed to the caller as if it were the bytes
at the requested offset: after `seek(100)` and `setReadUntilPosition(200)`
a response starting at byte `0` delivered bytes `0..99` under offsets
`100..199`, a wrong slice of the blob.

`checkResponseStartsAtRequestedOffset` compares the range of the response
with the offset that was requested and rejects a mismatch, in both
`initialize` (the sequential path) and `readBigAt`. There is no fallback
that skips the unwanted prefix: only the correct slice is accepted.

New gtests `AzureReadUntilPosition.RejectsResponseStartingAtWrongOffset`
and `AzureReadBigAt.RejectsResponseStartingAtWrongOffset` read from a
nonzero offset through `RangeResponseTransport`, which answers every
request with the blob from its beginning, and
`AzureReadUntilPosition.SeekToNonZeroOffsetWithHonestEndpoint` pins that
an endpoint honouring the range still works. A control binary with the
check removed fails both rejection tests; 15/15 `AzureRead*` pass with it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed ab915b227519.

It adopts the AI-Review Blocker — a ranged response was still trusted to start at the requested offset, so after seek(100) + setReadUntilPosition(200) an endpoint answering from byte 0 handed out bytes 0..99 under offsets 100..199. checkResponseStartsAtRequestedOffset now compares DownloadBlobResult::ContentRange with the requested offset and throws AZURE_BLOB_STORAGE_ERROR on a mismatch, in initialize and in readBigAt; details and the control-binary proof are in the review thread. 15/15 AzureRead* pass, 2 new rejection tests fail on a control without the check.

It also merges master (the branch was 38 commits behind), which pulls in #121163 — merged in the meantime — so the only remaining red, 05227_storage_settings_unknown_name on amd_debug and arm_binary, is cleared on the new head. The performance rows are covered by #121090 as @groeneai explained above, so nothing else is outstanding here.

@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1d6b7c4da with master c9c24473f (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

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

Job report

alexey-milovidov and others added 2 commits September 21, 2026 05:02
Conflict in `src/Disks/IO/ReadBufferFromAzureBlobStorage.cpp`: master has
landed `checkReturnedRange`, which does exactly what the
`checkResponseStartsAtRequestedOffset` helper added here did - it compares
`ContentRange.Offset` of the response with the requested offset and throws,
in both `initialize` and `readBigAt`. Resolved by keeping master's helper and
dropping the duplicate one, along with the two gtests that only pinned that
behaviour, which master's new `gtest_azure_read_buffer_range_check.cpp`
covers. The rest of this PR - bounding a sequential read by the locally set
`read_until_position` instead of the response length - is unaffected.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…metadata

`AzureObjectStorage::readObject` passed `std::nullopt` as `read_until_position`,
so a plain whole-object read had no trusted right bound at all and its size came
from the length of the response, which is exactly what this PR set out to stop
trusting. An endpoint answering a request for a 100-byte object with 128 bytes
handed the caller 28 bytes past the end of the object on the default path used
by `ObjectStorageSourceReader::open` and `readSmallObjectAndGetObjectMetadata`.

`StoredObject::bytes_size` is the locally known bound for that case, so it is now
threaded through as the initial `read_until_position`, with the `UnknownSize`
sentinel (and `0`) mapped to `std::nullopt` exactly as in
`S3ObjectStorage::readObject`.

Two gtests on the `readObject` path: `AzureReadObject` checks that a 100-byte
object served by a 128-byte response yields 100 bytes, and that an object of
unknown size still reads to the end. A control build keeping `std::nullopt`
fails the first with `Which is: 128` against `Which is: 100`; 19/19 `AzureRead*`
pass with the fix.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure and provide a fix in a separate PR (if a fix is already in progress, link it here):

It is unrelated to this PR. The throw is in src/Planner/findParallelReplicasQuery.cpp:639, reached by a fuzzed RIGHT JOIN under INTERSECT inside viewExplain('EXPLAIN', ...) with parallel_replicas_prefer_local_join = 1. The only server-side code this PR changes is ReadBufferFromAzureBlobStorage and the Azure object storage that instantiates it; the remaining file is a gtest that is not linked into the server. Nothing on that query path touches Azure blob storage, and the other seven AST fuzzer jobs on the same commit are green.

The two closed CI-matching issues for this message, #119408 and #113292, were both closed on 2026-09-13 with no closing commit, and the first has been cross-referenced by several PRs hitting it since, so the family looks like it is recurring on master rather than fixed. It may need a fresh issue.

Pushed in the meantime: merged master (the branch was 284 commits behind and CONFLICTING) and adopted the AI Review blocker, in 5d67836. unit_tests_dbms builds and 19/19 AzureRead* pass locally on the merged tree.

@groeneai

Copy link
Copy Markdown
Collaborator

Fix in progress: #110020, and it targets exactly the throw you pointed at. findParallelReplicasQuery.cpp:639 fires when findTableForParallelReplicas returns null. #110020 patches that function and getSupportingParallelReplicasQueries to carry the per-(sub)query context through both traversals, so a branch whose own SETTINGS opted out of parallel replicas is no longer picked by the outer pass and then rejected by the inner one.

I verified it against this shape instead of assuming. On master 8467884689659 a reduced INTERSECT ALL query reaches the same throw site, and with #110020 applied it returns a result. Reduced reproducer and the A/B: #120908 (comment)

Why the family keeps recurring: #110020 is green and mergeable, open since 2026-07-10, and in those 73 days no human review has ever been requested on it. The only earlier review_requested event on it is Copilot, on 2026-08-03. Nothing technical is blocking it. I have just requested review from devcrafter and KochetovNicolai, the comp-parallel-replicas owners with the most history in the two files it changes.

On the two closed issues, the measured picture supports your reading. Both were closed at 2026-09-13T08:54:17Z and 08:54:18Z, one second apart, by you, with state_reason: completed and no closing commit, so it looks like a bulk sweep rather than a fix landing. #119408 has picked up 6 cross-references in the 8 days since (#119846, #108721, #118427, #86431, #120908, and this PR), 5 of them still open.

I would reopen #113292 rather than file a fresh issue. It is titled for this exact shape, a RIGHT JOIN whose right side has no eligible table, it carries a deterministic reproducer that needs no fuzzer, and it has 35 cross-references. A fresh issue would start from zero and split that history. Filing one also needs approval on my side, whereas the reopen is yours to make since you closed it. Tell me which you prefer and I will follow up.

`AzureObjectStorage::readObject` mapped both `StoredObject::UnknownSize` and
`0` to "no right bound". `UnknownSize` is the default-constructed value of
`StoredObject::bytes_size`, so it is the only sentinel a caller that does not
know the size leaves behind; `bytes_size == 0` describes a genuinely empty
object and is a bound like any other.

With `0` taken for "unknown", an empty object was read unbounded, so an
endpoint answering the `GET` with a non-empty body handed the caller bytes of
an object whose trusted metadata says it has none - exactly the leak this
change is about, on the one input where the bound is tightest.

`S3ObjectStorage::readObject` keeps mapping `0` to "no bound" because
`ReadBufferFromS3::read_until_position` is a plain `size_t` whose `0` already
means "unbounded", so it cannot express the empty range at all.
`ReadBufferFromAzureBlobStorage` can, since the bound became a
`std::optional<size_t>` in an earlier round of this review.

New regression `AzureReadObject.EmptyObjectReadsAsEmpty`: a `StoredObject`
of size `0` against an endpoint serving 128 bytes must read as empty. A
control build keeping the old condition fails it; 20/20 `AzureRead*` pass
with the fix.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai — your reading is right on both counts, thanks for measuring it rather than assuming.

I have reopened #113292 rather than filing a fresh one, for the reasons you gave: it is titled for exactly this shape, it carries a deterministic reproducer that needs no fuzzer, and a new issue would split its 35 cross-references. #119408 can stay closed as the fuzzer-reported duplicate of it. My close on 2026-09-13 was a sweep, not a fix landing, as the one-second gap between the two shows.

On #110020 — green, mergeable, and open since 2026-07-10 with no human review ever requested is not a state it should be in for a fix to a recurring logical error. Requesting devcrafter and KochetovNicolai was the right move; I will look at it myself as well.

Pushed c87294e here in the meantime, adopting the remaining AI Review finding: AzureObjectStorage::readObject mapped both StoredObject::UnknownSize and 0 to "no right bound", but UnknownSize is the default-constructed value and therefore the only sentinel, so bytes_size == 0 is a genuinely empty object and was being read unbounded. Only UnknownSize maps to std::nullopt now, with a regression that a control build fails; 20/20 AzureRead* pass.

The other finding of that round — threading expected_file_size into BackupWriterAzureBlobStorage::readFile — I declined with the reasoning in the thread: BackupWriterS3::readFile passes that value as ReadBufferFromS3's non-bounding file_size hint while passing 0 for read_until_position, and using it as Azure's hard right bound would make the eof check in BackupWriterDefault::fileContentsEqual true by construction, so a longer lock file whose prefix matches would be accepted as our own.

No failed checks on the previous head 5d67836, so the AST fuzzer red above is cleared as far as this branch is concerned.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 4, 2026
robinld pushed a commit to robinld/ClickHouse that referenced this pull request Oct 4, 2026
Address the review of ClickHouse#123379:

- `.claude/tools/fetch_ci_report.js` with a PR URL expanded the all-green `PR`
  workflow into all its ~146 green job reports even when the `MergeQueueCI`
  run of a PR rejected by the merge queue contributed the failed job, burying
  the one failure that matters. An all-green top-level report is now expanded
  only when no other workflow has failed jobs; for the merge-queue rejection of
  ClickHouse#120910 the output shrinks from
  147 reports to the single failed `Build (amd_binary)` job.
- The `continue-pr` and `continue-pr-auto` skills suggested building the log
  URL as `.../mergequeueci/<job>/job.log`, but Praktika stores attached files
  under normalized sub-result directories, so such a URL returns
  `AccessDenied`. They now say to follow the `links` of the failed results
  (as printed by `fetch_ci_report.js`, also with `--links`) or to use
  `--download-logs`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged via the queue into master with commit 8c71394 Oct 4, 2026
150 checks passed
@alexey-milovidov
alexey-milovidov deleted the azure-read-bound-locally branch October 4, 2026 02:03
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added 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 labels Oct 4, 2026
alexey-milovidov added a commit that referenced this pull request Oct 4, 2026
…nly the core bound fix

The original PR #120910 builds on Azure
reader changes that are not in 26.3 (#119054,
#120955, #120963,
`s3_validate_etag_on_read`, `LazyReadFromObjectStorageSource`, the `gtest_azure_read_buffer`
fake transport). Resolved by taking the 26.3 tree for every touched path and porting only the
fix itself to `ReadBufferFromAzureBlobStorage`:

- the bound of the current download (`total_size`) is the locally set `read_until_position`,
  and the `Content-Length` of the response can only shorten it;
- `setReadUntilPosition` discards the bytes buffered under the previous, wider bound and
  rewinds `offset`, so a tightened bound takes effect immediately.

Not backported: `If-Match` pinning with `azure_validate_etag_on_read` and the
`AZURE_OBJECT_CHANGED_DURING_READ` error code, the `std::optional` right bound, the
`file_size` constructor argument, and the tests that depend on those (the gtest file does
not exist in 26.3, `05259_lazy_materialization_azure_etag_pinned`, the integration test).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll4 added a commit that referenced this pull request Oct 4, 2026
Cherry pick #120910 to 26.3: Bound a sequential Azure read by the locally set right bound, not by the response length
robot-clickhouse added a commit that referenced this pull request Oct 4, 2026
…y set right bound, not by the response length
alexey-milovidov added a commit that referenced this pull request Oct 4, 2026
Resolve the conflicts of the cherry-pick of #120910 to 26.7. The release
branch lacks several prerequisites of the original change, so only its own
part is kept:
- `checkReturnedRange`, the premature-end-of-response handling and the lazy
  `getBlobClient` are not on 26.7; the `ETag` pinning and the local right
  bound are applied to the existing `blob_client` code instead.
- Lazy materialization from object storage is not on 26.7, so the changes to
  `LazyReadFromObjectStorageSource`, `canUseLazyMaterialization` and the test
  `05259_lazy_materialization_azure_etag_pinned` are dropped.
- `gtest_azure_read_buffer.cpp` is not on 26.7 (it came with #119054, which is
  not backported), so it is not added here.
- The new setting `azure_validate_etag_on_read` is recorded in the "26.8"
  block of `SettingsChangesHistory.cpp`, as other backported settings are.
robot-ch-test-poll3 added a commit that referenced this pull request Oct 4, 2026
Cherry pick #120910 to 26.7: Bound a sequential Azure read by the locally set right bound, not by the response length
robot-clickhouse added a commit that referenced this pull request Oct 4, 2026
…y set right bound, not by the response length
alexey-milovidov added a commit that referenced this pull request Oct 4, 2026
…o 26.8

The cherry-pick of #120910 conflicted because
26.8 lacks the prerequisite Azure read fixes that landed on `master` first:
#119054 (lazy blob client, `readBigAt` fix, and
the creation of `gtest_azure_read_buffer.cpp`),
#120955 (`checkReturnedRange`) and
#120963 (reopen on a premature end of a bounded read).

Resolution:
- `ReadBufferFromAzureBlobStorage` is the 26.8 version with the changes of #120910 applied on
  top: `read_until_position` becomes `std::optional<size_t>`, the current download is bounded by
  `getTotalSizeOfCurrentDownload`, `setReadUntilPosition` drops the bytes buffered past a tighter
  bound, and every `Download` is pinned with `If-Match` to `expected_etag`, with the `ETag` of the
  response checked and `412` reported as `AZURE_OBJECT_CHANGED_DURING_READ`. The `file_size`
  argument is reported by `tryGetFileSize`.
- `AzureObjectStorage::readObject` uses `connection_params.getContainer` as in 26.8.
- `AZURE_OBJECT_CHANGED_DURING_READ` keeps the code 1021 from `master`; `END` is raised to it.
- `azure_validate_etag_on_read` is declared in the 26.8 style, with its history entry in the
  `26.10` section of `SettingsChangesHistory.cpp`.
- `gtest_azure_read_buffer.cpp` is added with the tests of #120910 only. The tests that belong to
  the prerequisites (`AzureReadBigAt.DoesNotTrustResponseLength`,
  `AzureReadBigAt.ReturnsAccumulatedCountOnTruncatedResponse`,
  `AzureReadUntilPosition.ShortRangeResponse`) are dropped, the `AzureObjectStorage` constructor
  takes the 26.8 `auth_method` argument, and `AzureReadBigAt.RejectsReplacedBlobThroughIfMatch`
  calls `getFileSize` first, because in 26.8 that is what creates the blob client for `readBigAt`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 4, 2026
Cherry pick #120910 to 26.8: Bound a sequential Azure read by the locally set right bound, not by the response length
robot-clickhouse added a commit that referenced this pull request Oct 4, 2026
…y set right bound, not by the response length
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 4, 2026
valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Oct 4, 2026
Master's ClickHouse#120910 pins Azure reads to the listed generation inside
ReadBufferFromAzureBlobStorage itself, so master's version of that buffer
replaces the branch's own If-Match code. It reports a replaced blob as
AZURE_OBJECT_CHANGED_DURING_READ, so the queue now treats that code like
FILE_CHANGED_DURING_READ and S3_OBJECT_CHANGED_DURING_READ; otherwise a
rewritten Azure object would be charged to the retry budget.

Master also made read_until_position an optional where 0 is an empty
range, so the read-and-write copy fallback now passes no bound instead
of 0. createReadBuffer pins under either per-backend validate setting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Oct 4, 2026
Backport #120910 to 26.8: Bound a sequential Azure read by the locally set right bound, not by the response length
alexey-milovidov added a commit that referenced this pull request Oct 4, 2026
Backport #120910 to 26.3: Bound a sequential Azure read by the locally set right bound, not by the response length
PedroTadim added a commit that referenced this pull request Oct 5, 2026
Backport #120910 to 26.7: Bound a sequential Azure read by the locally set right bound, not by the response length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-azure Azure Blob Storage integration (credentials, multipart, Azure-specific IO). 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.

4 participants