Skip to content

Commit

Permalink
Fix addMetrics() of ShardedLRU
Browse files Browse the repository at this point in the history
  • Loading branch information
fufuok authored and rockdaboot committed Mar 20, 2024
1 parent c89e6e0 commit 837c651
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions shardedlru.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (lru *ShardedLRU[K, V]) Metrics() Metrics {
m := lru.lrus[shard].Metrics()
lru.mus[shard].Unlock()

addMetrics(metrics, m)
addMetrics(&metrics, m)
}

return metrics
Expand All @@ -242,13 +242,13 @@ func (lru *ShardedLRU[K, V]) ResetMetrics() Metrics {
m := lru.lrus[shard].ResetMetrics()
lru.mus[shard].Unlock()

addMetrics(metrics, m)
addMetrics(&metrics, m)
}

return metrics
}

func addMetrics(dst, src Metrics) {
func addMetrics(dst *Metrics, src Metrics) {
dst.Inserts += src.Inserts
dst.Collisions += src.Collisions
dst.Evictions += src.Evictions
Expand Down
2 changes: 1 addition & 1 deletion shardedlru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestShardedRaceCondition(t *testing.T) {
}

func TestShardedLRUMetrics(t *testing.T) {
cache, _ := NewSynced[uint64, uint64](1, hashUint64)
cache, _ := NewSharded[uint64, uint64](1, hashUint64)
testMetrics(t, cache)
}

Expand Down

0 comments on commit 837c651

Please sign in to comment.