Skip to content

Improvements to keeper-utils analyze-snapshot - #106270

Merged
alexey-milovidov merged 8 commits into
masterfrom
keeper-snapshot-stats
Oct 20, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
keeper-snapshot-stats

Conversation

@al13n321

@al13n321 al13n321 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

A straightforward mostly-vibecoded (but I have reviewed the code) tool that prints lots of stats about Keeper snapshot contents. Replaces clickhouse keeper-utils analyze-snapshot, which printed much fewer stats and was picky about input filename format. Existing features are preserved (with-node-stats and the few stats that were previously printed).

Switched from using SnapshotManager to custom deserialization code (duplicating SnapshotManager, so it'll need to be kept in sync) to avoid building a whole KeeperStorage in memory. It's simple enough and stable enough that the duplication seems ok.

% time build/programs/clickhouse keeper-utils snapshot-analyzer --snapshot-path ~/t/snap54.bin.zstd
=== Snapshot: /home/al13n/t/snap54.bin.zstd ===
Processed 10000000 / 111360784 nodes
Processed 20000000 / 111360784 nodes
Processed 30000000 / 111360784 nodes
Processed 40000000 / 111360784 nodes
Processed 50000000 / 111360784 nodes
Processed 60000000 / 111360784 nodes
Processed 70000000 / 111360784 nodes
Processed 80000000 / 111360784 nodes
Processed 90000000 / 111360784 nodes
Processed 100000000 / 111360784 nodes
Processed 110000000 / 111360784 nodes
  Last committed log index: 139193018826
  Last committed log term: 53655
  Snapshot format version: 7
  Uncompressed snapshot size: 26736849413 bytes
  Number of nodes: 111360784
  Ephemeral nodes: 81175
  TTL nodes: 0
  Container nodes: 0
  Digest: none (disabled, unsupported digest version, or pre-V5 snapshot)
  ZXID: 139129199059
  Session ID counter: 63800290
  Nodes with non-empty data: 63242825
  Total node data size: 5183422805 bytes (avg 46.5)
  Max node data size: 254322 bytes
  Sum of path lengths: 12822837947 (avg 115.1)
  Sum of last-component lengths: 2642239223 (avg 23.7)
  Max number of children: 11750268
  Top 5 nodes by children count:
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects: 11750268 children
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_transactions: 343188 children
    /clickhouse/sessions/zookeeper: 27393 children
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects/8092221579/.dir: 13879 children
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects/12674535664/.dir: 13072 children
  Nodes by children count:
    0: 91823682
    1: 11993683
    2: 26066
    3: 11962
    4: 11113
    >4: 7494278
  ACL map size: 0
  Nodes with non-empty ACL: 0
  Number of sessions: 9751
  Random sample of up to 20 nodes (path: data size):
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects/12315259146/.dir/event_date.bin: 11 bytes
    /clickhouse/tables/a6534ba3-f652-4e3d-840a-3cc7d5de03b3/default/async_blocks/202403_4568171853653271131_10145634717533886968: 20 bytes
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects/12318526101/.dir/ProfileEvent_PerfCacheReferences.sparse.idx.cmrk2: 11 bytes
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects/22685547075/.data: 104 bytes
    /clickhouse/tables/cee99bea-0547-425f-9e0a-e0332f316011/default/async_blocks/202503_6448164381955659400_17045717571342081732: 18 bytes
    /clickhouse/tables/2a610a7a-a276-4204-a7a3-4abac28a8625/default/async_blocks/202504_761568444491119872_14286062054095641668: 18 bytes
    /clickhouse/tables/098c77d1-ed28-4e71-be57-280bf72b5d5f/default/replicas/c-mint-ej-28-server-zrj65oq-0/flags/parts_attributes_serde_version=2: 0 bytes
    /clickhouse/tables/0b996516-137d-46af-8994-0ccb2a10f351/default/replicas/c-mint-ej-28-server-ubkwcc5-0: 0 bytes
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects/24002888468/.data: 112 bytes
    /clickhouse/tables/9356331c-8020-4c59-aa75-b64fe7aee224/default/replicas/c-mint-ej-28-server-uf9758b-0/flags/clickhouse_version=26.5.1.186: 0 bytes
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects/12318227365/.dir/ProfileEvent_DistributedConnectionSkipReadOnlyReplica.sparse.idx.cmrk2: 11 bytes
    /clickhouse/tables/d957e554-bc01-498e-a8c7-b7f2aaaca0c7/default/replicas/c-mint-ej-28-server-teab4a3-0/host: 192 bytes
    /clickhouse/tables/1e792dae-6a5c-4497-96d0-1925bf210eaf/default/replicas/c-mint-ej-28-server-8cgijhf-0/flags/part_in_memory_data_serde=2: 0 bytes
    /clickhouse/tables/d95c518f-a9fa-4e71-94f5-f115ef16e43b/default/deduplication_hashes/202603_9771346336038807549_12155958216800705048: 22 bytes
    /clickhouse/tables/9a6bd16a-2e64-4e90-9dc1-7692ce744819/default/replicas/c-mint-ej-28-server-qr9qmeu-0/flags/enable_coordinated_merges: 0 bytes
    /clickhouse/tables/355b01fd-3c19-4d16-902b-b25dfc4cc4c0/default/replicas/c-mint-ej-28-server-ze3tsrz-0/flags/part_in_memory_data_serde=2: 0 bytes
    /ch-s3-131ac5a5-f6aa-4a8f-9827-457a195d2494/mergetree/_objects/14634110244/.dir/ProfileEvent_RuntimeFilterRowsSkipped.sparse.idx.cmrk2: 11 bytes
    /clickhouse/tables/c2c5241a-eeed-4353-ba49-162f5025692d/default/replicas/c-mint-ej-28-server-747yfuk-0/mutations_pointer: 0 bytes
    /clickhouse/tables/30df77b3-b74d-4d38-a1ba-51431606da62/default/replicas/c-mint-ej-28-server-16vew6h-0/flags/parts_attributes_serde_version=2: 0 bytes
    /clickhouse/tables/3b1a4cff-1ced-4dc3-80b1-e6bec54d6592/default/blocks/202604_1098746869527631745_1783608367657059364: 20 bytes
  Predicted KeeperMemNodesStorage memory usage (not very accurate, expect ~20% underestimate):
    KeeperMemNode (104 B):                       11581521536 bytes (11045.0 MiB)
    ListNode and std::list overhead (40 B):       4454431360 bytes (4248.1 MiB)
    Paths:                                       12822837947 bytes (12228.8 MiB)
    Node data:                                    5183422805 bytes (4943.3 MiB)
    Children flat_hash_sets (>1 child):           2530464856 bytes (2413.2 MiB)
    Index HashMap:                                6442450944 bytes (6144.0 MiB)
    Ephemerals:                                     13171750 bytes (12.6 MiB)
    Sessions:                                         780080 bytes (0.7 MiB)
    Total:                                       43029081278 bytes (41035.7 MiB)

build/programs/clickhouse keeper-utils snapshot-analyzer --snapshot-path   16.48s user 0.13s system 99% cpu 16.680 total

(The last number 41093.3 MiB is ~20% underestimated, the actual clickhouse RSS was 50 GiB. My guess is that around half of the difference is jemalloc bin rounding, half is non-KeeperStorage memory.)


Some of the prompts:

Please make a minimal tool that reads a Keeper snapshot file and prints stats: number of znodes, number of ephemeral znodes, total znode data size, max znode data size, number of znodes with nonempty data, sum of path lengths, sum of lengths of last components of paths, max number of children, number of znodes with [0, 1, 2, 3, 4, >4] children, acl map size (only if serialization version is new enough that the map is stored separately), number of znodes with nonempty acl list, number of sessions, snapshot uncompressed size, paths and data sizes of 20 znodes chosen uniformly at random. Stream the data in, use O(1) memory, go reasonably fast. Decide whether it's better to reuse the existing deserialization code or duplicate it. Maybe make the tool a keeper-bench mode, maybe find a more appropriate place for it.

Please also print avgs next to totals: path len, path last component len, data len.

Print progress to stderr every 1M nodes.

Don't print number of znodes twice (in "Number of paths" and in stats), don't indent "Stats" an extra level.

Look at KeeperStorage code and make a formula for predicting memory usage (for memory storage, no rocksdb) based on the stats above. Make sure to include e.g. overhead from all the containers (std::list and HashMap in SnapshotableHashTable, CompactChildrenSet's flat_hash_set if >1 child, etc). Print the result and breakdown (e.g. this many bytes of NodeStats, this many bytes of std::list links, this many bytes of flat_hash_set-s, etc) in the tool's output.


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

Version info

  • Merged into: 26.11.1.343-master (included in 26.11 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a5a3411]

Summary: ✅


AI Review

Summary

The PR streams Keeper snapshots to report richer node statistics, samples, subtree sizes, and memory estimates. The current code addresses the six earlier review findings. No new actionable code findings remain.

Missing context / blind spots
  • ⚠️ Runtime validation remains unconfirmed: the retrieved integration reports contain no results for test_snapshot_analyzer, and the current workflow data lists the targeted integration jobs as pending. A completed run of both parametrizations would close this gap; no local ClickHouse build was available.
Final Verdict

Status: ✅ Approve based on code review and the supplied regression coverage. Integration execution remains subject to CI completion.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 2, 2026
Comment thread programs/keeper-utils/KeeperUtils.cpp Resolved
@antonio2368 antonio2368 self-assigned this Jun 3, 2026

@antonio2368 antonio2368 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.

Nothing new apart from what the review bot already found.
Good changes.

@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.50% 92.50% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 0/323 (0.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@al13n321

Copy link
Copy Markdown
Contributor Author

Big changes to snapshots coming in #107884 and then in #107261 , will rebase onto those eventually.

@al13n321
al13n321 marked this pull request as draft June 19, 2026 08:13
auto-merge was automatically disabled June 19, 2026 08:13

Pull request was converted to draft

@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

This PR only rewrites the standalone clickhouse-keeper-utils snapshot-analyzer command (a new SnapshotAnalyzer source plus its CLI options and docs); it does not touch any code the server runs to execute SELECT queries. The two flagged ClickBench improvements (Q4 -15.7%, Q15 -12.3%) therefore cannot be caused by this change and are run-to-run variance, so both have been downgraded to not-sure. No genuine performance impact is expected from this PR.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 4 not_sure 267 225 -15.7% <0.0001 PR only touches the keeper-utils snapshot-analyzer CLI; cannot affect ClickBench query execution. -15.7% is run variance
⚠️ 15 not_sure 249 218 -12.2% <0.0001 Same off-path PR (keeper snapshot CLI only); server query path untouched, so -12.3% is not a PR effect.

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
  • StressHouse run: bfcb97d3-1ed6-410b-b094-f2789d4ce8d0
  • MIRAI run: 283c095d-5d71-4460-ad24-23a99e4b3428
  • PR check IDs:
    • clickbench_35329_1782124105
    • clickbench_35335_1782124105
    • clickbench_35344_1782124105
    • tpch_adapted_1_official_35351_1782124105
    • tpch_adapted_1_official_35362_1782124105
    • tpch_adapted_1_official_35375_1782124105

@al13n321
al13n321 force-pushed the keeper-snapshot-stats branch from 1de6a5a to a3fa217 Compare August 1, 2026 01:02
@abashkeev abashkeev added the comp-keeper ClickHouse Keeper (Raft-based coordination layer; ZooKeeper replacement) and ZooKeeper client lib... label Sep 4, 2026
alexey-milovidov and others added 4 commits September 8, 2026 05:46
…ndling and ordering

The previous commit added `TopChildrenTracker` and the `--top-children` option but did
not wire them into `analyzeSnapshot`, so the build failed with `-Wmissing-prototypes`
(the definition did not match the declaration) and clang-tidy reported the tracker as
unused:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=106270&sha=d74d5b7fedcbac408f79a2a316b08d673d2406f7&name_0=PR&name_1=Fast%20test
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=106270&sha=d74d5b7fedcbac408f79a2a316b08d673d2406f7&name_0=PR&name_1=Build%20%28arm_tidy%29
PR: #106270

Also address review comments:
- A failure to analyze a single snapshot file now propagates, so the command exits
  with a non-zero code instead of just printing to stderr. In directory mode the
  remaining snapshots are still analyzed, but an exception is thrown at the end if
  any of them failed.
- Snapshots in a directory are sorted by the log index parsed from the file name
  (`getLogIdxFromSnapshotPath`) instead of lexicographically, so `snapshot_10.bin`
  really comes before `snapshot_9.bin`.
- Whether `--snapshot-path` is a file or a directory is decided by `is_directory`
  instead of the file extension.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Runs `clickhouse keeper-utils snapshot-analyzer` on snapshots written by Keeper in both
zstd and `CompressedWriteBuffer` formats, with and without the nodes digest, and checks
the printed statistics, the directory mode ordering and the exit code on a broken snapshot.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@al13n321
al13n321 marked this pull request as ready for review October 17, 2026 02:09
@alexey-milovidov alexey-milovidov self-assigned this Oct 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a5a3411cd with master 02fd3427a (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 110043e5d; 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.

Object file sizes

3 object files changed (+188.84 KiB total), 1 added.

Object file Master PR Δ
programs/keeper-utils/CMakeFiles/clickhouse-keeper-utils-lib.dir/SnapshotAnalyzer.cpp.o new 236.78 KiB +236.78 KiB
programs/keeper-utils/CMakeFiles/clickhouse-keeper-utils-lib.dir/KeeperUtils.cpp.o 719.91 KiB 671.97 KiB -47.94 KiB (-6.66%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Translation units without a recent master baseline:

  • programs/keeper-utils/SnapshotAnalyzer.cpp: 5.8 s

Job report

@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Dear @antonio2368, 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
alexey-milovidov added this pull request to the merge queue Oct 20, 2026
Merged via the queue into master with commit 63b1512 Oct 20, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the keeper-snapshot-stats branch October 20, 2026 20:06
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-keeper ClickHouse Keeper (Raft-based coordination layer; ZooKeeper replacement) and ZooKeeper client lib... pr-not-for-changelog This PR should not be mentioned in the changelog 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.

5 participants