Skip to content

Initialize profiler mark caches and handle uncached async loading - #119516

Merged
alexey-milovidov merged 7 commits into
ClickHouse:masterfrom
qoega:codex/fix-storage-memory-profiler
Sep 12, 2026
Merged

alexey-milovidov merged 7 commits into
ClickHouse:masterfrom
qoega:codex/fix-storage-memory-profiler

Conversation

@qoega

@qoega qoega commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

The storage memory profiler creates a lightweight global context but did not initialize its regular or secondary-index mark caches. MergeTree reads could therefore pass a null cache pointer into asynchronous mark loading and fail in pthread_mutex_lock during the storage scenarios.

Initialize both caches from the server settings and cap them by the configured RAM ratio, matching clickhouse-local. MergeTreeMarksLoader already supports a missing cache in synchronous loading, so make the asynchronous path equally safe by skipping the cache lookup while preserving uncached loading through the existing thread pool.

Add --no-mark-caches as an intentional validation mode. The related CI PR runs a dedicated PR-only scenario with asynchronous mark loading and a forced data-skipping index under this mode, while the shared master/PR comparison stays backward-compatible.

Failing CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119480&sha=0f939338cdc9cacc29a817cef37492e3f8d7e5ba&name_0=PR&name_1=Storage%20memory%20check

Related: #119480

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):

Not applicable.


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

Version info

  • Merged into: 26.9.1.1239 (included in 26.9 and later)

MergeTree reads require a context mark cache. Initialize it with the server settings and cap its configured size to the available-memory ratio, matching clickhouse-local.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119480&sha=0f939338cdc9cacc29a817cef37492e3f8d7e5ba&name_0=PR&name_1=Storage%20memory%20check

Related: ClickHouse#119480
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b8aa31c]

Summary: ✅


AI Review

Summary

This PR initializes the regular and secondary-index mark caches in storage_memory_profiler, makes asynchronous mark loading tolerate an absent cache, adds a focused MergeTreeMarksLoader gtest for that null-cache path, and extends the profiler scenarios with a skip-index read. The async null-cache fix itself looks correct, and the new unit test is enough to close the earlier coverage gap, but the default cache initialization changes what the shared storage-memory CI comparison measures against the current merge-base binary.

Findings

⚠️ Majors

src/Examples/storage_memory_profiler.cpp:349 storage_memory_check.py runs the PR checkout's scenario list against both the downloaded merge-base clickhouse-examples binary and the PR binary. After this change, the PR-side profiler keeps mark-cache entries alive across checkpoints, while the merge-base binary still runs without those caches and frees the same marks at query end. The shared comparison therefore stops being a like-for-like storage-scenario comparison and starts reporting the harness change itself as a memory regression. Keep the shared comparison on behavior that the current master binary can also reproduce, and run the cache-enabled validation separately or behind an opt-in mode.

Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit b8aa31c.

Metric Baseline Current Δ
Lines 89.00% 88.90% -0.10%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 30/67 (44.78%) · Uncovered code

Full report · Diff report

Mirror clickhouse-local initialization for the index mark cache and force a skip-index read in the storage scenario so the asynchronous marks-loading path is covered.

Related: ClickHouse#119516

Related: ClickHouse#119480
qoega added a commit to qoega/ClickHouse that referenced this pull request Sep 11, 2026
Mirror clickhouse-local initialization for the index mark cache and force a skip-index read in the storage scenario so the asynchronous marks-loading path is covered.

Related: ClickHouse#119516

Related: ClickHouse#119480
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 11, 2026
@qoega qoega changed the title Initialize mark cache in storage memory profiler Initialize profiler mark caches and handle uncached async loading Sep 11, 2026
@clickhouse-gh clickhouse-gh Bot added comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. and removed comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). labels Sep 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b8aa31cf9 with master 974267656 (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

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

Job report

Cover the null mark-cache path directly in MergeTreeMarksLoader. The test starts an asynchronous zero-mark load with no cache; the old implementation dereferenced storage during the cache lookup, while the fixed implementation completes through the uncached loader.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119480&sha=c5b92dd3b19f7c641e86c2588b5861b3c7b4deaf&name_0=PR&name_1=Storage%20memory%20check

PR: ClickHouse#119480
const size_t configured_mark_cache_size = server_settings[ServerSetting::mark_cache_size];
const size_t mark_cache_size = std::min(configured_mark_cache_size, max_cache_size);
const double mark_cache_size_ratio = server_settings[ServerSetting::mark_cache_size_ratio];
global_context->setMarkCache(mark_cache_policy, mark_cache_size, mark_cache_size_ratio);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

storage_memory_check.py runs the scenario list from the PR checkout against both binaries (ci/jobs/storage_memory_check.py:43-63 and :192-193). With the default cache initialization added here, the PR-side storage_memory_profiler now retains mark-cache entries after the new read in 03_add_secondary_indexes.sql, while the downloaded merge-base binary still has null mark caches and frees the same marks at query end.

That means the shared master/PR comparison is no longer measuring the storage scenario alone; for this PR it is also measuring "mark_cache/index_mark_cache enabled" vs "mark_cache/index_mark_cache absent". Because the storage-memory job flags any change above 100 bytes, even one cached marks file is enough to look like a regression. Please keep the shared comparison on a behavior the current master binary can reproduce, and move the cache-enabled validation to a separate path or make it opt-in instead of the default.

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into ClickHouse:master with commit b1b138d Sep 12, 2026
174 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 12, 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

comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants