Skip to content

Count packed skip-index archive index loads, and assert 04653 on that counter - #118234

Closed
groeneai wants to merge 5 commits into
ClickHouse:masterfrom
groeneai:04653-packed-archive-index-load-profile-event
Closed

groeneai wants to merge 5 commits into
ClickHouse:masterfrom
groeneai:04653-packed-archive-index-load-profile-event

Conversation

@groeneai

@groeneai groeneai commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #112691

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added the PackedSkipIndicesArchiveIndexLoads ProfileEvent, which counts attempted reads of the index of a part's packed skip-indices archive.

Description

04653_packed_part_size_accounting_no_read_in_commit (added by #112691) reddens unrelated PRs and master: 37 failures in 60 days, on 24 PRs and 3 master runs.

Both rows compared incidental I/O aggregates whose whole margin between the arms is one disk->readFile: the warm control resolves the archive index once while computing the cloned part's sizes at load, and the cold arm keeps them lazy, so the oracle was baseline < baseline + 1 and any one-unit perturbation flipped it. Since mid-September every failure is the FileOpen row alone, with the random MergeTree setting use_primary_key_cache = 1: in those jobs' part logs the cold arm loads the primary index (one more FileOpen) while the warm arm hits the cache. Pinning that setting hides this perturbation, not the next.

This adds PackedSkipIndicesArchiveIndexLoads, incremented once per attempted archive-index load at both sites performing one (DataPartStorageOnDiskPacked::getSkipIndicesPackedReader and the DataPartStorageOnDiskBase one used on Full storage), and rewrites the two rows as absolute counts: 0 cold, exactly 1 for the control. Two further arms cover the second site: one load with the archive bundled, zero without. Seeding paths install an index without reading it and do not count, which makes 0 meaningful.

The part log is read only after the tables are dropped, because mutations_sync does not imply the MutatePart row is queued: a mutation is reported done once its result part is visible, while dropping a table waits for its background tasks. The size precondition is asserted per table.

Validation: counts 0/1 and 1/0, identical 3/3; reverting the #112691 guards reddens the cold row alone; deleting the base-class increment reddens the Full row alone; a lazy warm arm reads 0, so the control can fail; 200/200 randomized runs green.

A residual occurrence now names its side: cold != 0 is a real extra read, warm != 1 an unarmed fixture.


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

groeneai and others added 3 commits September 5, 2026 07:22
A part's skip indices can be bundled into one archive (`skp_idx.packed`, or a
virtual file of that name inside `data.packed` on packed part storage), and
reading any of them first requires that archive's index. That read is lazy and
happens at most once per part storage object, on the first access to a bundled
skip index. No counter names it: it only ever showed up mixed into general I/O
counters such as `FileOpen` and `ThreadpoolReaderReadBytes`, so an extra
object-storage read of a part's index archive could not be attributed from
`system.events` or from the `ProfileEvents` map of `system.part_log`.

Count it at both sites that perform the read:

- `DataPartStorageOnDiskPacked::getSkipIndicesPackedReader`, which resolves the
  inner index through the outer archive reader
- `DataPartStorageOnDiskBase::getSkipIndicesPackedReader`, which opens the
  standalone archive on `Full` part storage

Both increments sit after the `skip_indices_packed_probed` memo check, so a
memoized second call counts nothing, and before the read itself, so an attempt
that ends in the 404 path is counted. That path deliberately does not cache a
miss, so a re-probe after a relocation counts again. The seeding paths
(`seedSkipIndicesPackedReader`, `seedSkipIndicesPackedReaderFrom` and the
writer) install an index without reading one, and do not count.

Measured on a mutation of a packed part carrying two minmax indices: a part
whose sizes are computed at load reports 1, a part that keeps them lazy reports
0, and the same fixture on `Full` part storage with index packing disabled
reports 0.

Co-Authored-By: Claude Opus 5 <[email protected]>
04653_packed_part_size_accounting_no_read_in_commit asserted that the commit does
not read a part's skip-index archive by comparing two incidental I/O aggregates
of the whole mutation between a cold arm and a warm control:

    maxIf(ProfileEvents['FileOpen'], cold)                < ... warm
    maxIf(ProfileEvents['ThreadpoolReaderReadBytes'], cold) < ... warm

The entire margin between the two arms is one `disk->readFile`. Measured: cold
`FileOpen` 12 against warm 13, and cold `ThreadpoolReaderReadBytes` 32825
against warm 33215. Both assertions were therefore of the form
`baseline < baseline + 1`, so any one-unit perturbation of unrelated I/O on
either side flipped both rows together. It did: 7 failures against 20774 passes
since the test was added, always both rows at once.

It is not a randomized-settings draw. The two most recent failures were re-run
124 and 121 times with byte-identical randomized settings and did not reproduce
once, so pinning a setting or clamping its range would close nothing.

Assert the operation actually under test instead, as absolute counts on
`PackedSkipIndicesArchiveIndexLoads`. The cold arm must be 0, because the commit
no longer reads and the sizes stay lazy, so the archive is not resolved at all.
The warm control must be exactly 1, because it computes the cloned part's sizes
at load and a part storage resolves that index at most once. No other row
changes, and the strict comparison is not relaxed: two equalities are stricter
than the inequality they replace.

Absolute counts also make a residual occurrence self-diagnosing, which the
inequality could not be. A non-zero cold count is a real extra read in the
commit; a warm count other than 1 is a fixture that was not armed. The old rows
printed the same `0 0` for both.

This does not claim the failure rate drops to zero. No mechanism able to move
both old counters was identified, and that evidence is obtainable neither
locally, where the rate is 0.1 % and does not reproduce under identical
settings, nor from CI, where the test printed only booleans. The claim is that
the oracle no longer depends on quantities the rest of the mutation moves.

Validation: the rewritten test fails on a build with the two
`areColumnAndSecondaryIndexSizesCalculated` guards removed, where the cold count
becomes 1 and only that row moves, and passes with them present; a warm arm
switched to lazy sizes reports 0, so the control can still fail; 220 randomized
runs at 8-way concurrency are green.

Co-Authored-By: Claude Opus 5 <[email protected]>
`PackedSkipIndicesArchiveIndexLoads` is incremented at two sites, but the test
reached only one of them: both of its tables pin
`min_bytes_for_full_part_storage` to 1 GB and the `packed` row asserts `Packed`
part storage, so every count went through the packed override and deleting the
increment from `DataPartStorageOnDiskBase::getSkipIndicesPackedReader` left the
whole test green.

Two arms on `Full` part storage close that. Measured on the fixture: with the
skip indices bundled (`packed_skip_index_max_bytes = '1M'`) the part is `Full`
with 17 files and the mutation's clone opens the standalone archive index
exactly once; with packing disabled the same two minmax indices are written
standalone (103 index bytes either way, 20 files) and the count is 0. The 0
therefore means "no archive to load", not "no indices" and not "the part was
never probed", and the mutation is asserted to have taken the untouched-part
shortcut on both arms so that neither `= 0` row can pass on an empty set.
Deleting the base-class increment now reddens `full_one_archive_load`, and only
that row.

The event description promised the read happens "at most once" per part storage.
It does not: the packed override releases `skip_indices_packed_mutex` after its
memo check and reacquires it only after the read, so concurrent first accesses
can each read, which is the window
`04401_packed_skip_indices_concurrent_read_long.sh` engineers across 50 unprobed
parts, and a probe that finds the archive relocated is deliberately not
memoized. The description now says attempted reads and keeps no bound the code
does not hold, and the test derives its exact 1 from its own single-threaded
fixture instead of from that bound.

The file header also records why the object-storage policy is kept, since the
counter itself is disk-independent.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 5, 2026
@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (1 fix round; 4 findings agreed and fixed, re-review clean)

Two independent passes over this diff, my own cold read and a second-model gate, then one fix round
and a clean re-review of both.

❌ The test did not protect the second instrumented site. Both original arms pin Packed storage,
so every counter assertion ran through DataPartStorageOnDiskPacked::getSkipIndicesPackedReader, and
deleting the increment in the base-class implementation left the whole test green. Fixed: a
Full-storage arm with a bundled archive asserts one load, and an archive-absent control asserts
zero. Checked by deleting the base-class increment alone and confirming only that row moves.

⚠️ The event description promised a bound the code does not hold. It said a part storage reads the
index "at most once", while the packed implementation loads outside the mutex (a concurrent first
probe is exactly what 04401_packed_skip_indices_concurrent_read_long engineers) and neither
implementation memoizes a relocation miss. Reworded to count attempted loads; the test's = 1 now
derives from its single-threaded fixture rather than from a general bound.

💡 Also addressed: the no-fasttest reason argued against itself once the oracle stopped measuring
read volume. Not done: renaming the event to match the Loaded* prefix of the group it sits in,
which is cosmetic.

Session id: cron:clickhouse-review-slot-8:20260905-085900

@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4868397]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
04413_documentation_no_indented_lines FAIL cidb
Stateless tests (amd_debug, sequential) FAIL
05339_iceberg_top_k_query_condition_cache FAIL cidb
Stateless tests (amd_debug, distributed plan, s3 storage, sequential) FAIL
05339_iceberg_top_k_query_condition_cache FAIL cidb
Stateless tests (arm_binary, sequential) FAIL
05339_iceberg_top_k_query_condition_cache FAIL cidb
Stateless tests (arm_asan_ubsan, azure, sequential, 2/2) FAIL
05339_iceberg_top_k_query_condition_cache FAIL cidb
Stateless tests (arm_binary, s3 storage, DBReplicated, sequential) FAIL
05339_iceberg_top_k_query_condition_cache FAIL cidb
Stateless tests (arm_binary, ParallelReplicas, s3 storage, sequential) FAIL
05339_iceberg_top_k_query_condition_cache FAIL cidb
Stateless tests (arm_binary, AsyncInsert, s3 storage, sequential) FAIL
05339_iceberg_top_k_query_condition_cache FAIL cidb
01168_mutations_isolation_3 NOT_FAILED cidb

AI Review

Summary

PR #118234 adds PackedSkipIndicesArchiveIndexLoads to both archive-index loading paths and replaces incidental I/O comparisons in 04653_packed_part_size_accounting_no_read_in_commit with mutation-scoped load counts. It adds Full storage controls and drains background tasks before reading system.part_log. No actionable findings remain, including the previously reported per-table precondition issue. Archived CI at 06a7c5ee7c8a361c9212dec17c9280315cdeaf03 confirms 50/50 passes in both the debug flaky check and the ARM ASan targeted check; the test is unchanged at the current head. No local build or runtime tests were run.

Final Verdict

✅ Approve. No required changes.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 5, 2026
@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano @tiandiwonder, could you review this? 04653_packed_part_size_accounting_no_read_in_commit compared two incidental I/O aggregates whose entire margin between its arms is one disk->readFile, so any unrelated one-unit perturbation flipped both rows (7 failures against 20774 passes). This adds a ProfileEvent incremented at both sites that load a packed skip-indices archive index, and asserts absolute counts instead: 0 for the cold arm, exactly 1 for the control, plus two Full-storage arms that cover the second site.

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 486839722 with master f5b8c2c15 (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

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

Job report

A synchronous mutation is reported done as soon as its result part becomes
visible: getIncompleteMutationsStatus derives is_done from the visible parts'
data versions, which needs only a shared parts lock, and the commit that
publishes the part runs before MutatePlainMergeTreeTask writes its MutatePart
row. mutations_sync therefore does not imply that row is queued, so a
SYSTEM FLUSH LOGS issued straight after the ALTER can miss it.

Measured, not argued: with a 5 s delay injected between the commit and the part
log write, the test reproduced the amd_debug flaky-check failure byte for byte.
full_rows and full_untouched flip to 0 while every counter row stays green,
because maxIf over the empty group lets full_no_archive_zero_load pass on a
missing row. The row itself was correct, only late: written 5.01 s after its
MutatePartStart, after the test had already flushed and read the log.

The four tables are therefore dropped before the part log is read. Dropping a
table waits for that table's background tasks, so afterwards every MutatePart
row is queued and one flush observes all of them. On the same delay-injected
build the restructured test is green and byte identical over three runs, and
both mutation arms still redden exactly one row each.

Also assert the size-accounting precondition per table rather than as an
aggregate over both packed tables. Reading system.data_skipping_indices calls
getSecondaryIndexSizes for every table it lists, so both tables are armed
either way; the aggregate assertion, however, cannot distinguish one armed
table from two. On a fixture where one of the two reports zero index bytes the
old form prints 1 and the per-table form prints 0.
@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

Stateless tests (amd_debug, flaky check) was red on 5b1019e, and it was mine: 1 of 50 runs, full_rows and full_untouched reddening while full_no_archive_zero_load stayed green on a missing MutatePart row. PR-caused, fixed in this PR @ 06a7c5e. Every other check on that commit passed.

mutations_sync does not imply that row is queued. getIncompleteMutationsStatus derives is_done from the visible parts' data versions, which needs only a shared parts lock, and the commit that publishes the part runs before MutatePlainMergeTreeTask writes its part log row. With a 5 s delay injected between the two, the failure reproduces byte for byte and the row arrives 5.01 s after its own MutatePartStart: correct, just late.

The test now reads the part log after dropping the tables, which waits for those tables' background tasks. On the same delay-injected build it is green and byte identical over three runs; both mutation arms still redden exactly one row each, and 200/200 randomized runs pass.

@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 06a7c5e

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, sequential) / Unknown error AST fuzzer oracle false positive, not a test failure. The run's own summary is Failed: 0, Passed: 971, Skipped: 19, and the single <Fatal> line in the server log is ASTFuzzer: AST Fuzzer oracle mismatch detected! from 04658_ast_fuzzer_oracle_tlp_aggregate_counter.sh (Code: 906, Identity WHERE (NOT(NOT p)) oracle mismatch! on approx_top_kOrDefault, which is approximate by construction). That <Fatal> line makes the post-run log check parse the server log, no ERROR_PATTERNS entry matches, and it emits the synthetic Unknown error / "Lost connection to server" row. No crash, no sanitizer report, no OOM. #117200 (external, open)
Mergeable Check, PR rollup of the row above #117200 (external, open)

Praktika tree on this head: 172 nodes, 147 OK / 22 SKIPPED / 0 DROPPED, so the skips are digest
and label skips rather than a dropped matrix.

04653_packed_part_size_accounting_no_read_in_commit, the test this PR is about, is green on this
commit everywhere it ran: 50/50 in each of the five flaky check arms, 50/50 in
arm_asan_ubsan, targeted, and OK in every ordinary stateless parametrization including the
amd_debug, sequential job above.

Session id: cron:our-pr-ci-monitor:20260906-000110

…e-index-load-profile-event

# Conflicts:
#	src/Storages/MergeTree/DataPartStorageOnDiskPacked.cpp
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4868397

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, sequential) / 05339_iceberg_top_k_query_condition_cache master breakage, not from this PR (it changes only ProfileEvents.cpp, DataPartStorageOnDiskBase.cpp, DataPartStorageOnDiskPacked.cpp and the test 04653): the test failed on every master commit from the #126987 merge 41d5f3406f9d until its revert, and the tested merge tree 5d7ad5b584c6 contains #126987 but not the revert #127378 (external, merged revert)
Stateless tests (amd_debug, distributed plan, s3 storage, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_asan_ubsan, azure, sequential, 2/2) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_binary, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_binary, AsyncInsert, s3 storage, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_binary, s3 storage, DBReplicated, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (amd_debug, parallel) / 04413_documentation_no_indented_lines flaky, not from this PR: MEMORY_LIMIT_EXCEEDED in the test's own query, which is quadratic in the number of documentation lines, when the random settings pick enable_lazy_columns_replication = 0 (fails in 22 PRs in 30 days, passes in the 7 other jobs of this head that ran it); the tested merge tree 5d7ad5b584c6 predates the fix #127390 (external, merged)
Mergeable Check, PR praktika rollups of the rows above #127378 and #127390 (the owners of the rows above)

Fast test, Style check and all five Stateless tests (*, flaky check) jobs passed. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261022-193007

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai Please avoid adding profile events for tests unless they are really necessary. New profile events add extra memory to be set and used in each and every query. Prefer simplifying the tests or, if they don't provide anything useful, drop them

@groeneai

Copy link
Copy Markdown
Collaborator Author

Agreed, the event is not needed. The flakiness it was meant to remove is already fixed on master by #129938, which pins use_primary_key_cache = 0 (CIDB shows 0 failures of 04653 in 7,696 runs since it merged). Without the event nothing in this PR is worth keeping, so I am closing it.

@groeneai groeneai closed this Nov 10, 2026
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants