mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: replace the remaining atomic.* functions with atomic.* types for the sake of consistency
See ea9e2b19a5
This commit is contained in:
parent
b3d9d36fb3
commit
55f1f24e62
3 changed files with 15 additions and 8 deletions
|
@ -2611,8 +2611,12 @@ func (s *Storage) mustOpenIndexDBTables(path string) (next, curr, prev *indexDB)
|
||||||
var indexDBTableNameRegexp = regexp.MustCompile("^[0-9A-F]{16}$")
|
var indexDBTableNameRegexp = regexp.MustCompile("^[0-9A-F]{16}$")
|
||||||
|
|
||||||
func nextIndexDBTableName() string {
|
func nextIndexDBTableName() string {
|
||||||
n := atomic.AddUint64(&indexDBTableIdx, 1)
|
n := indexDBTableIdx.Add(1)
|
||||||
return fmt.Sprintf("%016X", n)
|
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
|
||||||
|
}()
|
||||||
|
|
|
@ -25,7 +25,7 @@ func benchmarkStorageAddRows(b *testing.B, rowsPerBatch int) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var globalOffset uint64
|
var globalOffset atomic.Uint64
|
||||||
|
|
||||||
b.SetBytes(int64(rowsPerBatch))
|
b.SetBytes(int64(rowsPerBatch))
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
@ -39,7 +39,7 @@ func benchmarkStorageAddRows(b *testing.B, rowsPerBatch int) {
|
||||||
{[]byte("instance"), []byte("1.2.3.4")},
|
{[]byte("instance"), []byte("1.2.3.4")},
|
||||||
}
|
}
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
offset := int(atomic.AddUint64(&globalOffset, uint64(rowsPerBatch)))
|
offset := int(globalOffset.Add(uint64(rowsPerBatch)))
|
||||||
for i := 0; i < rowsPerBatch; i++ {
|
for i := 0; i < rowsPerBatch; i++ {
|
||||||
mr := &mrs[i]
|
mr := &mrs[i]
|
||||||
mr.MetricNameRaw = mn.marshalRaw(mr.MetricNameRaw[:0])
|
mr.MetricNameRaw = mn.marshalRaw(mr.MetricNameRaw[:0])
|
||||||
|
|
|
@ -69,8 +69,11 @@ func createBenchTable(b *testing.B, path string, startTimestamp int64, rowsPerIn
|
||||||
strg := newTestStorage()
|
strg := newTestStorage()
|
||||||
tb := mustOpenTable(path, strg)
|
tb := mustOpenTable(path, strg)
|
||||||
|
|
||||||
insertsCount := uint64((rowsCount + rowsPerInsert - 1) / rowsPerInsert)
|
var insertsCount atomic.Int64
|
||||||
timestamp := uint64(startTimestamp)
|
insertsCount.Store(int64((rowsCount + rowsPerInsert - 1) / rowsPerInsert))
|
||||||
|
|
||||||
|
var timestamp atomic.Uint64
|
||||||
|
timestamp.Store(uint64(startTimestamp))
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for k := 0; k < cgroup.AvailableCPUs(); k++ {
|
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)))
|
rng := rand.New(rand.NewSource(int64(n)))
|
||||||
rows := make([]rawRow, rowsPerInsert)
|
rows := make([]rawRow, rowsPerInsert)
|
||||||
value := float64(100)
|
value := float64(100)
|
||||||
for int(atomic.AddUint64(&insertsCount, ^uint64(0))) >= 0 {
|
for insertsCount.Add(-1) >= 0 {
|
||||||
for j := 0; j < rowsPerInsert; j++ {
|
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))
|
value += float64(int(rng.NormFloat64() * 5))
|
||||||
|
|
||||||
r := &rows[j]
|
r := &rows[j]
|
||||||
|
|
Loading…
Reference in a new issue