Files
Michael KolupaevandClaude Fable 5.1 7b210c6b7f keeper-utils snapshot-analyzer: finish --top-children, fix error handling 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: https://github.com/ClickHouse/ClickHouse/pull/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 <noreply@anthropic.com>
2026-10-16 19:06:13 -07:00

29 lines
924 B
C++

#pragma once
#include <cstddef>
#include <string>
namespace DB
{
/// Analyze a Keeper snapshot file (or every snapshot in a directory) by streaming it
/// from disk with O(1) memory and printing summary information and statistics.
///
/// If `with_node_stats` is set, the set of all paths is additionally kept in memory
/// (O(number of nodes)) to compute the biggest subtrees - this is the only part that
/// is not O(1) memory.
///
/// `sample_size` random nodes and the `top_children_limit` nodes with the most children are
/// printed too (0 disables).
///
/// Throws if `snapshot_path` is a file that can't be analyzed, or a directory in which some
/// snapshot can't be analyzed (the remaining snapshots in the directory are still analyzed).
void analyzeSnapshot(
const std::string & snapshot_path,
bool with_node_stats,
size_t subtrees_limit,
size_t sample_size,
size_t top_children_limit);
}