Skip to content

Commit

Permalink
test: Fix deadlock in table_manager relating to Stop/SyncTables (#12597)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul1r committed Apr 12, 2024
1 parent d12cfed commit 13d45bc
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
70 changes: 70 additions & 0 deletions pkg/storage/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 13d45bc

Please sign in to comment.