-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store/tikv: Make RangeTaskRunner support dividing task by multiple regions #10482
store/tikv: Make RangeTaskRunner support dividing task by multiple regions #10482
Conversation
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
…concurrent-resolve-lock
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
…yonKeminta/tidb into misono/concurrent-resolve-lock
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## master #10482 +/- ##
================================================
- Coverage 81.0157% 80.9952% -0.0205%
================================================
Files 419 419
Lines 88747 88825 +78
================================================
+ Hits 71899 71944 +45
- Misses 11629 11652 +23
- Partials 5219 5229 +10 |
…concurrent-resolve-lock
/run-all-tests pd=pr/1535 |
} | ||
regions = append(regions, region) | ||
} | ||
if len(regions) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate condition checking with L531.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the same, since not every item in metas
will be added to regions
if len(regions) == 0 { | ||
return nil, errors.New("receive Regions with no peer") | ||
} | ||
if len(regions) < len(metas) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems len(regions) always equal to len(metas)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regions with no leader will be ignored.
…range-task-multi-region
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
the rest LGTM |
…range-task-multi-region
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
/run-all-tests |
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
…yonKeminta/tidb into misono/range-task-multi-region
LGTM |
@disksing Do you think this should be cherry-picked to release-3.0? |
I think yes. PTAL @zhangjinpeng1987 |
…range-task-multi-region
@lysu Could you please help me check if I've used the new refactored region cache the correct way? |
defer c.RUnlock() | ||
|
||
regions := make([]*Region, 0, len(c.regions)) | ||
for _, region := range c.regions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use copy(regions, c.regions)
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.regions
is a map and I only needs its values. It seems that copy
doesn't work well here.
c.RLock() | ||
defer c.RUnlock() | ||
|
||
regions := make([]*Region, 0, len(c.regions)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need limit
regions but copy the entire slice here. It's OK because the mocktikv will not contain a lot of regions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regions is in arbitrary order and ScanRegions needs to scan regions by key. I get all regions here and do a sorting below. I think this will be faster than finding regions by key for at most limit
times, because the mock cluster doesn't support quickly finding region by key. You can see that in GetRegionByKey
method, it does a linear searching on c.regions
.
for _, region := range regions { | ||
leader := region.leaderPeer() | ||
if leader == nil { | ||
leader = &metapb.Peer{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems violate the semantics of this function if we return invalid leader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as PD's ScanRegions API. It uses a repeated field for leaders so that it can't be nil. Therefore we judge if a region has no leader by checking if the leader's ID is 0.
…range-task-multi-region
/run-all-tests |
/run-unit-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What problem does this PR solve?
This PR continue improves #10379 and should be merged after that PR.
Also requires pingcap/kvproto#396 and tikv/pd#1535 .
The implementation of
RangeTaskRunner
in #10379 divides the range by regions in one thread, and dispatch these tasks to the worker threads. But if the concurrency is set too high or the tasks costs too short time to finish, then the single thread which is responsible to fetch region meta and divide the range will be the bottleneck ofRangeTaskRunner
. This PR makes it support divides the ranges by multiple regions to reduce the main thread orRangeTaskRunner
.What is changed and how it works?
ScanRegions
of PD is added in pdpb: add ScanRegions kvproto#396 .BatchLoadRegions
toRegionCache
. It invokesScanRegions
of PDClient, fill the scanned regions toRegionCache
, and return the end key of the last scanned region.RangeTaskRunner,
the main threads invokesBatchLoadRegions
to divide the region into multiple tasks, and the number of regions of each divided subtask is configurable.Check List
Tests
Code changes
Side effects
Related changes