From 443661a5daa1051b590c25e56384a7cffe0d4244 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 13 Jul 2023 17:13:24 -0700 Subject: [PATCH] lib/storage: properly free up resources from newTestStorage() by calling stopTestStorage() --- lib/storage/index_db_timing_test.go | 2 -- lib/storage/merge_test.go | 2 ++ lib/storage/merge_timing_test.go | 2 ++ lib/storage/partition_search_test.go | 1 + lib/storage/storage.go | 4 +--- lib/storage/table_search_test.go | 1 + lib/storage/table_search_timing_test.go | 8 +++++--- lib/storage/table_test.go | 2 ++ lib/storage/table_timing_test.go | 1 + 9 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/storage/index_db_timing_test.go b/lib/storage/index_db_timing_test.go index bb7cbd650..8c1d0c28f 100644 --- a/lib/storage/index_db_timing_test.go +++ b/lib/storage/index_db_timing_test.go @@ -303,14 +303,12 @@ func BenchmarkIndexDBGetTSIDs(b *testing.B) { b.RunParallel(func(pb *testing.PB) { var genTSIDLocal generationTSID var metricNameLocal []byte - var metricNameLocalRaw []byte mnLocal := mn is := db.getIndexSearch(noDeadline) for pb.Next() { for i := 0; i < recordsPerLoop; i++ { mnLocal.sortTags() metricNameLocal = mnLocal.Marshal(metricNameLocal[:0]) - metricNameLocalRaw = mnLocal.marshalRaw(metricNameLocalRaw[:0]) if !is.getTSIDByMetricName(&genTSIDLocal, metricNameLocal, date) { panic(fmt.Errorf("cannot obtain tsid for row %d", i)) } diff --git a/lib/storage/merge_test.go b/lib/storage/merge_test.go index 35a6d7d94..4017e6532 100644 --- a/lib/storage/merge_test.go +++ b/lib/storage/merge_test.go @@ -384,6 +384,7 @@ func TestMergeForciblyStop(t *testing.T) { if rowsDeleted != 0 { t.Fatalf("unexpected rowsDeleted; got %d; want %d", rowsDeleted, 0) } + stopTestStorage(strg) } func testMergeBlockStreams(t *testing.T, bsrs []*blockStreamReader, expectedBlocksCount, expectedRowsCount int, expectedMinTimestamp, expectedMaxTimestamp int64) { @@ -399,6 +400,7 @@ func testMergeBlockStreams(t *testing.T, bsrs []*blockStreamReader, expectedBloc if err := mergeBlockStreams(&mp.ph, &bsw, bsrs, nil, strg, 0, &rowsMerged, &rowsDeleted); err != nil { t.Fatalf("unexpected error in mergeBlockStreams: %s", err) } + stopTestStorage(strg) // Verify written data. if mp.ph.RowsCount != uint64(expectedRowsCount) { diff --git a/lib/storage/merge_timing_test.go b/lib/storage/merge_timing_test.go index 34ddde98f..324812d9f 100644 --- a/lib/storage/merge_timing_test.go +++ b/lib/storage/merge_timing_test.go @@ -47,6 +47,8 @@ func benchmarkMergeBlockStreams(b *testing.B, mps []*inmemoryPart, rowsPerLoop i } } }) + + stopTestStorage(strg) } var benchTwoSourcesWorstCaseMPS = func() []*inmemoryPart { diff --git a/lib/storage/partition_search_test.go b/lib/storage/partition_search_test.go index 2f2d28527..4e37ea6ae 100644 --- a/lib/storage/partition_search_test.go +++ b/lib/storage/partition_search_test.go @@ -186,6 +186,7 @@ func testPartitionSearchEx(t *testing.T, ptt int64, tr TimeRange, partsCount, ma pt = mustOpenPartition(smallPartsPath, bigPartsPath, strg) testPartitionSearch(t, pt, tsids, tr, rbsExpected, rowsCountExpected) pt.MustClose() + stopTestStorage(strg) if err := os.RemoveAll("small-table"); err != nil { t.Fatalf("cannot remove small parts directory: %s", err) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index bd444bbc1..818de037d 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -1845,7 +1845,7 @@ func SetLogNewSeries(ok bool) { var logNewSeries = false -func (s *Storage) createAllIndexesForMetricName(is *indexSearch, mn *MetricName, metricNameRaw []byte, genTSID *generationTSID, date uint64) error { +func (s *Storage) createAllIndexesForMetricName(is *indexSearch, mn *MetricName, metricNameRaw []byte, genTSID *generationTSID, date uint64) { is.createGlobalIndexes(&genTSID.TSID, mn) is.createPerDayIndexes(date, &genTSID.TSID, mn) @@ -1856,8 +1856,6 @@ func (s *Storage) createAllIndexesForMetricName(is *indexSearch, mn *MetricName, // Register the (date, metricID) entry in the cache, // so next time the entry is found there instead of searching for it in the indexdb. s.dateMetricIDCache.Set(date, genTSID.TSID.MetricID) - - return nil } func (s *Storage) registerSeriesCardinality(metricID uint64, metricNameRaw []byte) bool { diff --git a/lib/storage/table_search_test.go b/lib/storage/table_search_test.go index 20a387061..d92e8f786 100644 --- a/lib/storage/table_search_test.go +++ b/lib/storage/table_search_test.go @@ -203,6 +203,7 @@ func testTableSearchEx(t *testing.T, rng *rand.Rand, trData, trSearch TimeRange, tb = mustOpenTable("test-table", strg) testTableSearch(t, tb, tsids, trSearch, rbsExpected, rowsCountExpected) tb.MustClose() + stopTestStorage(strg) } func testTableSearch(t *testing.T, tb *table, tsids []TSID, tr TimeRange, rbsExpected []rawBlock, rowsCountExpected int64) { diff --git a/lib/storage/table_search_timing_test.go b/lib/storage/table_search_timing_test.go index 1e9a62b48..a0c8fd376 100644 --- a/lib/storage/table_search_timing_test.go +++ b/lib/storage/table_search_timing_test.go @@ -38,7 +38,7 @@ func BenchmarkTableSearch(b *testing.B) { } } -func openBenchTable(b *testing.B, startTimestamp int64, rowsPerInsert, rowsCount, tsidsCount int) *table { +func openBenchTable(b *testing.B, startTimestamp int64, rowsPerInsert, rowsCount, tsidsCount int) (*table, *Storage) { b.Helper() path := filepath.Join("benchmarkTableSearch", fmt.Sprintf("rows%d_tsids%d", rowsCount, tsidsCount)) @@ -58,7 +58,7 @@ func openBenchTable(b *testing.B, startTimestamp int64, rowsPerInsert, rowsCount b.Fatalf("unexpected rows count in the table %q; got %d; want %d", path, rowsCount, rowsCountExpected) } - return tb + return tb, strg } var createdBenchTables = make(map[string]bool) @@ -98,13 +98,14 @@ func createBenchTable(b *testing.B, path string, startTimestamp int64, rowsPerIn wg.Wait() tb.MustClose() + stopTestStorage(strg) } func benchmarkTableSearch(b *testing.B, rowsCount, tsidsCount, tsidsSearch int) { startTimestamp := timestampFromTime(time.Now()) - 365*24*3600*1000 rowsPerInsert := getMaxRawRowsPerShard() - tb := openBenchTable(b, startTimestamp, rowsPerInsert, rowsCount, tsidsCount) + tb, strg := openBenchTable(b, startTimestamp, rowsPerInsert, rowsCount, tsidsCount) tr := TimeRange{ MinTimestamp: startTimestamp, MaxTimestamp: (1 << 63) - 1, @@ -135,4 +136,5 @@ func benchmarkTableSearch(b *testing.B, rowsCount, tsidsCount, tsidsSearch int) b.StopTimer() tb.MustClose() + stopTestStorage(strg) } diff --git a/lib/storage/table_test.go b/lib/storage/table_test.go index 2e8da8aad..c664a55fe 100644 --- a/lib/storage/table_test.go +++ b/lib/storage/table_test.go @@ -29,4 +29,6 @@ func TestTableOpenClose(t *testing.T) { tb := mustOpenTable(path, strg) tb.MustClose() } + + stopTestStorage(strg) } diff --git a/lib/storage/table_timing_test.go b/lib/storage/table_timing_test.go index 56865900f..d7363105f 100644 --- a/lib/storage/table_timing_test.go +++ b/lib/storage/table_timing_test.go @@ -104,4 +104,5 @@ func benchmarkTableAddRows(b *testing.B, rowsPerInsert, tsidsCount int) { b.Fatalf("cannot remove table %q: %s", tablePath, err) } } + stopTestStorage(strg) }