Skip to content

raftstore: reset region approximate size/keys stats when it becomes leader#19181

Merged
ti-chi-bot[bot] merged 3 commits intotikv:masterfrom
glorv:fix-region-hb
Dec 8, 2025
Merged

raftstore: reset region approximate size/keys stats when it becomes leader#19181
ti-chi-bot[bot] merged 3 commits intotikv:masterfrom
glorv:fix-region-hb

Conversation

@glorv
Copy link
Contributor

@glorv glorv commented Dec 8, 2025

What is changed and how it works?

Issue Number: Close #19180

What's Changed:

Reset region's approximate size/keys stats when peer becomes leader. This can avoid peer report outdated stats to pd and caused unnecessary balance scheduling.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

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

Release note

Fix the bug that pd heartbeat may report wrong region size/keys statistics data after leader change.

@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. dco-signoff: yes Indicates the PR's author has signed the dco. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 8, 2025
Signed-off-by: glorv <glorvs@163.com>
.pd_client
.get_region_approximate_size(region_id)
.unwrap_or_default();
assert_eq!(size, 0);
Copy link
Member

Choose a reason for hiding this comment

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

It's technically possible to let the test pd-client ignore the 0 value as well, right? If we do that, we will be able to assert size >= 2000 in the end. But we will need to ensure that the new leader has uploaded its heartbeat (possibily using a failpoint).

Copy link
Contributor

Choose a reason for hiding this comment

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

+1. we can add an assertion for the final state (size >= 2000).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@hhwyt hhwyt left a comment

Choose a reason for hiding this comment

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

Rest LGTM

.pd_client
.get_region_approximate_size(region_id)
.unwrap_or_default();
assert_eq!(size, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

+1. we can add an assertion for the final state (size >= 2000).

Signed-off-by: glorv <glorvs@163.com>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 8, 2025
@glorv
Copy link
Contributor Author

glorv commented Dec 8, 2025

@hbisheng PTAL again, thanks

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 8, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 8, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-12-08 07:13:16.250627183 +0000 UTC m=+852341.064404754: ☑️ agreed by hhwyt.
  • 2025-12-08 08:12:33.531703407 +0000 UTC m=+855898.345480979: ☑️ agreed by hbisheng.

@glorv
Copy link
Contributor Author

glorv commented Dec 8, 2025

/approve

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 8, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: glorv, hbisheng, hhwyt

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:

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 the approved label Dec 8, 2025
@glorv
Copy link
Contributor Author

glorv commented Dec 8, 2025

/retest

@glorv
Copy link
Contributor Author

glorv commented Dec 8, 2025

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 8, 2025
@glorv
Copy link
Contributor Author

glorv commented Dec 8, 2025

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 8, 2025
@glorv
Copy link
Contributor Author

glorv commented Dec 8, 2025

/retest

@jebter
Copy link
Collaborator

jebter commented Dec 8, 2025

/test pull-unit-test

@glorv glorv added needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. labels Dec 8, 2025
@glorv
Copy link
Contributor Author

glorv commented Dec 8, 2025

/retest

@ti-chi-bot ti-chi-bot bot merged commit ede1a44 into tikv:master Dec 8, 2025
9 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone Dec 8, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #19184.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #19185.

@glorv glorv deleted the fix-region-hb branch December 8, 2025 13:36
glorv added a commit to glorv/tikv that referenced this pull request Dec 8, 2025
…eader (tikv#19181)

close tikv#19180

Reset region's approximate size/keys stats when peer becomes leader. This can avoid peer report outdated stats to pd and caused unnecessary balance scheduling.

Signed-off-by: glorv <glorvs@163.com>
glorv added a commit that referenced this pull request Dec 8, 2025
…eader (#19181) (#19186)

close #19180

Reset region's approximate size/keys stats when peer becomes leader. This can avoid peer report outdated stats to pd and caused unnecessary balance scheduling.

Signed-off-by: glorv <glorvs@163.com>
ti-chi-bot bot pushed a commit that referenced this pull request Dec 10, 2025
…eader (#19181) (#19185)

close #19180

Reset region's approximate size/keys stats when peer becomes leader. This can avoid peer report outdated stats to pd and caused unnecessary balance scheduling.

Signed-off-by: glorv <glorvs@163.com>

Co-authored-by: glorv <glorvs@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Region approximate_size/keys may be incorrect after leader transfer

5 participants