Skip to content

Commit d3add7c

Browse files
authored
statstics: trigger evict by the timer (#58027)
close #58052
1 parent 2a1f646 commit d3add7c

File tree

7 files changed

+24
-0
lines changed

7 files changed

+24
-0
lines changed

pkg/domain/domain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,7 @@ func (do *Domain) updateStatsWorker(_ sessionctx.Context) {
27182718
}
27192719
case <-readMemTicker.C:
27202720
memory.ForceReadMemStats()
2721+
do.StatsHandle().StatsCache.TriggerEvict()
27212722
case <-updateStatsHealthyTicker.C:
27222723
statsHandle.UpdateStatsHealthyMetrics()
27232724
}

pkg/statistics/handle/cache/internal/inner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ type StatsCacheInner interface {
4141
SetCapacity(int64)
4242
// Close stops the cache
4343
Close()
44+
// TriggerEvict triggers the cache to evict some items
45+
TriggerEvict()
4446
}

pkg/statistics/handle/cache/internal/lfu/lfu_cache.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,8 @@ func (s *LFU) addCost(v int64) {
251251
newv := s.cost.Add(v)
252252
metrics.CostGauge.Set(float64(newv))
253253
}
254+
255+
// TriggerEvict implements statsCacheInner
256+
func (s *LFU) TriggerEvict() {
257+
s.triggerEvict()
258+
}

pkg/statistics/handle/cache/internal/mapcache/map_cache.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,6 @@ func (*MapCache) SetCapacity(int64) {}
131131

132132
// Close implements StatsCacheInner
133133
func (*MapCache) Close() {}
134+
135+
// TriggerEvict implements statsCacheInner
136+
func (*MapCache) TriggerEvict() {}

pkg/statistics/handle/cache/statscache.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ func (s *StatsCacheImpl) Put(id int64, t *statistics.Table) {
259259
s.Load().put(id, t)
260260
}
261261

262+
// TriggerEvict triggers the cache to evict some items.
263+
func (s *StatsCacheImpl) TriggerEvict() {
264+
s.Load().TriggerEvict()
265+
}
266+
262267
// MaxTableStatsVersion returns the version of the current cache, which is defined as
263268
// the max table stats version the cache has in its lifecycle.
264269
func (s *StatsCacheImpl) MaxTableStatsVersion() uint64 {

pkg/statistics/handle/cache/statscacheinner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,8 @@ func (sc *StatsCache) Update(tables []*statistics.Table, deletedIDs []int64, ski
183183
}
184184
}
185185
}
186+
187+
// TriggerEvict triggers the cache to evict some items.
188+
func (sc *StatsCache) TriggerEvict() {
189+
sc.c.TriggerEvict()
190+
}

pkg/statistics/handle/types/interfaces.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ type StatsCache interface {
260260

261261
// UpdateStatsHealthyMetrics updates stats healthy distribution metrics according to stats cache.
262262
UpdateStatsHealthyMetrics()
263+
264+
// TriggerEvict triggers the cache to evict some items
265+
TriggerEvict()
263266
}
264267

265268
// StatsLockTable is the table info of which will be locked.

0 commit comments

Comments
 (0)