-
Notifications
You must be signed in to change notification settings - Fork 728
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
schedulers: region should splitted if region is too hot. #6618
Merged
Merged
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
dea2914
hot region
bufferflies f1676d4
add test for write
bufferflies 9fe27cf
extra const variable
bufferflies 25b0145
lint
bufferflies 311bb19
pass ut
bufferflies b90e13a
Merge branch 'master' into hot_region_split
bufferflies 4933372
skip if only one bucket hot
bufferflies ad8434b
Merge branch 'master' into hot_region_split
bufferflies 85c242f
default MaxMovableHotPeerSize
bufferflies ce8df89
rename too hot and add comment for function
bufferflies 7aa5c81
Merge branch 'master' into hot_region_split
bufferflies a3faee3
add config for split thresholds
bufferflies 273b196
Merge branch 'hot_region_split' of github.com:bufferflies/pd into hot…
bufferflies 6d8cdc7
pass unit
bufferflies a6006b1
avoid panic
bufferflies 5f25ce5
logic error
bufferflies db9247d
make config more reasonable
bufferflies 019d0a0
Merge branch 'master' into hot_region_split
bufferflies 3628645
pass ut
bufferflies 6310efe
pass ut
bufferflies 787f6f1
update master
bufferflies 1305bd3
pass ut
bufferflies 3bd39cb
Merge branch 'master' into hot_region_split
ti-chi-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ var ( | |
hotSchedulerRegionBucketsNotHotCounter = schedulerCounter.WithLabelValues(HotRegionName, "region_buckets_not_hot") | ||
hotSchedulerSplitSuccessCounter = schedulerCounter.WithLabelValues(HotRegionName, "split_success") | ||
hotSchedulerNeedSplitBeforeScheduleCounter = schedulerCounter.WithLabelValues(HotRegionName, "need_split_before_move_peer") | ||
hotSchedulerRegionIsTooHotCounter = schedulerCounter.WithLabelValues(HotRegionName, "region_is_too_hot") | ||
|
||
hotSchedulerMoveLeaderCounter = schedulerCounter.WithLabelValues(HotRegionName, moveLeader.String()) | ||
hotSchedulerMovePeerCounter = schedulerCounter.WithLabelValues(HotRegionName, movePeer.String()) | ||
|
@@ -159,21 +160,23 @@ func (h *baseHotScheduler) prepareForBalance(rw statistics.RWType, cluster sche. | |
// It makes each dim rate or count become `weight` times to the origin value. | ||
func (h *baseHotScheduler) summaryPendingInfluence() { | ||
for id, p := range h.regionPendings { | ||
from := h.stInfos[p.from] | ||
to := h.stInfos[p.to] | ||
maxZombieDur := p.maxZombieDuration | ||
weight, needGC := calcPendingInfluence(p.op, maxZombieDur) | ||
|
||
if needGC { | ||
delete(h.regionPendings, id) | ||
continue | ||
} | ||
for _, from := range p.froms { | ||
from := h.stInfos[from] | ||
to := h.stInfos[p.to] | ||
maxZombieDur := p.maxZombieDuration | ||
weight, needGC := calcPendingInfluence(p.op, maxZombieDur) | ||
|
||
if needGC { | ||
delete(h.regionPendings, id) | ||
continue | ||
} | ||
|
||
if from != nil && weight > 0 { | ||
from.AddInfluence(&p.origin, -weight) | ||
} | ||
if to != nil && weight > 0 { | ||
to.AddInfluence(&p.origin, weight) | ||
if from != nil && weight > 0 { | ||
from.AddInfluence(&p.origin, -weight) | ||
} | ||
if to != nil && weight > 0 { | ||
to.AddInfluence(&p.origin, weight) | ||
} | ||
} | ||
} | ||
for storeID, info := range h.stInfos { | ||
|
@@ -203,6 +206,7 @@ const ( | |
|
||
minHotScheduleInterval = time.Second | ||
maxHotScheduleInterval = 20 * time.Second | ||
regionTooHotThreshold = 0.3 | ||
) | ||
|
||
var ( | ||
|
@@ -294,7 +298,7 @@ func (h *hotScheduler) dispatch(typ statistics.RWType, cluster sche.ScheduleClus | |
return nil | ||
} | ||
|
||
func (h *hotScheduler) tryAddPendingInfluence(op *operator.Operator, srcStore, dstStore uint64, infl statistics.Influence, maxZombieDur time.Duration) bool { | ||
func (h *hotScheduler) tryAddPendingInfluence(op *operator.Operator, srcStore []uint64, dstStore uint64, infl statistics.Influence, maxZombieDur time.Duration) bool { | ||
regionID := op.RegionID() | ||
_, ok := h.regionPendings[regionID] | ||
if ok { | ||
|
@@ -664,6 +668,16 @@ func (bs *balanceSolver) solve() []*operator.Operator { | |
} | ||
} | ||
bs.cur.mainPeerStat = mainPeerStat | ||
if regionTooHot(srcStore, mainPeerStat) { | ||
bufferflies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hotSchedulerRegionIsTooHotCounter.Inc() | ||
ops := bs.createSplitOperator([]*core.RegionInfo{bs.cur.region}) | ||
if len(ops) > 0 { | ||
bs.ops = ops | ||
bs.cur.calcPeersRate(bs.firstPriority, bs.secondPriority) | ||
bs.best = bs.cur | ||
return ops | ||
} | ||
} | ||
|
||
for _, dstStore := range bs.filterDstStores() { | ||
bs.cur.dstStore = dstStore | ||
|
@@ -723,24 +737,38 @@ func (bs *balanceSolver) tryAddPendingInfluence() bool { | |
if bs.best == nil || len(bs.ops) == 0 { | ||
return false | ||
} | ||
if bs.best.srcStore.IsTiFlash() != bs.best.dstStore.IsTiFlash() { | ||
isSplit := bs.ops[0].Kind() == operator.OpSplit | ||
if !isSplit && bs.best.srcStore.IsTiFlash() != bs.best.dstStore.IsTiFlash() { | ||
hotSchedulerNotSameEngineCounter.Inc() | ||
return false | ||
} | ||
maxZombieDur := bs.calcMaxZombieDur() | ||
|
||
// TODO: Process operators atomically. | ||
// main peer | ||
srcStoreID := bs.best.srcStore.GetID() | ||
dstStoreID := bs.best.dstStore.GetID() | ||
|
||
srcStoreIDs := make([]uint64, 0) | ||
dstStoreID := uint64(0) | ||
if isSplit { | ||
region := bs.GetRegion(bs.ops[0].RegionID()) | ||
for id := range region.GetStoreIDs() { | ||
srcStoreIDs = append(srcStoreIDs, id) | ||
} | ||
} else { | ||
srcStoreIDs = append(srcStoreIDs, bs.best.srcStore.GetID()) | ||
dstStoreID = bs.best.dstStore.GetID() | ||
} | ||
infl := bs.collectPendingInfluence(bs.best.mainPeerStat) | ||
if !bs.sche.tryAddPendingInfluence(bs.ops[0], srcStoreID, dstStoreID, infl, maxZombieDur) { | ||
if !bs.sche.tryAddPendingInfluence(bs.ops[0], srcStoreIDs, dstStoreID, infl, maxZombieDur) { | ||
bufferflies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false | ||
} | ||
if isSplit { | ||
return true | ||
} | ||
// revert peers | ||
if bs.best.revertPeerStat != nil && len(bs.ops) > 1 { | ||
infl := bs.collectPendingInfluence(bs.best.revertPeerStat) | ||
if !bs.sche.tryAddPendingInfluence(bs.ops[1], dstStoreID, srcStoreID, infl, maxZombieDur) { | ||
if !bs.sche.tryAddPendingInfluence(bs.ops[1], srcStoreIDs, dstStoreID, infl, maxZombieDur) { | ||
return false | ||
} | ||
} | ||
|
@@ -1529,6 +1557,10 @@ func (bs *balanceSolver) createSplitOperator(regions []*core.RegionInfo) []*oper | |
for _, region := range regions { | ||
createFunc(region) | ||
} | ||
// the split bucket's priority is highest | ||
if len(operators) > 0 { | ||
bs.cur.progressiveRank = -5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is it used for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make split stragy is the best stragy. |
||
} | ||
return operators | ||
} | ||
|
||
|
@@ -1789,3 +1821,10 @@ func dimToString(dim int) string { | |
func prioritiesToDim(priorities []string) (firstPriority int, secondPriority int) { | ||
return stringToDim(priorities[0]), stringToDim(priorities[1]) | ||
} | ||
|
||
// regionTooHot returns true if any dim of the hot region is greater than the store threshold. | ||
func regionTooHot(store *statistics.StoreLoadDetail, region *statistics.HotPeerStat) bool { | ||
return slice.AnyOf(store.LoadPred.Current.Loads, func(i int) bool { | ||
return region.Loads[i] > store.LoadPred.Current.Loads[i]*regionTooHotThreshold | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why change it?
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.
In before, regions key will order by [1,2,3,4,5], there are no key range for the buckets.
In this pr, regions key will order by [10,20,30,40,50], I can put some buckets in one regions.