Skip to content

topsql_v2: add detailed TiKV I/O dimensions - #96

Open
jiong-nba wants to merge 1 commit into
tidbcloud:0.49from
jiong-nba:codex/add-tikv-topsql-resource-dimensions
Open

topsql_v2: add detailed TiKV I/O dimensions#96
jiong-nba wants to merge 1 commit into
tidbcloud:0.49from
jiong-nba:codex/add-tikv-topsql-resource-dimensions

Conversation

@jiong-nba

@jiong-nba jiong-nba commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

TiKV TopSQL Detailed I/O Dimensions

Overview

This PR updates the 0.49 TopSQL v2 pipeline to consume and persist the detailed TiKV I/O dimensions introduced by tikv/tikv#19837 and pingcap/kvproto#1498.

It covers the dedicated cloud path implemented on the 0.49 branch:

TiKV -> topsql_v2 -> topsql_data_deltalake -> Delta Lake

Changes

Protocol

  • Add rocksdb_block_read_count = 9 to GroupTagRecordItem.
  • Keep old TiKV payloads compatible: the protobuf default remains 0 when the field is absent.

TopSQL v2 source

  • Propagate rocksdb_block_read_count for both tikv_topsql and tikv_topregion events.
  • Select the per-second candidate union independently by:
    • CPU
    • Combined network input/output
    • Logical reads
    • Logical writes
    • RocksDB block reads
  • Preserve the new dimension when merging upstream/evicted others records and during downsampling.

Delta Lake sink

  • Add nullable topsql_rocksdb_block_read_count to the TopSQL data schema.
  • Keep historical Delta Lake data compatible when older partitions do not contain the new column.

Metric semantics

rocksdb_block_read_count is the number of foreground RocksDB block reads attributed to a request. It is useful for relative TopSQL ranking, but it is not device-level Read IOPS and should not be presented as an exact physical I/O count.

Validation

cargo test --lib sources::topsql_v2::upstream::tikv::parser::tests -- --nocapture
cargo test --lib --features nextgen sources::topsql_v2::upstream::tikv::parser::tests -- --nocapture
cargo test --lib sinks::topsql_data_deltalake::processor::tests::test_topsql_schema_contains_rocksdb_block_read_count -- --nocapture
cargo check --workspace --all-targets
cargo check --workspace --all-targets --features nextgen
git diff --check

Related changes:

Copilot AI review requested due to automatic review settings August 3, 2026 08:33
@pingcap-cla-assistant

pingcap-cla-assistant Bot commented Aug 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Not ready to approve

The updated Top-N cutoff logic has a tie-handling bug and also risks u64 overflow when summing network bytes, which can lead to incorrect filtering/aggregation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR extends the TiKV TopSQL upstream parser to decode and emit additional resource-dimension metrics (network I/O bytes, logical read/write bytes, RocksDB block read count) while preserving existing behaviors like per-second Top-N filtering, others aggregation, and downsampling.

Changes:

  • Extend GroupTagRecordItem (protobuf + Rust handling) to include 5 new TiKV resource usage fields.
  • Emit new TopSQL metrics for the added resource dimensions.
  • Update Top-N filtering, others merging behavior, and downsampling logic/tests to account for the new dimensions.
File summaries
File Description
src/sources/topsql/upstream/tikv/parser.rs Adds field merges, resource-aware Top-N selection, emits new metrics, and extends downsampling/tests.
src/sources/topsql/upstream/tikv/mock_upstream.rs Extends mock TiKV metering records with the new resource fields.
src/sources/topsql/upstream/consts.rs Adds metric name constants for the new TiKV resource dimensions.
proto/tikv.proto Extends the protobuf message with new fields and field numbers (5–9).
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment on lines +149 to +167
let kth_cpu = kth_largest(v.iter().map(|psd| psd.cpu_time_ms), top_n);
let kth_network = kth_largest(
v.iter()
.map(|psd| psd.network_in_bytes + psd.network_out_bytes),
top_n,
);
let kth_logical_read = kth_largest(v.iter().map(|psd| psd.logical_read_bytes), top_n);
let kth_logical_write = kth_largest(v.iter().map(|psd| psd.logical_write_bytes), top_n);
let kth_block_read =
kth_largest(v.iter().map(|psd| psd.rocksdb_block_read_count), top_n);

let mut kept = Vec::with_capacity(v.len());
for psd in std::mem::take(v) {
if psd.cpu_time_ms > kth_cpu
|| psd.network_in_bytes + psd.network_out_bytes > kth_network
|| psd.logical_read_bytes > kth_logical_read
|| psd.logical_write_bytes > kth_logical_write
|| psd.rocksdb_block_read_count > kth_block_read
{
Signed-off-by: jiong-nba <jiongnba@gmail.com>
@jiong-nba
jiong-nba force-pushed the codex/add-tikv-topsql-resource-dimensions branch from 1af8155 to b701ade Compare August 7, 2026 02:33
@ti-chi-bot ti-chi-bot Bot added size/XXL and removed size/XL labels Aug 7, 2026
@jiong-nba
jiong-nba changed the base branch from master to 0.49 August 7, 2026 02:38
@ti-chi-bot ti-chi-bot Bot added size/XL and removed size/XXL labels Aug 7, 2026
@jiong-nba jiong-nba changed the title Add TiKV resource dimensions for topsql topsql_v2: add detailed TiKV I/O dimensions Aug 7, 2026
@jiong-nba
jiong-nba force-pushed the codex/add-tikv-topsql-resource-dimensions branch from a716bd3 to b701ade Compare August 11, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants