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

fit: further optimize the selection of witness rule candidates #6148

Merged
merged 4 commits into from
Mar 29, 2023
Merged
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
18 changes: 17 additions & 1 deletion pkg/schedule/placement/fit.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type RuleFit struct {
// IsolationScore indicates at which level of labeling these Peers are
// isolated. A larger value is better.
IsolationScore float64 `json:"isolation-score"`
WitnessScore int64 `json:"witness-score"`
// stores is the stores that the peers are placed in.
stores []*core.StoreInfo
}
Expand Down Expand Up @@ -139,6 +140,10 @@ func compareRuleFit(a, b *RuleFit) int {
return -1
case a.IsolationScore > b.IsolationScore:
return 1
case a.WitnessScore > b.WitnessScore:
return -1
case a.WitnessScore < b.WitnessScore:
return 1
default:
return 0
}
Expand Down Expand Up @@ -333,7 +338,7 @@ func (w *fitWorker) updateOrphanPeers(index int) {
}

func newRuleFit(rule *Rule, peers []*fitPeer, supportWitness bool) *RuleFit {
rf := &RuleFit{Rule: rule, IsolationScore: isolationScore(peers, rule.LocationLabels)}
rf := &RuleFit{Rule: rule, IsolationScore: isolationScore(peers, rule.LocationLabels), WitnessScore: witnessScore(peers, supportWitness && rule.IsWitness)}
for _, p := range peers {
rf.Peers = append(rf.Peers, p.Peer)
rf.stores = append(rf.stores, p.store)
Expand Down Expand Up @@ -429,3 +434,14 @@ func stateScore(region *core.RegionInfo, peerID uint64) int {
return 2
}
}

func witnessScore(peers []*fitPeer, fitWitness bool) int64 {
var score int64
if !fitWitness || len(peers) == 0 {
return 0
}
for _, p := range peers {
score += int64(p.store.GetWitnessCount())
}
return score
}