Skip to content

Commit

Permalink
statstics: trigger evict by the timer (pingcap#58027)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Dec 11, 2024
1 parent 2a1f646 commit d3add7c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,7 @@ func (do *Domain) updateStatsWorker(_ sessionctx.Context) {
}
case <-readMemTicker.C:
memory.ForceReadMemStats()
do.StatsHandle().StatsCache.TriggerEvict()
case <-updateStatsHealthyTicker.C:
statsHandle.UpdateStatsHealthyMetrics()
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/statistics/handle/cache/internal/inner.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ type StatsCacheInner interface {
SetCapacity(int64)
// Close stops the cache
Close()
// TriggerEvict triggers the cache to evict some items
TriggerEvict()
}
5 changes: 5 additions & 0 deletions pkg/statistics/handle/cache/internal/lfu/lfu_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,8 @@ func (s *LFU) addCost(v int64) {
newv := s.cost.Add(v)
metrics.CostGauge.Set(float64(newv))
}

// TriggerEvict implements statsCacheInner
func (s *LFU) TriggerEvict() {
s.triggerEvict()
}
3 changes: 3 additions & 0 deletions pkg/statistics/handle/cache/internal/mapcache/map_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ func (*MapCache) SetCapacity(int64) {}

// Close implements StatsCacheInner
func (*MapCache) Close() {}

// TriggerEvict implements statsCacheInner
func (*MapCache) TriggerEvict() {}
5 changes: 5 additions & 0 deletions pkg/statistics/handle/cache/statscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ func (s *StatsCacheImpl) Put(id int64, t *statistics.Table) {
s.Load().put(id, t)
}

// TriggerEvict triggers the cache to evict some items.
func (s *StatsCacheImpl) TriggerEvict() {
s.Load().TriggerEvict()
}

// MaxTableStatsVersion returns the version of the current cache, which is defined as
// the max table stats version the cache has in its lifecycle.
func (s *StatsCacheImpl) MaxTableStatsVersion() uint64 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/statistics/handle/cache/statscacheinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,8 @@ func (sc *StatsCache) Update(tables []*statistics.Table, deletedIDs []int64, ski
}
}
}

// TriggerEvict triggers the cache to evict some items.
func (sc *StatsCache) TriggerEvict() {
sc.c.TriggerEvict()
}
3 changes: 3 additions & 0 deletions pkg/statistics/handle/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ type StatsCache interface {

// UpdateStatsHealthyMetrics updates stats healthy distribution metrics according to stats cache.
UpdateStatsHealthyMetrics()

// TriggerEvict triggers the cache to evict some items
TriggerEvict()
}

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

0 comments on commit d3add7c

Please sign in to comment.