-
Notifications
You must be signed in to change notification settings - Fork 735
scheduler: decouple the keyranges with different schedulers #9330
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Skipping CI for Draft Pull Request. |
7fa0925
to
808b7a1
Compare
Signed-off-by: 童剑 <[email protected]>
808b7a1
to
dbff105
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9330 +/- ##
==========================================
+ Coverage 76.02% 76.14% +0.11%
==========================================
Files 475 479 +4
Lines 74080 74636 +556
==========================================
+ Hits 56320 56830 +510
- Misses 14241 14275 +34
- Partials 3519 3531 +12
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Signed-off-by: 童剑 <[email protected]>
885ffe7
to
51f06d1
Compare
Signed-off-by: 童剑 <[email protected]>
51f06d1
to
01f2334
Compare
@@ -429,7 +429,12 @@ func makeInfluence(op *operator.Operator, plan *solver, usedRegions map[uint64]s | |||
// It randomly selects a health region from the source store, then picks | |||
// the best follower peer and transfers the leader. | |||
func (s *balanceLeaderScheduler) transferLeaderOut(solver *solver, collector *plan.Collector) *operator.Operator { | |||
solver.Region = filter.SelectOneRegion(solver.RandLeaderRegions(solver.sourceStoreID(), s.conf.getRanges()), | |||
rs := s.conf.getRanges() | |||
if len(rs) == 1 && len(rs[0].StartKey) == 0 && len(rs[0].EndKey) == 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.
How about adding a function in rs to check len(rs) == 1 && len(rs[0].StartKey) == 0 && len(rs[0].EndKey) == 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.
done
Signed-off-by: 童剑 <[email protected]>
@@ -137,6 +137,11 @@ func (s *balanceRegionScheduler) Schedule(cluster sche.SchedulerCluster, dryRun | |||
solver.Step++ | |||
var sourceIndex int | |||
|
|||
rs := s.conf.Ranges |
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.
Does the Ranges always have a value?
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.
yes, it can be seen as
pd/pkg/schedule/schedulers/utils.go
Lines 218 to 237 in 6f886e0
func getKeyRanges(args []string) ([]keyutil.KeyRange, error) { | |
var ranges []keyutil.KeyRange | |
for len(args) > 1 { | |
startKey, err := url.QueryUnescape(args[0]) | |
if err != nil { | |
return nil, errs.ErrQueryUnescape.Wrap(err) | |
} | |
endKey, err := url.QueryUnescape(args[1]) | |
if err != nil { | |
return nil, errs.ErrQueryUnescape.Wrap(err) | |
} | |
args = args[2:] | |
ranges = append(ranges, keyutil.NewKeyRange(startKey, endKey)) | |
} | |
if len(ranges) == 0 { | |
return []keyutil.KeyRange{keyutil.NewKeyRange("", "")}, nil | |
} | |
return ranges, nil | |
} |
) | ||
|
||
// KeyRangeManager is a manager for key ranges. | ||
type KeyRangeManager struct { |
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 keyutil is a more proper package?
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.
moved to the new pkg pkg/schedule/rangelist
@@ -429,7 +429,12 @@ func makeInfluence(op *operator.Operator, plan *solver, usedRegions map[uint64]s | |||
// It randomly selects a health region from the source store, then picks | |||
// the best follower peer and transfers the leader. | |||
func (s *balanceLeaderScheduler) transferLeaderOut(solver *solver, collector *plan.Collector) *operator.Operator { | |||
solver.Region = filter.SelectOneRegion(solver.RandLeaderRegions(solver.sourceStoreID(), s.conf.getRanges()), | |||
rs := s.conf.getRanges() | |||
if IsDefaultKeyRange(rs) { |
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.
How about the hot region scheduler?
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.
Hot region scheduler can schedule all the regions, not restricting this limit.
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
1aa9b40
to
0e2a025
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lhy1024 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
ping @rleungx again |
for _, r := range rs { | ||
s.sortedKeyRanges.Append(r.StartKey, r.EndKey) | ||
} | ||
s.sortedKeyRanges.SortAndDeduce() |
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.
For every time we append, we need to sort?
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.
yes
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.
done, using adjust function to check the two regions
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
@@ -41,6 +41,36 @@ func MinKey(a, b []byte) []byte { | |||
return a | |||
} | |||
|
|||
// MaxKeyWithBoundary returns the bigger key for the given keys. | |||
// it is different from MaxKey, if the key is empty and the boundary is right, the empty key is biggest, | |||
func MaxKeyWithBoundary(a, b []byte, opt boundary) []byte { |
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.
How about changing to MaxStartKey/MinEndKey? The boundary is useless.
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.
good idea
for i := 1; i < len(rs.krs); i++ { | ||
last := res[len(res)-1] | ||
if last.IsAdjacent(rs.krs[i]) { | ||
last.StartKey = MinKeyWithBoundary(last.StartKey, rs.krs[i].StartKey, left) |
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 has already been sorted, no need to compare?
rs := s.conf.getRanges() | ||
if IsDefaultKeyRange(rs) { | ||
km := solver.GetKeyRangeManager() | ||
rs = km.GetNonOverlappingKeyRanges(&rs[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.
Will it slow down the balance leader's speed?
@@ -137,6 +137,11 @@ func (s *balanceRegionScheduler) Schedule(cluster sche.SchedulerCluster, dryRun | |||
solver.Step++ | |||
var sourceIndex int | |||
|
|||
rs := s.conf.Ranges |
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.
What if we change the range manually?
What problem does this PR solve?
Issue Number: Close #9302
What is changed and how does it work?
Check List
Tests
Code changes
Side effects
Related changes
pingcap/docs
/pingcap/docs-cn
:pingcap/tiup
:Release note