server/cluster: avoid repeated region size scans - #11072
Conversation
Cache each key range size for one checkStores round so preparing stores share the same calculation. Move the range size lookup out of the placement rule processing loop. Ref tikv#9574 Signed-off-by: lhy1024 <19542290+lhy1024@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
📝 WalkthroughWalkthroughThe cluster now caches region sizes by key range for each ChangesRegion-size threshold calculations
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
Pass the store snapshot collected by checkStores into each store state check instead of rebuilding the complete store slice for every preparing store. Ref tikv#9574 Signed-off-by: lhy1024 <19542290+lhy1024@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #11072 +/- ##
==========================================
+ Coverage 79.23% 79.24% +0.01%
==========================================
Files 540 541 +1
Lines 76010 76509 +499
==========================================
+ Hits 60226 60631 +405
- Misses 11533 11595 +62
- Partials 4251 4283 +32
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This reverts commit 1bacbb0. Signed-off-by: lhy1024 <19542290+lhy1024@users.noreply.github.com>
Signed-off-by: lhy1024 <19542290+lhy1024@users.noreply.github.com>
|
@lhy1024: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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 kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What problem does this PR solve?
When multiple stores are in the Preparing state, PD recalculates the same
region sizes for every store during each
checkStoresround. With placementrules enabled,
calculateRangealso callsGetRegionSizeByRangeonce forevery matching rule.
For non-empty key ranges, these repeated scans can significantly increase
Region tree lock contention and delay Region heartbeat processing.
Issue Number: ref #9574
What is changed and how does it work?
Limitations
This PR eliminates duplicate range scans across placement rules and Preparing
stores within one
checkStoresround. Each unique non-empty range is stillscanned in O(N) time once per round. Supporting O(log N) range queries or
incremental range-size aggregation will be handled separately.
Check List
Tests
Related changes
Release note
Summary by CodeRabbit
Bug Fixes
Tests