Skip to content

KVStore: fix tiflash_raft_throughput_bytes warp problem#10700

Merged
ti-chi-bot[bot] merged 6 commits intopingcap:masterfrom
CalvinNeo:fix-warp
Feb 5, 2026
Merged

KVStore: fix tiflash_raft_throughput_bytes warp problem#10700
ti-chi-bot[bot] merged 6 commits intopingcap:masterfrom
CalvinNeo:fix-warp

Conversation

@CalvinNeo
Copy link
Member

@CalvinNeo CalvinNeo commented Feb 4, 2026

What problem does this PR solve?

Issue Number: close #10701

Problem Summary:

What is changed and how it works?


Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Fixed an issue where Grafana's Raft throughput might incorrectly display very large values.

Summary by CodeRabbit

  • Bug Fixes
    • Safer storage size accounting implemented to prevent underflow/overflow on edge-case writes.
    • Size updates unified across insert paths, improving accuracy of write-size reporting and reducing risk of rare errors or crashes while preserving existing insert behavior.

Signed-off-by: Calvin Neo <calvinneo1995@gmail.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 4, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds a guarded local updater in RaftCommands.cpp that centralizes write_size adjustments: entries compute a payload (unifying v2 and non-v2 paths), then call update_write_size(payload) which handles positive, negative, and INT64_MIN edge cases to avoid underflow.

Changes

Cohort / File(s) Summary
Raft Payload Handling
dbms/src/Storages/KVStore/MultiRaft/RaftCommands.cpp
Replaced direct write_size modifications with a local update_write_size(payload) lambda; both v2 and non-v2 insert branches now compute a single payload via doInsert/dup-check and call the updater, which clamps negative adjustments and handles INT64_MIN edge case to prevent underflow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 I nibble bytes with gentle paws,
Tallying payloads without a pause,
Clamp the dips, dodge the fall,
Keep counts steady, one and all —
A cautious hop, a guarded cause.

🚥 Pre-merge checks | ✅ 2 | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description follows the template structure but has critical gaps: the 'What is changed and how it works?' section is empty, no commit message is provided, and no tests are documented. Fill in the 'What is changed and how it works?' section with implementation details, provide commit message, and specify what tests were performed.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive Issue #10701 is incomplete—it lacks reproduction steps, expected vs. actual outputs, and version details needed to validate whether the code changes address the reported metric warp problem. Complete issue #10701 with reproduction steps, expected behavior, and actual behavior observed to confirm the fix addresses the root cause.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'KVStore: fix tiflash_raft_throughput_bytes warp problem' is specific and clearly indicates the module and the bug being fixed.
Out of Scope Changes check ✅ Passed Code changes focus on safe write_size handling and payload accounting in RaftCommands, which aligns with fixing a metric warp issue; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@dbms/src/Storages/KVStore/MultiRaft/RaftCommands.cpp`:
- Around line 385-398: The code mixes signed payload with unsigned write_size
causing wrap/overflow; fix by treating payload as a signed integer before doing
arithmetic: capture payload from doInsert into a signed type (e.g., long long)
such as payload_signed = static_cast<long long>(... .payload), then if
(payload_signed > 0) do write_size += static_cast<size_t>(payload_signed); else
if (write_size >= static_cast<size_t>(-payload_signed)) do write_size -=
static_cast<size_t>(-payload_signed). Apply this change in both branches that
call doInsert (the blocks guarded by is_v2 and the else), referencing doInsert,
payload, write_size and DupCheck.

Signed-off-by: Calvin Neo <calvinneo1995@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 4, 2026
@JaySon-Huang JaySon-Huang changed the title fix tiflash_raft_throughput_bytes warp problem raft: fix tiflash_raft_throughput_bytes warp problem Feb 4, 2026
@JaySon-Huang JaySon-Huang changed the title raft: fix tiflash_raft_throughput_bytes warp problem KVStore: fix tiflash_raft_throughput_bytes warp problem Feb 4, 2026
CalvinNeo and others added 4 commits February 5, 2026 01:20
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 5, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 5, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JaySon-Huang, JinheLin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [JaySon-Huang,JinheLin]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 5, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 5, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-05 03:55:45.858370432 +0000 UTC m=+325616.959769150: ☑️ agreed by JaySon-Huang.
  • 2026-02-05 07:18:23.950297304 +0000 UTC m=+337775.051696020: ☑️ agreed by JinheLin.

@ti-chi-bot ti-chi-bot bot merged commit 74de3a5 into pingcap:master Feb 5, 2026
8 checks passed
@JaySon-Huang
Copy link
Contributor

/cherry-pick release-8.5

@ti-chi-bot
Copy link
Member

@JaySon-Huang: new pull request created to branch release-8.5: #10705.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-8.5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Feb 5, 2026
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Feb 5, 2026
wshwsh12 pushed a commit to wshwsh12/tiflash that referenced this pull request Feb 9, 2026
close pingcap#10701

Signed-off-by: Calvin Neo <calvinneo1995@gmail.com>

Co-authored-by: JaySon <tshent@qq.com>
ti-chi-bot bot pushed a commit that referenced this pull request Feb 9, 2026
)

close #10701

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: JaySon-Huang <tshent@qq.com>

Co-authored-by: Calvin Neo <CalvinNeo@users.noreply.github.com>
Co-authored-by: JaySon-Huang <tshent@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tiflash_raft_throughput_bytes may warp

4 participants