Skip to content

Commit 01f22e1

Browse files
authored
Merge branch 'master' into fix-race1
2 parents 9fe3637 + 9097e68 commit 01f22e1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

server/core/store_option.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ func SetStoreStats(stats *pdpb.StoreStats) StoreCreateOption {
187187
}
188188
}
189189

190+
// SetNewStoreStats sets the raw statistics information for the store.
191+
func SetNewStoreStats(stats *pdpb.StoreStats) StoreCreateOption {
192+
return func(store *StoreInfo) {
193+
// There is no clone in default store stats, we create new one to avoid to modify others.
194+
// And range cluster cannot use HMA because the last value is not cached
195+
store.storeStats = &storeStats{
196+
rawStats: stats,
197+
}
198+
}
199+
}
200+
190201
// AttachAvailableFunc attaches a customize function for the store. The function f returns true if the store limit is not exceeded.
191202
func AttachAvailableFunc(limitType storelimit.Type, f func() bool) StoreCreateOption {
192203
return func(store *StoreInfo) {

server/core/store_stats.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func (ss *storeStats) updateRawStats(rawStats *pdpb.StoreStats) {
4949
defer ss.mu.Unlock()
5050
ss.rawStats = rawStats
5151

52+
if ss.avgAvailable == nil {
53+
return
54+
}
55+
5256
ss.avgAvailable.Add(float64(rawStats.GetAvailable()))
5357
deviation := math.Abs(float64(rawStats.GetAvailable()) - ss.avgAvailable.Get())
5458
ss.maxAvailableDeviation.Add(deviation)
@@ -143,13 +147,19 @@ func (ss *storeStats) GetApplyingSnapCount() uint32 {
143147
func (ss *storeStats) GetAvgAvailable() uint64 {
144148
ss.mu.RLock()
145149
defer ss.mu.RUnlock()
150+
if ss.avgAvailable == nil {
151+
return ss.rawStats.Available
152+
}
146153
return climp0(ss.avgAvailable.Get())
147154
}
148155

149156
// GetAvailableDeviation returns approximate magnitude of available in the recent period.
150157
func (ss *storeStats) GetAvailableDeviation() uint64 {
151158
ss.mu.RLock()
152159
defer ss.mu.RUnlock()
160+
if ss.avgMaxAvailableDeviation == nil {
161+
return 0
162+
}
153163
return climp0(ss.avgMaxAvailableDeviation.Get())
154164
}
155165

server/schedule/range_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (r *RangeCluster) updateStoreInfo(s *core.StoreInfo) *core.StoreInfo {
5757
newStats.UsedSize = uint64(float64(regionSize)/amplification) * (1 << 20)
5858
newStats.Available = s.GetCapacity() - newStats.UsedSize
5959
newStore := s.Clone(
60-
core.SetStoreStats(newStats),
60+
core.SetNewStoreStats(newStats), // it means to use instant value directly
6161
core.SetLeaderCount(leaderCount),
6262
core.SetRegionCount(regionCount),
6363
core.SetPendingPeerCount(pendingPeerCount),

0 commit comments

Comments
 (0)