Skip to content
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

placement: add manager and FitRegion interface #1865

Merged
merged 7 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions server/schedule/placement/fit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ import (
)

// RegionFit is the result of fitting a region's peers to rule list.
// All peers are divided into corresponding rules according to the matching
// rules, and the remaining Peers are placed in the OrphanPeers list.
type RegionFit struct {
Luffbee marked this conversation as resolved.
Show resolved Hide resolved
RuleFits []*RuleFit
OrphanPeers []*metapb.Peer
rleungx marked this conversation as resolved.
Show resolved Hide resolved
}

// IsSatisfied returns if the rules are properly satisfied.
// It means all Rules are fulfilled and there is no orphan peers.
func (f *RegionFit) IsSatisfied() bool {
if len(f.RuleFits) == 0 {
return false
Expand All @@ -50,6 +53,7 @@ func (f *RegionFit) GetRuleFit(peerID uint64) *RuleFit {
}

// CompareRegionFit determines the superiority of 2 fits.
// It returns 1 when the first fit result is better.
func CompareRegionFit(a, b *RegionFit) int {
for i := range a.RuleFits {
if cmp := compareRuleFit(a.RuleFits[i], b.RuleFits[i]); cmp != 0 {
Expand All @@ -68,10 +72,16 @@ func CompareRegionFit(a, b *RegionFit) int {

// RuleFit is the result of fitting status of a Rule.
type RuleFit struct {
Rule *Rule
Peers []*metapb.Peer
Rule *Rule
// Peers of the Region that are divided to this Rule.
Peers []*metapb.Peer
// LoosematchedPeers is subset of `Peers`. It contains all Peers that have
// different Role from configuration (the Role can be migrated to target role
// by scheduling).
LooseMatchedPeers []*metapb.Peer
Luffbee marked this conversation as resolved.
Show resolved Hide resolved
IsolationLevel int
// IsolationLevel indicates at which level of labeling these Peers are
// isolated. A larger value indicates a higher isolation level.
IsolationLevel int
}

// IsSatisfied returns if the rule is properly satisfied.
Expand Down
4 changes: 2 additions & 2 deletions server/schedule/placement/rule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (m *RuleManager) updateSplitKeys() {
}
}

// GetSplitKeys returns all split keys in the range.
// GetSplitKeys returns all split keys in the range (start, end).
func (m *RuleManager) GetSplitKeys(start, end []byte) [][]byte {
m.RLock()
defer m.RUnlock()
Expand Down Expand Up @@ -268,7 +268,7 @@ func (m *RuleManager) GetRulesForApplyRegion(region *core.RegionInfo) []*Rule {
// or
// |<-- rule -->|
// |<--- region --->|
return nil
return nil // It will considered abnormal when no rules for the regoin. Then Rule checker will try to split the region.
Luffbee marked this conversation as resolved.
Show resolved Hide resolved
}
return prepareRulesForApply(rules)
}
Expand Down