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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 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🧪 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.33% +0.10%
==========================================
Files 540 541 +1
Lines 76010 76675 +665
==========================================
+ Hits 60226 60832 +606
- Misses 11533 11560 +27
- 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>
Signed-off-by: lhy1024 <19542290+lhy1024@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bufferflies, rleungx The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
/retest |
1 similar comment
|
/retest |
|
In response to a cherrypick label: new pull request created to branch |
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