From 13d45bc5127adc3ec55848ee4b5e25cc597d309b Mon Sep 17 00:00:00 2001 From: Paul Rogers <129207811+paul1r@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:50:04 -0400 Subject: [PATCH] test: Fix deadlock in table_manager relating to Stop/SyncTables (#12597) --- pkg/storage/store_test.go | 70 +++++++++++++++++++ .../indexshipper/downloads/table_manager.go | 3 +- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/pkg/storage/store_test.go b/pkg/storage/store_test.go index a60c183fe022f..45a505be3f439 100644 --- a/pkg/storage/store_test.go +++ b/pkg/storage/store_test.go @@ -1932,6 +1932,76 @@ func TestStore_BoltdbTsdbSameIndexPrefix(t *testing.T) { } } +func TestStore_SyncStopInteraction(t *testing.T) { + tempDir := t.TempDir() + + ingesterName := "ingester-1" + limits, err := validation.NewOverrides(validation.Limits{}, nil) + require.NoError(t, err) + + // config for BoltDB Shipper + boltdbShipperConfig := boltdb.IndexCfg{} + flagext.DefaultValues(&boltdbShipperConfig) + boltdbShipperConfig.ActiveIndexDirectory = path.Join(tempDir, "boltdb-index") + boltdbShipperConfig.CacheLocation = path.Join(tempDir, "boltdb-shipper-cache") + boltdbShipperConfig.Mode = indexshipper.ModeReadWrite + boltdbShipperConfig.IngesterName = ingesterName + boltdbShipperConfig.ResyncInterval = time.Millisecond + + // config for tsdb Shipper + tsdbShipperConfig := indexshipper.Config{} + flagext.DefaultValues(&tsdbShipperConfig) + tsdbShipperConfig.ActiveIndexDirectory = path.Join(tempDir, "tsdb-index") + tsdbShipperConfig.CacheLocation = path.Join(tempDir, "tsdb-shipper-cache") + tsdbShipperConfig.Mode = indexshipper.ModeReadWrite + tsdbShipperConfig.IngesterName = ingesterName + tsdbShipperConfig.ResyncInterval = time.Millisecond + + // dates for activation of boltdb shippers + boltdbShipperStartDate := parseDate("2019-01-01") + tsdbStartDate := parseDate("2019-01-02") + + cfg := Config{ + FSConfig: local.FSConfig{Directory: path.Join(tempDir, "chunks")}, + BoltDBShipperConfig: boltdbShipperConfig, + TSDBShipperConfig: tsdbShipperConfig, + } + + schemaConfig := config.SchemaConfig{ + Configs: []config.PeriodConfig{ + { + From: config.DayTime{Time: timeToModelTime(boltdbShipperStartDate)}, + IndexType: "boltdb-shipper", + ObjectType: types.StorageTypeFileSystem, + Schema: "v12", + IndexTables: config.IndexPeriodicTableConfig{ + PathPrefix: "index/", + PeriodicTableConfig: config.PeriodicTableConfig{ + Prefix: "index_", + Period: time.Hour * 24, + }}, + RowShards: 2, + }, + { + From: config.DayTime{Time: timeToModelTime(tsdbStartDate)}, + IndexType: "tsdb", + ObjectType: types.StorageTypeFileSystem, + Schema: "v12", + IndexTables: config.IndexPeriodicTableConfig{ + PathPrefix: "index/", + PeriodicTableConfig: config.PeriodicTableConfig{ + Prefix: "index_", + Period: time.Hour * 24, + }}, + }, + }, + } + + store, err := NewStore(cfg, config.ChunkStoreConfig{}, schemaConfig, limits, cm, nil, log.NewNopLogger(), constants.Loki) + require.NoError(t, err) + store.Stop() +} + func TestQueryReferencingStructuredMetadata(t *testing.T) { ctx := user.InjectOrgID(context.Background(), "fake") tempDir := t.TempDir() diff --git a/pkg/storage/stores/shipper/indexshipper/downloads/table_manager.go b/pkg/storage/stores/shipper/indexshipper/downloads/table_manager.go index 12e8a9373ed7d..9f2401c209d0e 100644 --- a/pkg/storage/stores/shipper/indexshipper/downloads/table_manager.go +++ b/pkg/storage/stores/shipper/indexshipper/downloads/table_manager.go @@ -153,10 +153,9 @@ func (tm *tableManager) loop() { func (tm *tableManager) Stop() { tm.cancel() - + tm.wg.Wait() tm.tablesMtx.Lock() defer tm.tablesMtx.Unlock() - tm.wg.Wait() for _, table := range tm.tables { table.Close()