Repository navigation
Avoid GET requests for unchanged plain-rewritable directories - #119760
alexey-milovidov merged 21 commits into
Conversation
|
Workflow [PR], commit [fd39ac8] Summary: ✅
AI ReviewSummaryThis PR adds a Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit fd39ac8.
Changed lines: Changed C/C++ lines covered: 18/18 (100.00%) · 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 units8 translation units recompiled, 16 s compile time in total, 8 of them have a recent master baseline. |
|
📊 Cloud Performance Report
Release-transition baseline: compared against the most recent available 26.9 masters at or before the trusted base-commit anchor because no 26.10 master baseline exists there. This PR only changes background refresh for the plain_rewritable metadata storage: it skips re-reading directories whose ETag has not changed, and it adds a unit test. No ClickBench SELECT runs that code while it executes. The seven flagged ClickBench improvements are all aggregation-heavy queries that used less CPU, which does not fit this diff, so six are downgraded to not_sure. Q32 (-47.0%) stays because its size locks the verdict, but it most likely comes from other changes in the newer 26.10 PR build, not from this PR. clickbench🟢 1 improved · Flagged queries (7 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
|
A matching nonempty ETag validates the version observed by LIST. Remote renames and deletions after that listing are observed by the next refresh. The existing load algorithm explicitly permits concurrent-change races; another GET would not make layout publication atomic. Clarify the contract at the reuse point without adding a redundant remote request. ClickHouse#119760 (comment)
# Conflicts: # src/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/MetadataStorageFromPlainRewritableObjectStorage.cpp
…able-etag-refresh
The etag of `LocalObjectStorage` is `(mtime, inode, size)`. An unconditional write truncates and rewrites the file in place, so it keeps the inode, and a payload of the same length keeps the size. On a kernel that stamps inode times from the coarse per-tick clock, two writes within one tick then leave the etag unchanged, although the storage reports it as strong. This made `MetadataPlainRewritableDiskTest.RefreshSkipsUnchangedDirectoryReads` flaky: renaming directory `A/` to `C/` rewrites `prefix.path` with a payload of the same length, and the refresh trusted the unchanged etag and kept `A/`. Stamp the modification time of an unconditionally rewritten object past the one of the version it replaces, the same way conditional writes already do. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119760&sha=e2db0d9737b586e455db2451017db57371d7acc8&name_0=PR&name_1=Unit%20tests%20%28amd_llvm_coverage%29 PR: ClickHouse#119760 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… the directory lock Address review: an unconditional write rewrote the file in place and was stamped past the modification time captured when its writer was opened. Two writers of one path that are open at the same time both captured the same predecessor, so on a filesystem that stamps inode times from the coarse per-tick clock the second one could be stamped to the very etag the first one had already published: same mtime, same inode, same size, different content. A `plain_rewritable` reader that cached the first version under that etag would then skip re-reading `prefix.path` on every later refresh, since `LocalObjectStorage` advertises its etags as strong. A reader could also see a truncated or partially written object. Now every write, conditional or not, is staged in a temporary file and published by `publishVersion`, which takes the exclusive lock on the parent directory, stamps the new version past the version it actually replaces as it stands under that lock, and then `rename`s it into place. The etag strictly increases across the version history of the path, readers only ever see complete versions, and a cancelled write leaves the object untouched. Staging names are drawn from a separate generator so that writes do not advance `thread_local_rng`, from which object keys are generated. The new test `InterleavedUnconditionalWritesPublishDistinctEtags` reproduces the etag collision with the previous implementation. Related: ClickHouse#119760 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review: since every write is staged next to its target until it is finalized, a `plain_rewritable` metadata instance that loads (or calls `dropCache`) while a writer is open rebuilt the directory's file set from `listObjects` and recorded the staged `.tmp_...` file as a real file of the directory. Later refreshes skip unchanged directory bodies, so the phantom entry stayed until the next forced reload. Staging cannot move to a dedicated area: `rename` does not publish across filesystems and the key prefix may span several of them (it is `/` in `clickhouse-local`). Instead, a remote object storage never lists an unfinished upload, and neither does `listObjects` now: it skips every name with the reserved staging prefix `.tmp_local_object_storage_`. The name of the target is no longer part of the staging name, so a target whose name is close to `NAME_MAX` can still be staged. New tests: `LocalObjectStorage.ListObjectsHidesUnfinishedWrites` and `MetadataPlainRewritableDiskTest.LoadIgnoresUnfinishedWrite`. Related: ClickHouse#119760 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rash_server` The test waited for a `*.parquet` file to appear before `KILL QUERY`. Since `LocalObjectStorage` stages every write under a temporary name until it is finalized, like a remote object storage, a data file only shows up under its final name on commit, so the test timed out with `no inner sink opened its data file in time`. Count any file outside of `_delta_log` instead, and check that the cancelled insert leaves neither a published nor a staged file behind. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119760&sha=6abd16d3fbe008bcb017e34907dacf2830d92b85&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%202%2F8%29 Related: ClickHouse#119760 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r object names `listObjects` hides every name starting with `.tmp_local_object_storage_`, so an object written under such a name would be published but never listed. Reject such names in `writeObject`, which every object creation (including `copyObject`) goes through, so that hiding the prefix hides no object. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Michicosun
left a comment
There was a problem hiding this comment.
There are too many unrelated changes.
mtime in most filesystems (ext4-like) has nanosecond precision. We don't need to change anything for local object storage.
The reviewer asked to keep the PR limited to the plain-rewritable refresh. Restore `LocalObjectStorage`, its gtests and `test_storage_delta` to master, and remove `LoadIgnoresUnfinishedWrite`, which only covered the staged writes. `RefreshSkipsUnchangedDirectoryReads` was flaky because it renamed `A/` to `C/`, so `prefix.path` was rewritten in place with a payload of the same size. The `LocalObjectStorage` ETag is `(mtime, inode, size)`, and the kernel stamps mtime from its coarse clock, so a rewrite within one tick could keep the ETag. Rename to a name of a different length instead, so the ETag changes by size. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119760&sha=e2db0d9737b586e455db2451017db57371d7acc8&name_0=PR&name_1=Unit%20tests%20%28amd_llvm_coverage%29 Review: ClickHouse#119760 (review) PR: ClickHouse#119760 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Hey @Michicosun sorry you are right, the bot went a bit crazy after a flake and I didn't re-read the code. |
|
Hi, could this fix be backported to 26.8? On 26.8, a read-only The .cpp hunk doesn't apply as-is because master restructured Thanks! |
SipHash kept the current partial 8-byte word as a union of a UInt64 and UInt8[8]. `update` wrote a short tail byte by byte into the byte array (the remainder of a previous update too, which clang emits as a `memcpy`), and `finalize` stored the `cnt` byte into the last position and then read the whole word with one 8-byte load. An 8-byte load that overlaps several narrower in-flight stores cannot be store-forwarded on x86: it waits until the stores commit (`ld_blocks.store_forward`). When the hash state lives in memory across a call, e.g. `UniqVariadicHash::apply` -> virtual `IColumn::updateHashWithValue` -> `get128`, every row pays this. How often the blocked load is replayed depends on code placement, so the same machine code is fast in one build and ~55% slower in another: this is why `entropy #2` of the performance comparison flips between ~0.33 s and ~0.52 s per build on amd (master builds 4f8c9f2..a0b6517, and PR builds of ClickHouse#117704, ClickHouse#114690, ClickHouse#119760). Now `current_word` is a plain UInt64 holding the received bytes of the current word in little-endian order, the bytes not received yet being zero (the same numeric value the union had on both endiannesses, so CURRENT_BYTES_IDX is gone). `loadTail` assembles up to 7 bytes in a register with overlapping 4/1-byte loads, the remainder path ORs it in at the right shift, the main loop keeps the word in a local, and `finalize` folds `cnt` into the top byte in a register. Every access to `current_word` is now a whole-word store followed by a whole-word load. Hash values are unchanged. Validation (release build, CMAKE_BUILD_TYPE=None without ThinLTO, Xeon 6975P, `SELECT entropy(MobilePhoneModel)` over 100M rows of a 92%-empty sparse String column, max_threads=16, medians of 18 runs): - base 0.218 s, fix 0.150 s; official master builds 562bdc1 0.204 s (fast layout) and 4f8c9f2 0.285 s (slow layout). - 15 queries: ld_blocks.store_forward base 1.54e9, fix 2.7e7 (slow official 6.07e9); cycles 1.44e11 -> 8.98e10; instructions 5.27e11 -> 4.71e11. - `uniqExact(toString(number % 1000), toString(number % 7))` over 2e8 rows 5.23 s -> 2.98 s; sipHash64/sipHash128 of 1..5-byte strings -6.4%/-4.8%; sipHash64 of 10..50-byte strings +1.1% (instructions +1.8%); GROUP BY two String keys unchanged. - Hash identity: a throwaway differential gtest against the verbatim previous class (every length 0..80 x every 3-way split, 3 key pairs, get64/get128/get128Reference, double get, update after get, the ColumnString row shape, 300k random streams of raw and typed updates): 2,038,362 cases, 0 mismatches; a planted mutation (wrong value for 4-byte tails only) gives 808,592 mismatches. 02534_keyed_siphash and 02552_siphash128_reference (official vectors) pass, and SQL sums of sipHash64/128, keyed and reference variants over 2e7 strings are equal on both binaries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Metadata refresh reads each
prefix.pathobject before checking its listed ETag. Keep the remote-directory-to-local-path map after a successful load, and reuse metadata when the directory ID and nonempty ETag match. Changed or missing ETags still trigger GETs; forced reloads still read every directory. Publish the map only after the load succeeds.Refresh is not an atomic snapshot of remote metadata. Reuse validates the version observed by LIST. A rename or deletion after that listing can remain visible until the next refresh; the existing GET-based path also permits changes between a GET and publishing the resulting layout. The next listing observes a changed ETag or missing directory and refreshes/removes the cached entry.
Benchmark
The reader refreshed 100,000 packed parts every second, with no writes or statistics refresh. Values are medians of three 10-second windows after warmup.
Both 26.8-based Release builds disabled LTO and had limits of 4 CPUs and 16 GiB. An S3-compatible proxy served local NVMe data with a 2-CPU limit. The shared host used a Ryzen 9 5950X.
Faster refreshes explain the extra LIST requests. This test does not measure AWS S3 performance or isolate the map's memory cost.
Validation
All 53 metadata tests passed. Coverage includes unchanged directories, rename, deletion, path reuse, missing ETags, and forced reload. Both readers passed row-count checks.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Avoid object reads for unchanged directories when a plain-rewritable disk refreshes its metadata.
Workflow [PR]
Sync PR [sync-upstream/pr/119760]
Version info
26.10.1.1252-master(included in26.10and later)