From 3f02e33e34e2c312db7bbe5ab7b991046f452c23 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 10 Oct 2016 16:30:10 +0200 Subject: [PATCH] Re-add counting of evict chunk ops and decrementing NumMemChunks Also, modify test to expose the regression. --- storage/local/chunk/chunk.go | 2 ++ storage/local/storage_test.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/storage/local/chunk/chunk.go b/storage/local/chunk/chunk.go index 738e678f1..11c42b39d 100644 --- a/storage/local/chunk/chunk.go +++ b/storage/local/chunk/chunk.go @@ -252,6 +252,8 @@ func (d *Desc) MaybeEvict() bool { panic("ChunkLastTime not populated for evicted chunk") } d.C = nil + Ops.WithLabelValues(Evict).Inc() + atomic.AddInt64(&NumMemChunks, -1) return true } diff --git a/storage/local/storage_test.go b/storage/local/storage_test.go index ce7ed2bd6..e3b31620b 100644 --- a/storage/local/storage_test.go +++ b/storage/local/storage_test.go @@ -20,6 +20,7 @@ import ( "math/rand" "os" "strconv" + "sync/atomic" "testing" "testing/quick" "time" @@ -1412,6 +1413,10 @@ func testEvictAndLoadChunkDescs(t *testing.T, encoding chunk.Encoding) { Value: model.SampleValue(3.14), } + // Sadly, chunk.NumMemChunks is a global variable. We have to reset it + // explicitly here. + atomic.StoreInt64(&chunk.NumMemChunks, 0) + s, closer := NewTestStorage(t, encoding) defer closer.Close() @@ -1441,6 +1446,9 @@ func testEvictAndLoadChunkDescs(t *testing.T, encoding chunk.Encoding) { if oldLen <= len(series.chunkDescs) { t.Errorf("Expected number of chunkDescs to decrease, old number %d, current number %d.", oldLen, len(series.chunkDescs)) } + if int64(len(series.chunkDescs)) < atomic.LoadInt64(&chunk.NumMemChunks) { + t.Errorf("NumMemChunks is larger than number of chunk descs, number of chunk descs: %d, NumMemChunks: %d.", len(series.chunkDescs), atomic.LoadInt64(&chunk.NumMemChunks)) + } // Load everything back. it := s.preloadChunksForRange(makeFingerprintSeriesPair(s, fp), 0, 100000)