Repository navigation
Reopen a bounded Azure read whose response ends before the right bound - #120963
Conversation
`ReadBufferFromAzureBlobStorage::nextImpl` took the end of the response body as the end of the data. For a read with a right bound that is wrong: the bound is set locally by the caller, and every layer above the buffer takes it as the length of the data, so an endpoint or a proxy that caps its responses - or a blob that is shorter than the size it was listed with - silently truncated the file at the end of the first response. A response that ends before the bound is now a premature end: the download is reopened at the offset the read has reached and counted against `max_single_read_retries`, and when the endpoint keeps ending its responses before the bound the read fails with `UNEXPECTED_END_OF_FILE` instead of returning truncated data. A read without a right bound keeps its behaviour. The amount left of the current download is measured per attempt, so a reopened download is read from where it was reopened. `src/Disks/tests/gtest_azure_read_buffer_premature_end.cpp` reassembles a 100-byte blob from an endpoint that caps every response to 40 bytes, fails on a blob truncated at 40 bytes after the retries are spent, and checks that an exact response and an unbounded read are not reopened. This is one of the independent parts of #115706, which was reverted in #120419.
|
Workflow [PR], commit [e62ce35] Summary: ✅
AI ReviewSummaryThis PR fixes bounded sequential Azure reads so a response that ends before the requested right bound is reopened instead of being treated as EOF, and it adds focused regression coverage for capped responses, truncated blobs, range-ignoring reopens, and overlong responses. I did not find a remaining correctness, compatibility, or test-coverage gap in the current diff. Final Verdict✅ Approve. LLVM Coverage ReportMeasured on commit e62ce35.
Changed lines: Changed C/C++ lines covered: 31/33 (93.94%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
An endpoint that caps its responses ends every one of them before the right bound, so a read of more than the cap is a correct read assembled from several responses. The reopen that follows the first premature end of a `nextImpl` call continues such a read, and it was paying the price of the error path for it: a 100 ms backoff, doubling per attempt, and an increment of `ReadBufferFromAzureRequestsErrors` on every single response of the read. That reopen is now issued immediately, as a request of its own rather than as a retry of a failed one - the attempt number handed to `initialize` is 0, so its latency is measured as a first attempt and not as a retry. A reopened download that hands out nothing at all is the error case, and the further attempts of the loop back off for it as before, up to `max_single_read_retries`. `AzureBoundedRead.CappedResponsesAreReassembled` now also asserts that reassembling the three responses of the read counts no request errors, and `AzureBoundedRead.TruncatedBlobIsAnError` that a reopened download delivering nothing does. The first test drops from 200 ms to 0 ms and the second from 548 ms to 173 ms, which is the backoff that is no longer paid. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The `ignore_range` mode of the fake endpoint - answering every request with `200 OK` and the blob from byte 0, the way a proxy that does not understand ranges does - and the `HTTP_RANGE_NOT_SATISFIABLE` and `LOGICAL_ERROR` error codes are left over from #115706, where the check of the range an endpoint returns lived in the same change as the premature end. No test here uses them. That check is #120955, and it brings its own range-ignoring endpoint in `src/Disks/tests/gtest_azure_read_buffer_range_check.cpp`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…e-end Conflict in the error code list of `ReadBufferFromAzureBlobStorage.cpp`: kept both `UNEXPECTED_END_OF_FILE` and master's `HTTP_RANGE_NOT_SATISFIABLE`.
The analyzer does not follow the `catch` path, and on the path without an exception `FAIL` returned before `errors_before` was read. Record the error code and assert on it after the `try` block instead, so the value is read on every path. https://github.com/ClickHouse/ClickHouse/actions/runs/35472092610/job/105975000148 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…reopen range check The AI review asked that a reopened download be rejected when it does not start at the current offset, and that the data a response hands out be capped at `read_until_position`. The first half is `checkReturnedRange` from #120955, now on master and merged here; `AzureBoundedRead.RangeIgnoringEndpointIsRejectedOnReopen` pins that it applies to the reopen added by this PR. For the second half, `nextImpl` no longer reads past the right bound when a response runs longer than requested (e.g. a whole-object `200 OK` answering a ranged request at offset 0); before, the caller received the extra bytes and the next call threw `Attempt to read beyond right offset`. `AzureBoundedRead.LongerResponseIsCutAtTheRightBound` fails without the cap. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…position` #120963, merged into `master`, added code to `ReadBufferFromAzureBlobStorage::nextImpl` that treats `read_until_position` as an `off_t` with zero meaning no bound. In this PR it is a `std::optional<size_t>`, so the merged code did not compile in the merge queue. Dereference the bound where it is known to be set. Merge queue failure: https://s3.amazonaws.com/clickhouse-test-reports/REFs/gh-readonly-queue/master/pr-120910-38c3aeff5b23272021e0a5cc0686e63b1607d401/c20dae0928d9442f3de1361797cf66d0267cf361/mergequeueci/build_amd_binary/job.log PR: #120910 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ds short With #120963 from `master`, a response that ends before the right bound is reopened, and a read that still cannot reach the bound fails with `UNEXPECTED_END_OF_FILE` instead of silently ending at the end of the short response. The test `AzureReadUntilPosition.ShortRangeResponse` of this PR pinned the old behaviour, so it now expects the exception. It still guarantees that no bytes past the response reach the caller. Merge queue failure: https://s3.amazonaws.com/clickhouse-test-reports/REFs/gh-readonly-queue/master/pr-120910-38c3aeff5b23272021e0a5cc0686e63b1607d401/c20dae0928d9442f3de1361797cf66d0267cf361/mergequeueci/build_amd_binary/job.log PR: #120910 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
…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]>
…size A read without a right bound took the end of the first response as the end of the file. An endpoint or proxy that caps its responses then truncated the file silently, while a bounded read is reopened at the offset it reached (ClickHouse#120963). Iceberg manifests are now read without a size, so on Azure such a truncation could end a manifest at an Avro block boundary and drop its remaining entries (from queries and from the reachable set of `remove_orphan_files`). The size of the blob from the `Content-Range` of the response is now the end of the data for such a read: a shorter response is reopened the same way, and the read fails with `UNEXPECTED_END_OF_FILE` once the retries are spent. The size only decides when to reopen; what a response delivers is still bounded by its own length. `AzureBoundedRead.UnboundedReadEndsWithTheResponse` pinned the old behaviour and is replaced by `AzureUnboundedRead.*`: capped responses are reassembled, a blob shorter than its advertised size is an error, an exact response is not reopened. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #115706
Related: #120419
Related: #120955
ReadBufferFromAzureBlobStorage::nextImpltook the end of the response body as the end of the data. For a read with a right bound that is wrong: the bound is set locally by the caller, and every layer above the buffer (ReadBufferFromRemoteFSGather,AsynchronousBoundedReadBuffer, the caches) takes it as the length of the data. An Azure Blob Storage endpoint or a proxy that caps its responses, or a blob that turned out shorter than the size it was listed with, therefore silently truncated the file at the end of the first response: the reader returned fewer bytes than the bound and reported the end of the file.A response that ends before the bound is now treated as a premature end: the download is reopened at the offset the read has reached, counted against
max_single_read_retries, and when the endpoint keeps ending its responses before the bound the read fails withUNEXPECTED_END_OF_FILEinstead of returning truncated data. A read without a right bound keeps its previous behaviour. The amount left of the current download is now measured per attempt, so a download reopened by a retry is read from where it was reopened rather than with the count computed for the previous one.An endpoint that caps its responses ends every one of them before the bound, so a read of more than the cap is a correct read assembled from several responses, and the reopen that continues it must not be priced as a failure: the first reopen of a call is issued immediately, as a request of its own rather than as a retry, and does not increment
ReadBufferFromAzureRequestsErrors. Otherwise every single response of such a read would cost a 100 ms backoff and an error event. A reopened download that hands out nothing at all is the error case, and the further attempts back off for it as before.src/Disks/tests/gtest_azure_read_buffer_premature_end.cppreassembles a 100-byte blob from a fake endpoint that caps every response to 40 bytes (three requests, at offsets 0, 40 and 80) and counts no request error for it, fails withUNEXPECTED_END_OF_FILEon a blob truncated at 40 bytes once the retries are spent and counts the reopen that delivered nothing as an error, and checks that an exact response and an unbounded read are not reopened.This is one of the independent parts of #115706, which was reverted in #120419.
Whether the endpoint honoured the range of the reopened download at all is a separate question, and it is the subject of #120955: it checks the start of the returned range against the requested offset in
initialize, which every reopen - the one added here and the ones already on master - goes through.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A bounded read from Azure Blob Storage whose response ends before the requested right bound is now reopened and, if the endpoint keeps answering short, fails with
UNEXPECTED_END_OF_FILEinstead of silently returning a truncated file.Workflow [PR]
Sync PR [sync-upstream/pr/120963]
Version info
26.10.1.859-master(included in26.10and later)