From 05730a00350588803a5273f0a6ea58f3cc9526b5 Mon Sep 17 00:00:00 2001 From: Paul Rogers Date: Thu, 11 Apr 2024 16:42:29 -0400 Subject: [PATCH 1/2] Move counter increment to before starting goroutine --- .../stores/shipper/indexshipper/boltdb/table_manager.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/storage/stores/shipper/indexshipper/boltdb/table_manager.go b/pkg/storage/stores/shipper/indexshipper/boltdb/table_manager.go index 4bc00d082d293..82f86a720b4f8 100644 --- a/pkg/storage/stores/shipper/indexshipper/boltdb/table_manager.go +++ b/pkg/storage/stores/shipper/indexshipper/boltdb/table_manager.go @@ -88,12 +88,13 @@ func NewTableManager(cfg Config, indexShipper Shipper, tableRange config.TableRa } tm.tables = tables + // Increment the WaitGroup counter here before starting the goroutine + tm.wg.Add(1) go tm.loop() return &tm, nil } func (tm *TableManager) loop() { - tm.wg.Add(1) defer tm.wg.Done() tm.handoverIndexesToShipper(false) From 95f459e10708db4e765ee21afb77b8b7cd54bbf6 Mon Sep 17 00:00:00 2001 From: Paul Rogers Date: Thu, 11 Apr 2024 16:44:05 -0400 Subject: [PATCH 2/2] Lock the embedded cache while checking values --- pkg/storage/chunk/cache/embeddedcache_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/storage/chunk/cache/embeddedcache_test.go b/pkg/storage/chunk/cache/embeddedcache_test.go index 473c1b8e83a09..7e109efea4f97 100644 --- a/pkg/storage/chunk/cache/embeddedcache_test.go +++ b/pkg/storage/chunk/cache/embeddedcache_test.go @@ -203,6 +203,7 @@ func TestEmbeddedCacheExpiry(t *testing.T) { _, ok = c.Get(ctx, key1) require.False(t, ok) + c.lock.RLock() assert.Equal(t, float64(4), testutil.ToFloat64(c.entriesAddedNew)) assert.Equal(t, float64(0), testutil.ToFloat64(c.entriesEvicted.WithLabelValues(expiredReason))) assert.Equal(t, float64(1), testutil.ToFloat64(c.entriesEvicted.WithLabelValues(fullReason))) @@ -211,12 +212,14 @@ func TestEmbeddedCacheExpiry(t *testing.T) { assert.Equal(t, float64(c.lru.Len()), testutil.ToFloat64(c.entriesCurrent)) assert.Equal(t, float64(memorySz), testutil.ToFloat64(c.memoryBytes)) assert.Equal(t, int64(1), removedEntriesCount.Load(), "on removal callback had to be called for key1") + c.lock.RUnlock() // Expire the item. time.Sleep(2 * cfg.TTL) _, ok = c.Get(ctx, key4) require.False(t, ok) + c.lock.RLock() assert.Equal(t, float64(4), testutil.ToFloat64(c.entriesAddedNew)) assert.Equal(t, float64(3), testutil.ToFloat64(c.entriesEvicted.WithLabelValues(expiredReason))) assert.Equal(t, float64(1), testutil.ToFloat64(c.entriesEvicted.WithLabelValues(fullReason))) @@ -225,6 +228,7 @@ func TestEmbeddedCacheExpiry(t *testing.T) { assert.Equal(t, float64(c.lru.Len()), testutil.ToFloat64(c.entriesCurrent)) assert.Equal(t, float64(memorySz), testutil.ToFloat64(c.memoryBytes)) assert.Equal(t, int64(4), removedEntriesCount.Load(), "on removal callback had to be called for all 3 expired entries") + c.lock.RUnlock() c.Stop() }