Skip to content

Commit

Permalink
fit: further optimize the selection of witness rule candidates (#6148)
Browse files Browse the repository at this point in the history
close #5568, ref #5568

fit: further optimize the selection of witness rule candidates

Signed-off-by: Wenbo Zhang <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
ethercflow and ti-chi-bot authored Mar 29, 2023
1 parent fe22771 commit c4a8b80
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/schedule/placement/fit.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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 int `json:"witness-score"`
// stores is the stores that the peers are placed in.
stores []*core.StoreInfo
}
Expand Down Expand Up @@ -151,6 +152,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 @@ -345,7 +350,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 @@ -441,3 +446,14 @@ func stateScore(region *core.RegionInfo, peerID uint64) int {
return 2
}
}

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

0 comments on commit c4a8b80

Please sign in to comment.