Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#53979
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
hawkingrei authored and ti-chi-bot committed Jun 13, 2024
1 parent 3c02c2a commit 2c1787d
Show file tree
Hide file tree
Showing 3 changed files with 19 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 @@ -31,7 +31,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
6 changes: 6 additions & 0 deletions pkg/statistics/handle/cache/internal/lfu/lfu_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,14 @@ func (s *LFU) onExit(val any) {
if s.closed.Load() {
return
}
<<<<<<< HEAD
s.addCost(
-1 * val.(*statistics.Table).MemoryUsage().TotalTrackingMemUsage())
=======
s.triggerEvict()
// Subtract the memory usage of the table from the total memory usage.
s.addCost(-val.(*statistics.Table).MemoryUsage().TotalTrackingMemUsage())
>>>>>>> 2ee6d22383d (statistics: updating stats cache can trigger evict (#53979))
}

// Len implements statsCacheInner
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 @@ -306,3 +306,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 2c1787d

Please sign in to comment.