Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statstics: trigger evict by the timer #58027

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,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