Skip to content

Commit d6ec4e2

Browse files
committed
reverse space ratio
1 parent 562cd4a commit d6ec4e2

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

server/config.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,15 @@ type ScheduleConfig struct {
353353
// TolerantSizeRatio is the ratio of buffer size for balance scheduler.
354354
TolerantSizeRatio float64 `toml:"tolerant-size-ratio,omitempty" json:"tolerant-size-ratio"`
355355
//
356-
// high space stage transition stage low space stage
356+
// high space stage transition stage low space stage
357357
// |--------------------|-----------------------------|-------------------------|
358358
// ^ ^ ^ ^
359-
// 0 (1 - LowSpaceRatio) * capacity (1 - SpaceRatio) * capacity capacity
359+
// 0 HighSpaceRatio * capacity LowSpaceRatio * capacity capacity
360360
//
361-
// LowSpaceRatio is the lowest available ratio of store which regraded as low space.
361+
// LowSpaceRatio is the lowest usage ratio of store which regraded as low space.
362362
// When in low space, store region score increases to very large and varies inversely with available size.
363363
LowSpaceRatio float64 `toml:"low-space-ratio,omitempty" json:"low-space-ratio"`
364-
// HighSpaceRatio is the highest available ratio of store which regraded as high space.
364+
// HighSpaceRatio is the highest usage ratio of store which regraded as high space.
365365
// High space means there is a lot of spare capacity, and store region score varies directly with used size.
366366
HighSpaceRatio float64 `toml:"high-space-ratio,omitempty" json:"high-space-ratio"`
367367
// EnableRaftLearner is the option for using AddLearnerNode instead of AddNode
@@ -410,9 +410,9 @@ const (
410410
defaultRegionScheduleLimit = 4
411411
defaultReplicaScheduleLimit = 8
412412
defaultMergeScheduleLimit = 8
413-
defaultTolerantSizeRatio = 2.5
414-
defaultLowSpaceRatio = 0.2
415-
defaultHighSpaceRatio = 0.5
413+
defaultTolerantSizeRatio = 5
414+
defaultLowSpaceRatio = 0.8
415+
defaultHighSpaceRatio = 0.6
416416
)
417417

418418
var defaultSchedulers = SchedulerConfigs{

server/core/store.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,21 @@ func (s *StoreInfo) RegionScore(highSpaceRatio, lowSpaceRatio float64, delta int
122122

123123
var score float64
124124

125-
// lowSpaceRatio shouldn't greater than highSpaceRatio
126-
if lowSpaceRatio > highSpaceRatio {
127-
lowSpaceRatio = highSpaceRatio
128-
}
129-
130125
// because of rocksdb compression, region size is larger than actual used size
131126
amplification := float64(s.RegionSize) / (float64(s.Stats.GetUsedSize()) / (1 << 20))
132127

133-
if available-float64(delta)/amplification >= highSpaceRatio*capacity || lowSpaceRatio < 0 || lowSpaceRatio > 1 {
128+
if available-float64(delta)/amplification >= (1-highSpaceRatio)*capacity {
134129
score = float64(s.RegionSize + delta)
135-
} else if available-float64(delta)/amplification <= lowSpaceRatio*capacity || highSpaceRatio < 0 || highSpaceRatio > 1 {
130+
} else if available-float64(delta)/amplification <= (1-lowSpaceRatio)*capacity {
136131
score = maxScore - (available - float64(delta)/amplification)
137132
} else {
138133
// to make the score function continuous, we use linear function y = k * x + b as transition period
139134
// from above we know that there are two points must on the function image
140135
// p1((1-highSpaceRatio)*capacity*amplification, (1-highSpaceRatio)*capacity*amplification) and
141136
// p2((1-lowSpaceRatio)*capacity*amplification, maxScore-lowSpaceRatio*capacity)
142137
// so k = (y2 - y1) / (x2 - x1)
143-
x1, y1 := (1-highSpaceRatio)*capacity*amplification, (1-highSpaceRatio)*capacity*amplification
144-
x2, y2 := (1-lowSpaceRatio)*capacity*amplification, maxScore-lowSpaceRatio*capacity
138+
x1, y1 := highSpaceRatio*capacity*amplification, highSpaceRatio*capacity*amplification
139+
x2, y2 := lowSpaceRatio*capacity*amplification, maxScore-(1-lowSpaceRatio)*capacity
145140

146141
k := (y2 - y1) / (x2 - x1)
147142
b := y1 - k*x1
@@ -166,7 +161,7 @@ func (s *StoreInfo) AvailableRatio() float64 {
166161

167162
// IsLowSpace checks if the store is lack of space.
168163
func (s *StoreInfo) IsLowSpace(lowSpaceRatio float64) bool {
169-
return s.Stats != nil && s.AvailableRatio() < lowSpaceRatio
164+
return s.Stats != nil && s.AvailableRatio() < 1-lowSpaceRatio
170165
}
171166

172167
// ResourceCount reutrns count of leader/region in the store.

server/schedule/mockcluster.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ const (
379379
defaultRegionScheduleLimit = 4
380380
defaultReplicaScheduleLimit = 8
381381
defaultMergeScheduleLimit = 8
382-
defaultTolerantSizeRatio = 2.5
383-
defaultLowSpaceRatio = 0.2
384-
defaultHighSpaceRatio = 0.5
382+
defaultTolerantSizeRatio = 5
383+
defaultLowSpaceRatio = 0.8
384+
defaultHighSpaceRatio = 0.6
385385
)
386386

387387
// MockSchedulerOptions is a mock of SchedulerOptions

0 commit comments

Comments
 (0)