diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 6023031d7..dab0e7208 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -2611,8 +2611,12 @@ func (s *Storage) mustOpenIndexDBTables(path string) (next, curr, prev *indexDB) var indexDBTableNameRegexp = regexp.MustCompile("^[0-9A-F]{16}$") func nextIndexDBTableName() string { - n := atomic.AddUint64(&indexDBTableIdx, 1) + n := indexDBTableIdx.Add(1) return fmt.Sprintf("%016X", n) } -var indexDBTableIdx = uint64(time.Now().UnixNano()) +var indexDBTableIdx = func() *atomic.Uint64 { + var x atomic.Uint64 + x.Store(uint64(time.Now().UnixNano())) + return &x +}() diff --git a/lib/storage/storage_timing_test.go b/lib/storage/storage_timing_test.go index 1e95c8ce0..80666fc6d 100644 --- a/lib/storage/storage_timing_test.go +++ b/lib/storage/storage_timing_test.go @@ -25,7 +25,7 @@ func benchmarkStorageAddRows(b *testing.B, rowsPerBatch int) { } }() - var globalOffset uint64 + var globalOffset atomic.Uint64 b.SetBytes(int64(rowsPerBatch)) b.ReportAllocs() @@ -39,7 +39,7 @@ func benchmarkStorageAddRows(b *testing.B, rowsPerBatch int) { {[]byte("instance"), []byte("1.2.3.4")}, } for pb.Next() { - offset := int(atomic.AddUint64(&globalOffset, uint64(rowsPerBatch))) + offset := int(globalOffset.Add(uint64(rowsPerBatch))) for i := 0; i < rowsPerBatch; i++ { mr := &mrs[i] mr.MetricNameRaw = mn.marshalRaw(mr.MetricNameRaw[:0]) diff --git a/lib/storage/table_search_timing_test.go b/lib/storage/table_search_timing_test.go index 246cf9c60..ac4a5025e 100644 --- a/lib/storage/table_search_timing_test.go +++ b/lib/storage/table_search_timing_test.go @@ -69,8 +69,11 @@ func createBenchTable(b *testing.B, path string, startTimestamp int64, rowsPerIn strg := newTestStorage() tb := mustOpenTable(path, strg) - insertsCount := uint64((rowsCount + rowsPerInsert - 1) / rowsPerInsert) - timestamp := uint64(startTimestamp) + var insertsCount atomic.Int64 + insertsCount.Store(int64((rowsCount + rowsPerInsert - 1) / rowsPerInsert)) + + var timestamp atomic.Uint64 + timestamp.Store(uint64(startTimestamp)) var wg sync.WaitGroup for k := 0; k < cgroup.AvailableCPUs(); k++ { @@ -79,9 +82,9 @@ func createBenchTable(b *testing.B, path string, startTimestamp int64, rowsPerIn rng := rand.New(rand.NewSource(int64(n))) rows := make([]rawRow, rowsPerInsert) value := float64(100) - for int(atomic.AddUint64(&insertsCount, ^uint64(0))) >= 0 { + for insertsCount.Add(-1) >= 0 { for j := 0; j < rowsPerInsert; j++ { - ts := atomic.AddUint64(×tamp, uint64(10+rng.Int63n(2))) + ts := timestamp.Add(uint64(10 + rng.Int63n(2))) value += float64(int(rng.NormFloat64() * 5)) r := &rows[j]