Skip to content

Commit

Permalink
statistics: updating stats cache can trigger evict (#53979)
Browse files Browse the repository at this point in the history
close #53742
  • Loading branch information
hawkingrei authored Jun 13, 2024
1 parent fab0940 commit 2ee6d22
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/statistics/handle/cache/internal/lfu/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ go_test(
embed = [":lfu"],
flaky = True,
race = "on",
shard_count = 9,
shard_count = 10,
deps = [
"//pkg/statistics",
"//pkg/statistics/handle/cache/internal/testutil",
Expand Down
1 change: 1 addition & 0 deletions pkg/statistics/handle/cache/internal/lfu/lfu_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (s *LFU) onExit(val any) {
if s.closed.Load() {
return
}
s.triggerEvict()
// Subtract the memory usage of the table from the total memory usage.
s.addCost(-val.(*statistics.Table).MemoryUsage().TotalTrackingMemUsage())
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/statistics/handle/cache/internal/lfu/lfu_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,15 @@ func TestMemoryControl(t *testing.T) {
lfu.wait()
require.Equal(t, int64(10)*(2*mockCMSMemoryUsage+mockCMSMemoryUsage), lfu.Cost())
}

func TestMemoryControlWithUpdate(t *testing.T) {
capacity := int64(100)
lfu, err := NewLFU(capacity)
require.NoError(t, err)
for i := 0; i < 100; i++ {
t1 := testutil.NewMockStatisticsTable(i, 1, true, false, false)
lfu.Put(1, t1)
}
time.Sleep(1 * time.Second)
require.Equal(t, int64(0), lfu.Cost())
}

0 comments on commit 2ee6d22

Please sign in to comment.