Repository navigation
Bound reads of files inside packed parts to the file's slice - #118483
Conversation
`ReadBufferFromFileView` (used to read files inside `data.packed` of a part with the Packed storage) seeked the underlying buffer to the file's offset but did not pass the right bound until the reader called `setReadUntilPosition`. Reads of whole files (metadata files, marks files) therefore became open-ended range requests on object storage: they transferred the rest of the archive instead of the file, and the HTTP connection could not be returned to the pool. Reading one row of a `JSON` column with 1104 substreams from a Wide Packed part transferred 5.5 MB in 1419 requests over 1215 connections; the same read from the Full storage transferred 2.1 MB over 502 connections. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [38e2d96] Summary: ✅
AI ReviewSummaryThis PR bounds Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 38e2d96.
Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code |
|
Doesn't it make the caching worse? |
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, 5 s compile time in total, 7 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: The change adds a single read-bound to ReadBufferFromFileView so that reads of files inside a Packed-storage archive on object storage stop issuing open-ended range requests and can return their HTTP connection to the pool. That path is specific to Packed parts on S3-style object storage; the ClickBench benchmark runs on local storage and never touches this code. The flagged Q30 improvement (-11.0%) is on a query the history marks as flaky, with CPU essentially unchanged (2386 vs 2383 ms), so it reads as measurement variance rather than a PR effect and was downgraded to not sure. No credible per-query performance impact is expected from this diff. clickbenchFlagged queries (1 of 43)
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. tpch_adapted_1_official🟢 No significant changes Debug info
|
The flaky check failed 23 times out of 23 on the middle column of `05112_s3_packed_part_connection_reuse`: `DiskConnectionsCreated <= 2`. How many connections a query has to create depends on how many are already stored in the shared pool when it starts, which concurrently running queries change, so the count is not a property of this change. `DiskConnectionsReused >= 18` held in every one of those runs, and it is the assertion that actually pins the fix down: without bounding the read to the file's slice the response body is never fully consumed, every connection is reset instead of being returned to the pool, and there is nothing to reuse. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118483&sha=8a01efa9df92e18f013edc9e18ffdf3b087d2566&name_0=PR #118483 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 > Doesn't it make the caching worse? No — the only thing that changes is where the HTTP range of the request ends; the amount of data that is read and cached stays the same.
Also pushed: master merged, and the environment-dependent |
The test asserted that the warm reread of a cold-populated table touches the source not at all, and started failing on master right after ClickHouse#118483: -warm_served_from_cache 1 +warm_served_from_cache 0 `min_bytes_for_full_part_storage` is randomized by the test harness, so about two thirds of the runs store the part with the Packed storage: every file of the part lives in ONE object, hence ONE filesystem-cache segment. Inside a single query the marks streams and the data stream each build their own `ReaderExecutor` over that object (`max_threads = 1` does not serialize them - the marks load on their own pool threads) and race for the segment's single downloader role. Only the role winner writes; the losers read through from source and discard. Before ClickHouse#118483 this was invisible: a whole-file read inside `data.packed` was an open-ended range request, so the role winner's fetch ran to the end of the archive and populated the whole segment. ClickHouse#118483 bounds each read to the file's slice, so the winner now fills only that slice and the cold read leaves the segment with holes. The warm read then re-fetches such a segment from its start (`claimLeadRole`'s `available` prefix is deliberately unused - see the "Coarse by design" note in `ReaderExecutor::readThroughCaches`), so `warm` is the whole extent rather than 0. Pin `min_bytes_for_full_part_storage = 0`: with the Full storage every stream is its own object and therefore its own cache key, so each segment has exactly one writer and the cold read populates all of them. That is also what the test means to cover - the executor's read-through contract - rather than whether concurrent streams over one shared segment converge. Verified against a local minio with the failing run's randomized settings, on 26.9.1.1234 (the SHA below): the test as it stands fails 97/200, the patched test passes 350/350. Cross-checked on 26.9.1.1193 (just before ClickHouse#118483), where the unpatched test passes 100/100 and the cold read pulls 4064344 bytes from source for a 1630734-byte archive - the over-read that ClickHouse#118483 removed is what used to fill the segment. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=1d0999bf07898241e1229af5b6c1717aec5d275c&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20sequential%2C%202%2F2%29 Caused by: ClickHouse#118483 Related: ClickHouse#115664 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Both tests asserted `DiskConnectionsReused >= 18` for one sequential read of a 21-column Wide part. The connection pool is keyed on the endpoint and every test S3 disk is `localhost:11111`, so the counter measured a pool shared with every concurrent test: in the failed 05110 run all 42 connections were returned (Preserved 42, Reset 0), yet neighbours took them and the query created 26 and reused 16. The same counters also pass with each test's own fix reverted, because the test's INSERT leaves idle connections in the pool (05110: Created 0 / Reused 42; 05112: Reused 21). Assert each bug's own per-query effect instead: - 05112: `DiskConnectionsReset <= 2`. Without the view's right bound every file read is open-ended, the response is never read to the end and the connection is reset instead of returned. - 05110, now a `.sh` test: count the TEST-level `Read S3 object ... Range: a-b` lines of the SELECT. Without the right bound at the object end the data file requests have no range end and log no such line. Negative controls on a debug build (local MinIO): with the gather fix reverted the new 05110 fails 10/10 back-to-back on a warm pool (0 ranged requests vs 21, connection counters identical to the fixed build); with the view bound removed the new 05112 fails 10/10 (Reset 21 vs 0). The fixed build passes both in 50 sequential, 50 `-j 16` and 30 runs under a 16-way S3 load. CI failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=6101ac5e7d4976004fc00948f42677b22f3f40fc&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%202%2F3%29 https://github.com/ClickHouse/ClickHouse/actions/runs/36682278835/job/109784920371 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123673&sha=b0678011a1bdfaf285150128113a0ffd0e8097b5&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20AsyncInsert%2C%20s3%20storage%2C%20parallel%29 Related: ClickHouse#118480, ClickHouse#118483 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cked archive member `ReadBufferFromFileView` never told the buffer under it where a packed archive member ends, so every member read on an object storage disk was an open-ended `GET`: a merge of a 2,400-column table reset ~8,100 connections. The view now passes its right bound down. `05112` asserts `DiskConnectionsReset <= 2` instead of a reuse count of the shared S3 connection pool. Upstream: ClickHouse#118483 (merge commit dc740cb) Upstream: ClickHouse#124776 (merge commit 9e2445a), only its `05112` part: `05110` tests ClickHouse#118480, which is not on this branch. Signed-off-by: Mikhail Filimonov <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
Related: #118475
ReadBufferFromFileView, which reads a file insidedata.packedof a part with the Packed storage, seeked the underlying buffer to the file's offset but did not pass the right bound until the reader calledsetReadUntilPosition. Whole-file reads (metadata files, marks files, small streams) therefore became open-ended range requests on object storage: they transferred the rest of the archive instead of the file, and the HTTP connection could not be returned to the pool.Measured with a Wide Packed part of a
JSONcolumn with 1104 substreams behind an HTTP server with 30 ms latency,SELECT * ... ORDER BY t DESC LIMIT 1: before, 1419 requests of which 712 were open-ended, 5.5 MB transferred, 1215 connections opened; after, 0 open-ended requests, 2.0 MB transferred, and the connection count is the same as for the Full storage. For a Compact Packed part the same query used 12 connections before and 2 after.The test reads a Wide Packed part on an S3 disk with one thread and synchronous reads and checks that the connection is reused instead of created for every file.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Bound object storage requests for files inside packed parts to the file's slice, so that reading a packed part from object storage does not transfer the rest of the archive and reuses HTTP connections.
Workflow [PR]
Sync PR [sync-upstream/pr/118483]
Version info
26.9.1.1219(included in26.9and later)