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

core: change score calculator in few disk space to avoid offline earlier (#3592) #3605

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions server/core/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (s *StoreInfo) LeaderScore(policy SchedulePolicy, delta int64) float64 {
func (s *StoreInfo) RegionScore(version string, highSpaceRatio, lowSpaceRatio float64, delta int64, deviation int) float64 {
switch version {
case "v2":
return s.regionScoreV2(delta, deviation)
return s.regionScoreV2(delta, deviation, lowSpaceRatio)
case "v1":
fallthrough
default:
Expand Down Expand Up @@ -301,15 +301,16 @@ func (s *StoreInfo) regionScoreV1(highSpaceRatio, lowSpaceRatio float64, delta i
return score / math.Max(s.GetRegionWeight(), minWeight)
}

func (s *StoreInfo) regionScoreV2(delta int64, deviation int) float64 {
func (s *StoreInfo) regionScoreV2(delta int64, deviation int, lowSpaceRatio float64) float64 {
A := float64(float64(s.GetAvgAvailable())-float64(deviation)*float64(s.GetAvailableDeviation())) / gb
C := float64(s.GetCapacity()) / gb
R := float64(s.GetRegionSize() + delta)
var (
K, M float64 = 1, 256 // Experience value to control the weight of the available influence on score
F float64 = 20 // Experience value to prevent some nodes from running out of disk space prematurely.
F float64 = 50 // Experience value to prevent some nodes from running out of disk space prematurely.
B = 1e7
)

F = math.Max(F, C*(1-lowSpaceRatio))
var score float64
if A >= C || C < 1 {
score = R
Expand All @@ -319,7 +320,8 @@ func (s *StoreInfo) regionScoreV2(delta int64, deviation int) float64 {
score = (K + M*(math.Log(C)-math.Log(A-F+1))/(C-A+F-1)) * R
} else {
// When remaining space is less then F, the score is mainly determined by available space.
score = (K+M*math.Log(C)/C)*R + (F-A)*(K+M*math.Log(F)/F)
// store's score will increase rapidly after it has few space. and it will reach similar score when they has no space
score = (K+M*math.Log(C)/C)*R + B*(F-A)/F
}
return score / math.Max(s.GetRegionWeight(), minWeight)
}
Expand Down