Repository navigation
Do not read index marks from object storage while destroying a part - #113454
alexey-milovidov merged 8 commits into
Conversation
`IMergeTreeDataPart::removeIndexMarksFromCache` runs from `clearCaches` during
part destruction and needs nothing but mark-cache key strings. It asked
`getDeserializedFormat`, i.e. "which substreams does THIS PART hold?", and for a
part whose skip indices are bundled into `skp_idx.packed` answering that performs
a real object-storage read:
removeIndexMarksFromCache
-> IMergeTreeIndex::getDeserializedFormat
-> indexFileExistsInChecksums (packed branch)
-> IDataPartStorage::existsFile
-> DataPartStorageOnDiskBase::getSkipIndicesPackedReader
-> PackedFilesReader ctor -> disk->readFile(skp_idx.packed)
When the blob has been reclaimed while its metadata entry survives, that read
fails and the error is rethrown: `getSkipIndicesPackedReader` decides
swallow-vs-rethrow by re-checking `disk->existsFile`, which on object storage is
metadata-only and so still answers "present". The exception escapes into
`removeIfNeeded`'s `catch (...)` -> `tryLogCurrentException`, which re-emits the
whole `Code: 499 ... The specified key does not exist` text at `<Error>` level,
and it aborts the substream loop so the remaining keys are never evicted.
Ask the static, I/O-free question instead. `IMergeTreeIndex::getPotentialSubstreams`
returns every substream any version of the index could have written, taking
neither a part nor a storage, so it cannot do part I/O by construction:
- default: `getSubstreams`
- minmax: `.idx2` (v2) and legacy `.idx` (v1); `getDeserializedFormat` and
`getAllSubstreamsInPart` already probe both, which is the evidence a part may
hold either
- text: `.idx` / `.dct` / `.pst` / `.pos`, with `.pos` unconditional. Whether a
part holds `.pos` is a property of that part, not of the current
`params.positions`, so the writer-side view would miss it after the index was
redefined without positions
Removing an absent key is a no-op (`CacheBase::remove`), so the superset costs
nothing, and the computed keys are unchanged: the
`getStreamNameOrHash(..., checksums)` / `.value_or(full_stream_name)` /
`getMarksFilePath` chain is byte-identical to the one `loadIndexMarksToCache`
uses when inserting.
This deliberately touches neither `getSkipIndicesPackedReader` nor
`getArchiveReaderForFile`. Swallowing the 404 there instead would revert
7346f47 and e9f818e (PR ClickHouse#107995), which made that path fail
closed because callers treat a null reader as authoritative and could then
hardlink `skp_idx.packed` while dropping packed substreams.
One intentional behaviour change: a part with an invalidated system column
previously skipped eviction entirely, because `getDeserializedFormat` reports
nothing for it and the caller did `if (!index_format) continue;`. Its keys are
now evicted too, so those parts no longer leak marks.
Validated on an object-storage disk with the packed object deleted under a live
metadata entry: the eviction-frame error appears 3/3 runs before the change and
0/3 after, while the unrelated part-load error stays present in both arms as a
positive control that the object really is gone. A mutant that reverts only the
caller while keeping the new API still reproduces it 3/3, so the two unit tests
pin the API and this repro covers the caller.
…storage The two unit tests added with the fix inspect getPotentialSubstreams directly and pin the new API, not its caller. Reverting only the caller hunk in IMergeTreeDataPart::removeIndexMarksFromCache back to getDeserializedFormat leaves both of them green while the defect reproduces, so the user-visible half of the change was unpinned. The test creates a part whose minmax index is bundled into skp_idx.packed on an object-storage disk, deletes that archive object while its metadata entry survives, and reattaches so the archive probe is unseeded. Ordering is load-bearing: DiskObjectStorage::existsFile is metadata-only, so with the object gone the packed probe's re-check still answers "present" and rethrows the 404, and the writer seeds the reader, so deleting the object after the reattach resolves the probe and reproduces nothing. The oracle keys on the removeIfNeeded stack frame rather than the error code. The part-load path legitimately reads skp_idx.packed and is untouched here, so it reports the missing key in both directions; a bare Code: 499 count is non-zero either way. That count is asserted greater than zero as a positive control, so a fixture that failed to delete the blob cannot pass silently. Measured, each arm with its own build id asserted: passes on the fix; fails on the caller-only mutant with assert 1 == 0 on the frame-keyed assertion after the positive control has already passed; fails with the blob-deletion step removed, on assert 0 > 0. The whole test_merge_tree_s3 module is 23 passed, 3 skipped.
Internal second-model reviewTwo review rounds. Round 1 approved the source change and bounced one test-coverage gap; round 2 reviewed the integration test that closed it. Findings from an independent reviewer pass plus a second model, each adjudicated against the code.
Also checked: the substream carrier set is exactly the two indices with a Session id: cron:clickhouse-review-slot-8:20260805-104200 |
Pre-PR validation gate
Additional notes for reviewers: The two levels of test pin different properties, and each is pinned by its own mutant. Reverting only the The integration test asserts two things over a log window anchored before the reattach: that no One intentional behaviour change: a part with an invalidated system column previously skipped eviction entirely, because Regression: a paired sweep of 357 minmax, skip-index, text-index, data-skipping, index-mark and packed-skip-index tests with randomized settings, run on both binaries. No test fails with this change that does not also fail without it. |
|
cc @CurtizJ @al13n321, could you review this? Mark-cache eviction runs from the part destructor but asked |
|
Workflow [PR], commit [1ec0eff] Summary: ✅
AI ReviewSummaryThis PR removes part-destruction I/O from index-mark eviction by replacing per-part physical-format discovery with a no-I/O Missing context / blind spots
Final Verdict✅ No actionable findings at current HEAD. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 51/51 (100.00%) · Uncovered code |
The regression test added in this PR asserted its own positive control (`Code: 499` must appear at all) and that control read 0 in CI, so the arm never reached the assertion it exists to make. The `Code: 499` the control counts is emitted while ATTACH loads the part, reaching the archive through `getColumnSize` -> `calculateColumnsAndSecondaryIndicesSizesOnDiskUnlocked` -> `calculateSecondaryIndicesSizesOnDisk` -> `getAllSubstreamsInPart` -> `indexFileExistsInChecksums` -> `existsFile` -> `getArchiveReaderForFile`. The only call site that reaches that chain during load is `IMergeTreeDataPart.cpp:2095`, which sits inside the `#ifndef NDEBUG` block of `loadRowsCount`. The local build is `CMAKE_BUILD_TYPE=Debug` so the block compiles in, while the `amd_asan_ubsan` job builds with `-DCMAKE_BUILD_TYPE=None`, which `CMakeLists.txt` rewrites to `RelWithDebInfo`, where CMake defines `NDEBUG` and the block is compiled out. With no probe the part loads cleanly, is never detached as broken and never destroyed, so the eviction path is not entered and both assertions read 0 whether the fix is present or not: measured, the caller-reverted mutant was not caught either. `columns_and_secondary_indices_sizes_lazy_calculation = 0` runs the same size accounting eagerly during part load from `IMergeTreeDataPart.cpp:1412`, which is not `#ifndef`-gated, so the probe fires on every build type. Precedent for using it this way: `04341_packed_skip_indices_drop_size_object_storage.sql` and `04401_mutate_all_columns_preserve_skip_index_checksums.sql`. With the setting the test passes on the shipping binary and fails on a binary with only the caller hunk reverted, failing there on the frame-keyed oracle rather than the control, so the control still passes on that arm and the caller stays pinned. The whole `test_merge_tree_s3` module is 23 passed, 3 skipped, unchanged from before. No source change: the five source files and both unit tests are untouched.
CI finish ledger - bca24b2Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
All 174 check-runs completed and Two things on this commit look like failures and are not. The forty-four Session id: cron:our-pr-ci-monitor:20260805-230000 |
ClickHouse#112484 renamed the virtual IMergeTreeIndex::getDeserializedFormat to getPhysicalFormat and made getDeserializedFormat a non-virtual wrapper that adds usability checks. That rewrote the same four sites this branch touches. Resolution: keep master's rename everywhere (both overrides and the doc block), keep this branch's getPotentialSubstreams beside it. The eviction call site drops master's getPhysicalFormat call entirely, which is the point of the branch: that call is what does object-storage I/O during part destruction. getPhysicalFormat keeps its other caller in getDeserializedFormat, so nothing is orphaned. getPotentialSubstreams remains a superset of every layout getPhysicalFormat can report, for both overriding index types: minmax returns .idx2 and legacy .idx against master's two probes, and text returns .idx/.dct/.pst/.pos against master's v1/v2 pair. The evicted keys therefore still cover every key loadIndexMarksToCache can insert, which is the contract that could break silently. Also folded master's NOTE on getSubstreams into one sentence naming both methods, and updated the gtest comment to the new method name.
Two things the master merge left inconsistent, both comment-only. The doc block introduced by ClickHouse#112484 names "evicting index marks" as the exemplar caller that needs physical discovery, but this branch removes exactly that caller: resolving what a part holds probes the part's storage, which must not happen while destroying a part. Left as-is the comment invites reintroducing the object-storage read it exists to prevent, so it now names the constraint and points at getPotentialSubstreams instead. CLAUDE.md also asks for `f` rather than `f()` when a comment refers to a function itself; applied to the lines this branch writes. Pre-existing text elsewhere in these files is left alone so the diff stays about the substream API.
CI finish ledger - d8025dbEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task CI is fully finished on this head: 177/177 check-runs completed, 0 incomplete,
None of the three is caused by this PR. The
Session id: cron:our-pr-ci-monitor:20260817-213000 |
…ache-eviction-object-storage-io # Conflicts: # src/Storages/MergeTree/MergeTreeIndexMinMax.h # src/Storages/MergeTree/MergeTreeIndexText.cpp # src/Storages/MergeTree/MergeTreeIndexText.h
Eviction no longer asks getPhysicalFormat what a part holds, so the sentence naming ~IMergeTreeDataPart as a caller of the part-less overload described a call site this change removes. Left in place it reads as licence to probe the part's storage from a destructor again.
Wrap literal class, function and setting names and log-message excerpts in inline code blocks, and write a function name without parentheses, per .claude/CLAUDE.md. Comment-only. Also drop the same stale destructor clause from the helper's comment in MergeTreeIndices.cpp that the previous commit removed from the header.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units289 translation units recompiled, 2775 s compile time in total, 289 of them have a recent master baseline. |
|
Dear @CurtizJ, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Good change, thanks!
Related: #110050
Related: #112484
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed unnecessary object-storage reads, and
<Error>-level exception messages such asCode: 499 ... The specified key does not exist ... (S3_ERROR), while destroying a data part on an object-storage disk when its skip indices are packed intoskp_idx.packed. Evicting the part's index marks from the mark cache no longer inspects the part's on-disk layout, so it performs no I/O.Description
Mark-cache eviction needs only key strings, but
IMergeTreeDataPart::removeIndexMarksFromCacheaskedgetPhysicalFormat, i.e. "which substreams does this part hold?". For a part whose skip indices are bundled intoskp_idx.packedthat question is answered by reading the archive:indexFileExistsInChecksums->IDataPartStorage::existsFile->getSkipIndicesPackedReader->disk->readFile. This runs during part destruction, including fromunloadPrimaryKeysAndClearCachesOfOutdatedPartson the cleanup threads.When the blob has been reclaimed while its metadata entry survives, the read fails and the error is rethrown, because
getSkipIndicesPackedReaderdecides swallow-vs-rethrow by re-checkingdisk->existsFile, which on object storage is metadata-only and still answers "present". It then reachesremoveIfNeeded'scatch (...)and is logged in full at<Error>level, and it also aborts the substream loop so the remaining keys are not evicted.I added
IMergeTreeIndex::getPotentialSubstreams, which returns every substream any version of the index could have written. It takes neither a part nor a storage, so it cannot do part I/O. Overridden forminmax(.idx2and legacy.idx) and fortext(.posunconditionally, since holding.posis a property of the part, not of the current index definition). Removing an absent key is a no-op, so the superset is free, and the computed keys are unchanged.I deliberately did not make the packed probe swallow the 404 instead: #107995 made that path fail closed on purpose.
#112484 has since merged and renamed this virtual to
getPhysicalFormat; I mergedmasterto pick that up. It does not remove this read (it still passes the part into a storage-probing helper), so this change is still needed. My #110050 rewrites the same lines and is still open; whichever lands second hand-resolves.Validation
Jobs affected:
Integration tests (*), for the new test below; the change is also exercised by the existing packed-skip-index tests, andpacked_skip_index_max_bytesis randomized byclickhouse-test.Reproducer on an object-storage disk: create a fully packed skip-index part, delete the
skp_idx.packedobject out from under its live metadata entry,DETACH/ATTACHso the archive probe is unseeded, thenDROP TABLE ... SYNC. Deleting the object before the reattach is load-bearing, because the writer seeds the reader.The oracle keys on the stack frame, not on the error code: the part-load path legitimately reads
skp_idx.packedand is unaffected here, so it emitsCode: 499in both arms and serves as a positive control that the object really is gone. Counting bare occurrences would show a non-zero result either way.Code: 499Code: 499Two unit tests in
gtest_index_potential_substreams.cpppin the enumeration, and each override has a mutant that fails its test. They still pass when only the caller is reverted, so the caller is pinned separately bytest_merge_tree_s3/test.py::test_no_object_storage_read_when_evicting_index_marks, which fails on exactly that mutant.Paired regression sweep of 357 minmax, skip-index, text-index, data-skipping, index-mark and packed tests, randomized: no test fails with this change that does not also fail without it.
One residual I did not close: narrowing the caller to the also-I/O-free
getSubstreamsis not caught, since the fixture'sminmaxpart holds.idx2, which both return. Catching it needs a part holding a stale text.posunder a positions-disabled definition, and eviction is not assertable on such a part: only a part that never loaded can throw in the probe, and its index-mark cache is empty by construction.Workflow [PR]
Sync PR [sync-upstream/pr/113454]
Version info
26.10.1.317-master(included in26.10and later)