File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff 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.
191202func AttachAvailableFunc (limitType storelimit.Type , f func () bool ) StoreCreateOption {
192203 return func (store * StoreInfo ) {
Original file line number Diff line number Diff 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 {
143147func (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.
150157func (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
Original file line number Diff line number Diff 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 ),
You can’t perform that action at this time.
0 commit comments