lib/storage: run go fix -rangeint

This commit is contained in:
Aliaksandr Valialkin
2026-02-18 12:49:59 +01:00
parent 2ffd25a120
commit 655f0e9c1d
31 changed files with 145 additions and 145 deletions

View File

@@ -19,7 +19,7 @@ func TestMarshaledBlockHeaderSize(t *testing.T) {
func TestBlockHeaderMarshalUnmarshal(t *testing.T) {
var bh blockHeader
for i := 0; i < 1000; i++ {
for i := range 1000 {
bh.TSID.MetricID = uint64(i + 1)
bh.MinTimestamp = int64(-i*1e3 + 2)
bh.MaxTimestamp = int64(i*2e3 + 3)

View File

@@ -21,7 +21,7 @@ func TestBlockStreamReaderSingleBlockManyRows(t *testing.T) {
var rows []rawRow
var r rawRow
r.PrecisionBits = defaultPrecisionBits
for i := 0; i < maxRowsPerBlock; i++ {
for i := range maxRowsPerBlock {
r.Value = rng.Float64()*1e9 - 5e8
r.Timestamp = int64(i * 1e9)
rows = append(rows, r)
@@ -34,7 +34,7 @@ func TestBlockStreamReaderSingleTSIDManyBlocks(t *testing.T) {
var rows []rawRow
var r rawRow
r.PrecisionBits = 1
for i := 0; i < 5*maxRowsPerBlock; i++ {
for range 5 * maxRowsPerBlock {
r.Value = rng.NormFloat64() * 1e4
r.Timestamp = int64(rng.NormFloat64() * 1e9)
rows = append(rows, r)
@@ -47,7 +47,7 @@ func TestBlockStreamReaderManyTSIDSingleRow(t *testing.T) {
var rows []rawRow
var r rawRow
r.PrecisionBits = defaultPrecisionBits
for i := 0; i < 1000; i++ {
for i := range 1000 {
r.TSID.MetricID = uint64(i)
r.Value = rng.Float64()*1e9 - 5e8
r.Timestamp = int64(i * 1e9)
@@ -62,7 +62,7 @@ func TestBlockStreamReaderManyTSIDManyRows(t *testing.T) {
var r rawRow
r.PrecisionBits = defaultPrecisionBits
const blocks = 123
for i := 0; i < 3210; i++ {
for i := range 3210 {
r.TSID.MetricID = uint64((1e9 - i) % blocks)
r.Value = rng.Float64()
r.Timestamp = int64(rng.Float64() * 1e9)
@@ -77,7 +77,7 @@ func TestBlockStreamReaderReadConcurrent(t *testing.T) {
var r rawRow
r.PrecisionBits = defaultPrecisionBits
const blocks = 123
for i := 0; i < 3210; i++ {
for i := range 3210 {
r.TSID.MetricID = uint64((1e9 - i) % blocks)
r.Value = rng.Float64()
r.Timestamp = int64(rng.Float64() * 1e9)
@@ -87,12 +87,12 @@ func TestBlockStreamReaderReadConcurrent(t *testing.T) {
mp.InitFromRows(rows)
ch := make(chan error, 5)
for i := 0; i < 5; i++ {
for range 5 {
go func() {
ch <- testBlockStreamReaderReadRows(&mp, rows)
}()
}
for i := 0; i < 5; i++ {
for range 5 {
select {
case err := <-ch:
if err != nil {

View File

@@ -13,7 +13,7 @@ import (
func TestBlockMarshalUnmarshalPortable(t *testing.T) {
rng := rand.New(rand.NewSource(1))
var b Block
for i := 0; i < 1000; i++ {
for i := range 1000 {
b.Reset()
rowsCount := rng.Intn(maxRowsPerBlock) + 1
b.timestamps = getRandTimestamps(rowsCount)
@@ -132,7 +132,7 @@ func getValuesForPrecisionBits(values []int64, precisionBits uint8) []int64 {
func getRandValues(rowsCount int) []int64 {
rng := rand.New(rand.NewSource(1))
a := make([]int64, rowsCount)
for i := 0; i < rowsCount; i++ {
for i := range rowsCount {
a[i] = int64(rng.Intn(1e5) - 0.5e5)
}
return a
@@ -142,7 +142,7 @@ func getRandTimestamps(rowsCount int) []int64 {
rng := rand.New(rand.NewSource(1))
a := make([]int64, rowsCount)
ts := int64(rng.Intn(1e9))
for i := 0; i < rowsCount; i++ {
for i := range rowsCount {
a[i] = ts
ts += int64(rng.Intn(1e5))
}

View File

@@ -21,12 +21,12 @@ func TestDateMetricIDCacheConcurrent(t *testing.T) {
c := newDateMetricIDCache()
defer c.MustStop()
ch := make(chan error, 5)
for i := 0; i < 5; i++ {
for range 5 {
go func() {
ch <- testDateMetricIDCache(c, true)
}()
}
for i := 0; i < 5; i++ {
for range 5 {
select {
case err := <-ch:
if err != nil {
@@ -44,7 +44,7 @@ func testDateMetricIDCache(c *dateMetricIDCache, concurrent bool) error {
metricID uint64
}
m := make(map[dmk]bool)
for i := 0; i < 1e5; i++ {
for i := range int(1e5) {
date := uint64(i) % 2
metricID := uint64(i) % 1237
if !concurrent && c.Has(date, metricID) {
@@ -72,7 +72,7 @@ func testDateMetricIDCache(c *dateMetricIDCache, concurrent bool) error {
}
// Verify fast path after sync.
for i := 0; i < 1e5; i++ {
for i := range int(1e5) {
date := uint64(i) % 2
metricID := uint64(i) % 123
c.Set(date, metricID)
@@ -80,7 +80,7 @@ func testDateMetricIDCache(c *dateMetricIDCache, concurrent bool) error {
c.mu.Lock()
c.syncLocked()
c.mu.Unlock()
for i := 0; i < 1e5; i++ {
for i := range int(1e5) {
date := uint64(i) % 2
metricID := uint64(i) % 123
if !concurrent && !c.Has(date, metricID) {

View File

@@ -10,7 +10,7 @@ func BenchmarkDeduplicateSamples(b *testing.B) {
const blockSize = 8192
timestamps := make([]int64, blockSize)
values := make([]float64, blockSize)
for i := 0; i < len(timestamps); i++ {
for i := range timestamps {
isDuplicate := i%2 == 1
ts := int64(i) * 1e3
if isDuplicate {
@@ -44,7 +44,7 @@ func BenchmarkDeduplicateSamplesDuringMerge(b *testing.B) {
const blockSize = 8192
timestamps := make([]int64, blockSize)
values := make([]int64, blockSize)
for i := 0; i < len(timestamps); i++ {
for i := range timestamps {
isDuplicate := i%2 == 1
ts := int64(i) * 1e3
if isDuplicate {

View File

@@ -3224,7 +3224,7 @@ func (mp *tagToMetricIDsRowParser) ParseMetricIDs() {
mp.MetricIDs = slicesutil.SetLength(mp.MetricIDs, n)
metricIDs := mp.MetricIDs
_ = metricIDs[n-1]
for i := 0; i < n; i++ {
for i := range n {
if len(tail) < 8 {
logger.Panicf("BUG: tail cannot be smaller than 8 bytes; got %d bytes; tail=%X", len(tail), tail)
return

View File

@@ -330,7 +330,7 @@ func TestMergeTagToMetricIDsRows(t *testing.T) {
var metricIDs []uint64
metricIDs = metricIDs[:0]
for i := 0; i < maxMetricIDsPerRow-1; i++ {
for i := range maxMetricIDsPerRow - 1 {
metricIDs = append(metricIDs, uint64(i))
}
f([]string{
@@ -348,7 +348,7 @@ func TestMergeTagToMetricIDsRows(t *testing.T) {
})
metricIDs = metricIDs[:0]
for i := 0; i < maxMetricIDsPerRow; i++ {
for i := range maxMetricIDsPerRow {
metricIDs = append(metricIDs, uint64(i))
}
f([]string{
@@ -364,7 +364,7 @@ func TestMergeTagToMetricIDsRows(t *testing.T) {
})
metricIDs = metricIDs[:0]
for i := 0; i < 3*maxMetricIDsPerRow; i++ {
for i := range 3 * maxMetricIDsPerRow {
metricIDs = append(metricIDs, uint64(i))
}
f([]string{
@@ -394,7 +394,7 @@ func TestMergeTagToMetricIDsRows(t *testing.T) {
// Check for duplicate metricIDs removal
metricIDs = metricIDs[:0]
for i := 0; i < maxMetricIDsPerRow-1; i++ {
for range maxMetricIDsPerRow - 1 {
metricIDs = append(metricIDs, 123)
}
f([]string{
@@ -412,7 +412,7 @@ func TestMergeTagToMetricIDsRows(t *testing.T) {
// Check fallback to the original items after merging, which result in incorrect ordering.
metricIDs = metricIDs[:0]
for i := 0; i < maxMetricIDsPerRow-3; i++ {
for range maxMetricIDsPerRow - 3 {
metricIDs = append(metricIDs, uint64(123))
}
f([]string{
@@ -476,7 +476,7 @@ func TestIndexDBOpenClose(t *testing.T) {
var s Storage
path := filepath.Join(t.Name(), "2025_01")
for i := 0; i < 5; i++ {
for range 5 {
var isReadOnly atomic.Bool
db := mustOpenIndexDB(123, TimeRange{}, "name", path, &s, &isReadOnly, false)
db.MustClose()
@@ -523,7 +523,7 @@ func TestIndexDB(t *testing.T) {
db := ptw.pt.idb
ch := make(chan error, 3)
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
go func() {
mns, tsid, err := testIndexDBGetOrCreateTSIDByName(db, metricGroups, timestamp)
if err != nil {
@@ -538,7 +538,7 @@ func TestIndexDB(t *testing.T) {
}()
}
deadlineCh := time.After(30 * time.Second)
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
select {
case err := <-ch:
if err != nil {
@@ -566,7 +566,7 @@ func testIndexDBGetOrCreateTSIDByName(db *indexDB, metricGroups int, timestamp i
date := uint64(timestamp) / msecPerDay
var metricNameBuf []byte
for i := 0; i < 401; i++ {
for i := range 401 {
var mn MetricName
// Init MetricGroup.
@@ -574,7 +574,7 @@ func testIndexDBGetOrCreateTSIDByName(db *indexDB, metricGroups int, timestamp i
// Init other tags.
tagsCount := r.Intn(10) + 1
for j := 0; j < tagsCount; j++ {
for j := range tagsCount {
key := fmt.Sprintf("key\x01\x02\x00_%d_%d", i, j)
value := fmt.Sprintf("val\x01_%d\x00_%d\x02", i, j)
mn.AddTag(key, value)
@@ -712,7 +712,7 @@ func testIndexDBCheckTSIDByName(db *indexDB, mns []MetricName, tsids []TSID, tim
if err := tfs.Add(nil, mn.MetricGroup, false, false); err != nil {
return fmt.Errorf("cannot create tag filter for MetricGroup: %w", err)
}
for j := 0; j < len(mn.Tags); j++ {
for j := range mn.Tags {
t := &mn.Tags[j]
if err := tfs.Add(t.Key, t.Value, false, false); err != nil {
return fmt.Errorf("cannot create tag filter for tag: %w", err)
@@ -813,7 +813,7 @@ func testIndexDBCheckTSIDByName(db *indexDB, mns []MetricName, tsids []TSID, tim
if err := tfs.Add(nil, mn.MetricGroup, false, true); err != nil {
return fmt.Errorf("cannot create regexp tag filter for MetricGroup: %w", err)
}
for j := 0; j < len(mn.Tags); j++ {
for j := range mn.Tags {
t := &mn.Tags[j]
if err := tfs.Add(t.Key, append(t.Value, "|foo*."...), false, true); err != nil {
return fmt.Errorf("cannot create regexp tag filter for tag: %w", err)
@@ -960,7 +960,7 @@ func TestGetRegexpForGraphiteNodeQuery(t *testing.T) {
func TestMatchTagFilters(t *testing.T) {
var mn MetricName
mn.MetricGroup = append(mn.MetricGroup, "foobar_metric"...)
for i := 0; i < 5; i++ {
for i := range 5 {
key := fmt.Sprintf("key %d", i)
value := fmt.Sprintf("value %d", i)
mn.AddTag(key, value)
@@ -1471,10 +1471,10 @@ func TestSearchTSIDWithTimeRange(t *testing.T) {
db := ptw.pt.idb
is := db.getIndexSearch(noDeadline)
for day := 0; day < days; day++ {
for day := range days {
date := baseDate - uint64(day)
var metricIDs uint64set.Set
for metric := 0; metric < metricsPerDay; metric++ {
for metric := range metricsPerDay {
mn := newMN("testMetric", day, metric)
metricNameBuf = mn.Marshal(metricNameBuf[:0])
var tsid TSID

View File

@@ -79,7 +79,7 @@ func BenchmarkIndexDBAddTSIDs(b *testing.B) {
func benchmarkIndexDBAddTSIDs(db *indexDB, tsid *TSID, mn *MetricName, timestamp int64, startOffset, recordsPerLoop int) {
date := uint64(timestamp) / msecPerDay
for i := 0; i < recordsPerLoop; i++ {
for i := range recordsPerLoop {
mn.MetricGroup = strconv.AppendUint(mn.MetricGroup[:0], uint64(i+startOffset), 10)
for j := range mn.Tags {
mn.Tags[j].Value = strconv.AppendUint(mn.Tags[j].Value[:0], uint64(i*j), 16)
@@ -113,9 +113,9 @@ func BenchmarkHeadPostingForMatchers(b *testing.B) {
generateTSID(&tsid, &mn)
createAllIndexesForMetricName(db, &mn, &tsid, date)
}
for n := 0; n < 10; n++ {
for n := range 10 {
ns := strconv.Itoa(n)
for i := 0; i < 100000; i++ {
for i := range 100000 {
ix := strconv.Itoa(i)
addSeries("i", ix, "n", ns, "j", "foo")
// Have some series that won't be matched, to properly test inverted matches.
@@ -135,7 +135,7 @@ func BenchmarkHeadPostingForMatchers(b *testing.B) {
// Use special globalIndexTimeRange to instruct indexDB to search global
// index instead of per-day index.
tr := globalIndexTimeRange
for i := 0; i < b.N; i++ {
for range b.N {
is := db.getIndexSearch(noDeadline)
metricIDs, err := is.searchMetricIDs(nil, tfss, tr, 2e9)
db.putIndexSearch(is)
@@ -273,7 +273,7 @@ func BenchmarkIndexDBGetTSIDs(b *testing.B) {
// Fill the db with recordsCount records.
var mn MetricName
mn.MetricGroup = []byte("rps")
for i := 0; i < 2; i++ {
for i := range 2 {
key := fmt.Sprintf("key_%d", i)
value := fmt.Sprintf("value_%d", i)
mn.AddTag(key, value)
@@ -283,7 +283,7 @@ func BenchmarkIndexDBGetTSIDs(b *testing.B) {
var tsid TSID
date := uint64(timestamp) / msecPerDay
for i := 0; i < recordsCount; i++ {
for range int(recordsCount) {
generateTSID(&tsid, &mn)
createAllIndexesForMetricName(db, &mn, &tsid, date)
}
@@ -300,7 +300,7 @@ func BenchmarkIndexDBGetTSIDs(b *testing.B) {
mnLocal.sortTags()
for pb.Next() {
is := db.getIndexSearch(noDeadline)
for i := 0; i < recordsPerLoop; i++ {
for i := range recordsPerLoop {
metricNameLocal = mnLocal.Marshal(metricNameLocal[:0])
if !is.getTSIDByMetricName(&tsidLocal, metricNameLocal, date) {
panic(fmt.Errorf("cannot obtain tsid for row %d", i))

View File

@@ -27,7 +27,7 @@ func TestInmemoryPartInitFromRows(t *testing.T) {
rows = rows[:0]
initTestTSID(&r.TSID)
r.PrecisionBits = defaultPrecisionBits
for i := uint64(0); i < 1e4; i++ {
for range uint64(1e4) {
r.Timestamp = int64(rng.NormFloat64() * 1e7)
r.Value = rng.NormFloat64() * 100
@@ -37,7 +37,7 @@ func TestInmemoryPartInitFromRows(t *testing.T) {
// Test distinct tsids.
rows = rows[:0]
for i := 0; i < 1e4; i++ {
for i := range int(1e4) {
initTestTSID(&r.TSID)
r.TSID.MetricID = uint64(i)
r.Timestamp = int64(rng.NormFloat64() * 1e7)

View File

@@ -29,7 +29,7 @@ var benchRawRowsWorstCase = func() []rawRow {
rng := rand.New(rand.NewSource(1))
var rows []rawRow
var r rawRow
for i := 0; i < 1e5; i++ {
for i := range int(1e5) {
r.TSID.MetricID = uint64(i)
r.Timestamp = rng.Int63()
r.Value = rng.NormFloat64()
@@ -45,7 +45,7 @@ var benchRawRowsBestCase = func() []rawRow {
var rows []rawRow
var r rawRow
r.PrecisionBits = defaultPrecisionBits
for i := 0; i < 1e5; i++ {
for range int(1e5) {
r.Timestamp += 30e3
rows = append(rows, r)
}

View File

@@ -29,7 +29,7 @@ func TestMergeBlockStreamsOneStreamOneBlockManyRows(t *testing.T) {
r.PrecisionBits = 4
minTimestamp := int64(1<<63 - 1)
maxTimestamp := int64(-1 << 63)
for i := 0; i < maxRowsPerBlock; i++ {
for range maxRowsPerBlock {
r.Timestamp = int64(rng.Intn(1e9))
r.Value = rng.NormFloat64() * 2332
rows = append(rows, r)
@@ -54,7 +54,7 @@ func TestMergeBlockStreamsOneStreamManyBlocksOneRow(t *testing.T) {
const blocksCount = 1234
minTimestamp := int64(1<<63 - 1)
maxTimestamp := int64(-1 << 63)
for i := 0; i < blocksCount; i++ {
for i := range blocksCount {
initTestTSID(&r.TSID)
r.TSID.MetricID = uint64(i * 123)
r.Timestamp = int64(rng.Intn(1e9))
@@ -83,7 +83,7 @@ func TestMergeBlockStreamsOneStreamManyBlocksManyRows(t *testing.T) {
const rowsCount = 4938
minTimestamp := int64(1<<63 - 1)
maxTimestamp := int64(-1 << 63)
for i := 0; i < rowsCount; i++ {
for i := range rowsCount {
r.TSID.MetricID = uint64(i % blocksCount)
r.Timestamp = int64(rng.Intn(1e9))
r.Value = rng.NormFloat64() * 2332
@@ -181,7 +181,7 @@ func TestMergeBlockStreamsTwoStreamsManyBlocksManyRows(t *testing.T) {
initTestTSID(&r.TSID)
r.PrecisionBits = 2
const rowsCount1 = 4938
for i := 0; i < rowsCount1; i++ {
for i := range rowsCount1 {
r.TSID.MetricID = uint64(i % blocksCount)
r.Timestamp = int64(rng.Intn(1e9))
r.Value = rng.NormFloat64() * 2332
@@ -198,7 +198,7 @@ func TestMergeBlockStreamsTwoStreamsManyBlocksManyRows(t *testing.T) {
rows = rows[:0]
const rowsCount2 = 3281
for i := 0; i < rowsCount2; i++ {
for i := range rowsCount2 {
r.TSID.MetricID = uint64((i + 17) % blocksCount)
r.Timestamp = int64(rng.Intn(1e9))
r.Value = rng.NormFloat64() * 2332
@@ -226,7 +226,7 @@ func TestMergeBlockStreamsTwoStreamsBigOverlappingBlocks(t *testing.T) {
var r rawRow
r.PrecisionBits = 5
const rowsCount1 = maxRowsPerBlock + 234
for i := 0; i < rowsCount1; i++ {
for i := range rowsCount1 {
r.Timestamp = int64(i * 2894)
r.Value = float64(int(rng.NormFloat64() * 1e2))
rows = append(rows, r)
@@ -242,7 +242,7 @@ func TestMergeBlockStreamsTwoStreamsBigOverlappingBlocks(t *testing.T) {
rows = rows[:0]
const rowsCount2 = maxRowsPerBlock + 2344
for i := 0; i < rowsCount2; i++ {
for i := range rowsCount2 {
r.Timestamp = int64(i * 2494)
r.Value = float64(int(rng.NormFloat64() * 1e2))
rows = append(rows, r)
@@ -269,7 +269,7 @@ func TestMergeBlockStreamsTwoStreamsBigSequentialBlocks(t *testing.T) {
var r rawRow
r.PrecisionBits = 5
const rowsCount1 = maxRowsPerBlock + 234
for i := 0; i < rowsCount1; i++ {
for i := range rowsCount1 {
r.Timestamp = int64(i * 2894)
r.Value = float64(int(rng.NormFloat64() * 1e2))
rows = append(rows, r)
@@ -286,7 +286,7 @@ func TestMergeBlockStreamsTwoStreamsBigSequentialBlocks(t *testing.T) {
rows = rows[:0]
const rowsCount2 = maxRowsPerBlock - 233
for i := 0; i < rowsCount2; i++ {
for i := range rowsCount2 {
r.Timestamp = maxTimestampB1 + int64(i*2494)
r.Value = float64(int(rng.NormFloat64() * 1e2))
rows = append(rows, r)
@@ -316,10 +316,10 @@ func TestMergeBlockStreamsManyStreamsManyBlocksManyRows(t *testing.T) {
rowsCount := 0
const blocksCount = 113
var bsrs []*blockStreamReader
for i := 0; i < 20; i++ {
for range 20 {
rowsPerStream := rng.Intn(500)
var rows []rawRow
for j := 0; j < rowsPerStream; j++ {
for j := range rowsPerStream {
r.TSID.MetricID = uint64(j % blocksCount)
r.Timestamp = int64(rng.Intn(1e9))
r.Value = rng.NormFloat64()
@@ -350,10 +350,10 @@ func TestMergeForciblyStop(t *testing.T) {
rng := rand.New(rand.NewSource(1))
const blocksCount = 113
var bsrs []*blockStreamReader
for i := 0; i < 20; i++ {
for range 20 {
rowsPerStream := rng.Intn(1000)
var rows []rawRow
for j := 0; j < rowsPerStream; j++ {
for j := range rowsPerStream {
r.TSID.MetricID = uint64(j % blocksCount)
r.Timestamp = int64(rng.Intn(1e9))
r.Value = rng.NormFloat64()

View File

@@ -58,7 +58,7 @@ var benchTwoSourcesWorstCaseMPS = func() []*inmemoryPart {
var rows []rawRow
var r rawRow
r.PrecisionBits = defaultPrecisionBits
for i := 0; i < maxRowsPerBlock/2-1; i++ {
for range maxRowsPerBlock/2 - 1 {
r.Value = rng.NormFloat64()
r.Timestamp = rng.Int63n(1e12)
rows = append(rows, r)
@@ -72,11 +72,11 @@ const benchTwoSourcesWorstCaseMPSRowsPerLoop = (maxRowsPerBlock - 2)
var benchTwoSourcesBestCaseMPS = func() []*inmemoryPart {
var r rawRow
var mps []*inmemoryPart
for i := 0; i < 2; i++ {
for i := range 2 {
var rows []rawRow
r.PrecisionBits = defaultPrecisionBits
r.TSID.MetricID = uint64(i)
for j := 0; j < maxRowsPerBlock; j++ {
for range maxRowsPerBlock {
rows = append(rows, r)
}
mp := newTestInmemoryPart(rows)
@@ -92,7 +92,7 @@ var benchFourSourcesWorstCaseMPS = func() []*inmemoryPart {
var rows []rawRow
var r rawRow
r.PrecisionBits = defaultPrecisionBits
for i := 0; i < maxRowsPerBlock/2-1; i++ {
for range maxRowsPerBlock/2 - 1 {
r.Value = rng.NormFloat64()
r.Timestamp = rng.Int63n(1e12)
rows = append(rows, r)
@@ -106,11 +106,11 @@ const benchFourSourcesWorstCaseMPSRowsPerLoop = 2 * (maxRowsPerBlock - 2)
var benchFourSourcesBestCaseMPS = func() []*inmemoryPart {
var r rawRow
var mps []*inmemoryPart
for i := 0; i < 4; i++ {
for i := range 4 {
var rows []rawRow
r.PrecisionBits = defaultPrecisionBits
r.TSID.MetricID = uint64(i)
for j := 0; j < maxRowsPerBlock; j++ {
for range maxRowsPerBlock {
rows = append(rows, r)
}
mp := newTestInmemoryPart(rows)

View File

@@ -32,7 +32,7 @@ func TestMetaindexRowReset(t *testing.T) {
func TestMetaindexRowMarshalUnmarshal(t *testing.T) {
var mr metaindexRow
for i := 0; i < 1000; i++ {
for range 1000 {
initTestMetaindexRow(&mr)
testMetaindexRowMarshalUnmarshal(t, &mr)
}

View File

@@ -88,10 +88,10 @@ func TestMetricNameMarshalDuplicateKeys(t *testing.T) {
}
func TestMetricNameMarshalUnmarshal(t *testing.T) {
for i := 0; i < 10; i++ {
for tagsCount := 0; tagsCount < 10; tagsCount++ {
for i := range 10 {
for tagsCount := range 10 {
var mn MetricName
for j := 0; j < tagsCount; j++ {
for j := range tagsCount {
key := fmt.Sprintf("key_%d_%d_\x00\x01\x02", i, j)
value := fmt.Sprintf("\x02\x00\x01value_%d_%d", i, j)
mn.AddTag(key, value)
@@ -130,10 +130,10 @@ func TestMetricNameMarshalUnmarshal(t *testing.T) {
}
func TestMetricNameMarshalUnmarshalRaw(t *testing.T) {
for i := 0; i < 10; i++ {
for tagsCount := 0; tagsCount < 10; tagsCount++ {
for i := range 10 {
for tagsCount := range 10 {
var mn MetricName
for j := 0; j < tagsCount; j++ {
for j := range tagsCount {
key := fmt.Sprintf("key_%d_%d_\x00\x01\x02", i, j)
value := fmt.Sprintf("\x02\x00\x01value_%d_%d", i, j)
mn.AddTag(key, value)

View File

@@ -1160,7 +1160,7 @@ func testPartSearchMultiRowsOneTSID(t *testing.T, rowsCount int) {
var r rawRow
r.PrecisionBits = 24
r.TSID.MetricID = 1111
for i := 0; i < rowsCount; i++ {
for range rowsCount {
r.Timestamp = int64(rng.NormFloat64() * 1e6)
r.Value = float64(int(rng.NormFloat64() * 1e5))
rows = append(rows, r)
@@ -1196,7 +1196,7 @@ func testPartSearchMultiRowsMultiTSIDs(t *testing.T, rowsCount, tsidsCount int)
var rows []rawRow
var r rawRow
r.PrecisionBits = 24
for i := 0; i < rowsCount; i++ {
for range rowsCount {
r.TSID.MetricID = uint64(rng.Intn(tsidsCount))
r.Timestamp = int64(rng.NormFloat64() * 1e6)
r.Value = float64(int(rng.NormFloat64() * 1e5))
@@ -1205,7 +1205,7 @@ func testPartSearchMultiRowsMultiTSIDs(t *testing.T, rowsCount, tsidsCount int)
var tsids []TSID
var tsid TSID
for i := 0; i < 100; i++ {
for range 100 {
tsid.MetricID = uint64(rng.Intn(tsidsCount * 3))
tsids = append(tsids, tsid)
}
@@ -1229,13 +1229,13 @@ func testPartSearch(t *testing.T, p *part, tsids []TSID, tr TimeRange, expectedR
// Run concurrent part search.
ch := make(chan error, 5)
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
go func() {
err := testPartSearchSerial(p, tsids, tr, expectedRawBlocks)
ch <- err
}()
}
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
select {
case err := <-ch:
if err != nil {

View File

@@ -16,7 +16,7 @@ func BenchmarkPartSearch(b *testing.B) {
func benchmarkPartSearchWithSparseness(b *testing.B, sparseness int) {
blocksCount := 100000
rows := make([]rawRow, blocksCount)
for i := 0; i < blocksCount; i++ {
for i := range blocksCount {
r := &rows[i]
r.PrecisionBits = defaultPrecisionBits
r.TSID.MetricID = uint64(i * sparseness)
@@ -31,7 +31,7 @@ func benchmarkPartSearchWithSparseness(b *testing.B, sparseness int) {
for _, tsidsCount := range []int{100, 1000, 10000, 100000} {
b.Run(fmt.Sprintf("tsids-%d", tsidsCount), func(b *testing.B) {
tsids := make([]TSID, tsidsCount)
for i := 0; i < tsidsCount; i++ {
for i := range tsidsCount {
tsids[i].MetricID = uint64(i)
}
benchmarkPartSearch(b, p, tsids, tr, sparseness)

View File

@@ -1002,7 +1002,7 @@ func (pt *partition) DebugFlush() {
func (pt *partition) startInmemoryPartsMergers() {
pt.partsLock.Lock()
for i := 0; i < cap(inmemoryPartsConcurrencyCh); i++ {
for range cap(inmemoryPartsConcurrencyCh) {
pt.startInmemoryPartsMergerLocked()
}
pt.partsLock.Unlock()
@@ -1019,7 +1019,7 @@ func (pt *partition) startInmemoryPartsMergerLocked() {
func (pt *partition) startSmallPartsMergers() {
pt.partsLock.Lock()
for i := 0; i < cap(smallPartsConcurrencyCh); i++ {
for range cap(smallPartsConcurrencyCh) {
pt.startSmallPartsMergerLocked()
}
pt.partsLock.Unlock()
@@ -1036,7 +1036,7 @@ func (pt *partition) startSmallPartsMergerLocked() {
func (pt *partition) startBigPartsMergers() {
pt.partsLock.Lock()
for i := 0; i < cap(bigPartsConcurrencyCh); i++ {
for range cap(bigPartsConcurrencyCh) {
pt.startBigPartsMergerLocked()
}
pt.partsLock.Unlock()
@@ -1877,7 +1877,7 @@ func appendPartsToMerge(dst, src []*partWrapper, maxPartsToMerge int, maxOutByte
var pws []*partWrapper
maxM := float64(0)
for i := minSrcParts; i <= maxSrcParts; i++ {
for j := 0; j <= len(src)-i; j++ {
for j := range len(src) - i + 1 {
a := src[j : j+i]
if a[0].p.size*uint64(len(a)) < a[len(a)-1].p.size {
// Do not merge parts with too big difference in size,

View File

@@ -120,7 +120,7 @@ func testPartitionSearchEx(t *testing.T, ptt int64, tr TimeRange, partsCount, ma
// Generate tsids to search.
var tsids []TSID
var tsid TSID
for i := 0; i < 25; i++ {
for range 25 {
tsid.MetricID = uint64(rng.Intn(tsidsCount * 2))
tsids = append(tsids, tsid)
}
@@ -133,13 +133,13 @@ func testPartitionSearchEx(t *testing.T, ptt int64, tr TimeRange, partsCount, ma
var ptr TimeRange
ptr.fromPartitionTimestamp(ptt)
var rowss [][]rawRow
for i := 0; i < partsCount; i++ {
for range partsCount {
var rows []rawRow
var r rawRow
r.PrecisionBits = 30
timestamp := ptr.MinTimestamp
rowsCount := 1 + rng.Intn(maxRowsPerPart)
for j := 0; j < rowsCount; j++ {
for range rowsCount {
r.TSID.MetricID = uint64(rng.Intn(tsidsCount))
r.Timestamp = timestamp
r.Value = float64(int(rng.NormFloat64() * 1e5))
@@ -198,12 +198,12 @@ func testPartitionSearch(t *testing.T, pt *partition, tsids []TSID, tr TimeRange
}
ch := make(chan error, 5)
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
go func() {
ch <- testPartitionSearchSerial(pt, tsids, tr, rbsExpected, rowsCountExpected)
}()
}
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
select {
case err := <-ch:
if err != nil {

View File

@@ -44,7 +44,7 @@ func TestAppendPartsToMergeManyParts(t *testing.T) {
var sizes []uint64
maxOutSize := uint64(0)
r := rand.New(rand.NewSource(1))
for i := 0; i < 1024; i++ {
for range 1024 {
n := uint64(uint32(r.NormFloat64() * 1e9))
n++
maxOutSize += n

View File

@@ -435,7 +435,7 @@ func (sq *SearchQuery) Unmarshal(src []byte) ([]byte, error) {
src = src[nSize:]
sq.TagFilterss = slicesutil.SetLength(sq.TagFilterss, int(tfssCount))
for i := 0; i < int(tfssCount); i++ {
for i := range int(tfssCount) {
tfsCount, nSize := encoding.UnmarshalVarUint64(src)
if nSize <= 0 {
return src, fmt.Errorf("cannot unmarshal the count of TagFilters from uvarint")
@@ -444,7 +444,7 @@ func (sq *SearchQuery) Unmarshal(src []byte) ([]byte, error) {
tagFilters := sq.TagFilterss[i]
tagFilters = slicesutil.SetLength(tagFilters, int(tfsCount))
for j := 0; j < int(tfsCount); j++ {
for j := range int(tfsCount) {
tail, err := tagFilters[j].Unmarshal(src)
if err != nil {
return tail, fmt.Errorf("cannot unmarshal TagFilter #%d: %w", j, err)

View File

@@ -21,7 +21,7 @@ func TestSearchQueryMarshalUnmarshal(t *testing.T) {
var buf []byte
var sq2 SearchQuery
for i := 0; i < 1000; i++ {
for i := range 1000 {
v, ok := quick.Value(typ, rnd)
if !ok {
t.Fatalf("cannot create random SearchQuery via testing/quick.Value")
@@ -92,7 +92,7 @@ func TestSearch(t *testing.T) {
startTimestamp := timestampFromTime(time.Now())
startTimestamp -= startTimestamp % (1e3 * 60 * 30)
blockRowsCount := 0
for i := 0; i < rowsCount; i++ {
for i := range int(rowsCount) {
mn.MetricGroup = []byte(fmt.Sprintf("metric_%d", i%metricGroupsCount))
mr := &mrs[i]
@@ -124,13 +124,13 @@ func TestSearch(t *testing.T) {
t.Run("concurrent", func(t *testing.T) {
ch := make(chan error, 3)
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
go func() {
ch <- testSearchInternal(st, tr, mrs)
}()
}
var firstError error
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
select {
case err := <-ch:
if err != nil && firstError == nil {
@@ -178,7 +178,7 @@ func TestSearch_VariousTimeRanges(t *testing.T) {
}
func testSearchInternal(s *Storage, tr TimeRange, mrs []MetricRow) error {
for i := 0; i < 10; i++ {
for i := range 10 {
// Prepare TagFilters for search.
tfs := NewTagFilters()
metricGroupRe := fmt.Sprintf(`metric_\d*%d%d`, i, i)

View File

@@ -983,7 +983,7 @@ func unmarshalUint64Set(src []byte) (*uint64set.Set, []byte, error) {
return nil, nil, fmt.Errorf("cannot unmarshal uint64set; got %d bytes; want at least %d bytes", len(src), 8*mLen)
}
m := &uint64set.Set{}
for i := uint64(0); i < mLen; i++ {
for range mLen {
metricID := encoding.UnmarshalUint64(src)
src = src[8:]
m.Add(metricID)

View File

@@ -274,7 +274,7 @@ func TestMetricRowMarshalUnmarshal(t *testing.T) {
typ := reflect.TypeOf(&MetricRow{})
rng := rand.New(rand.NewSource(1))
for i := 0; i < 1000; i++ {
for range 1000 {
v, ok := quick.Value(typ, rng)
if !ok {
t.Fatalf("cannot create random MetricRow via quick.Value")
@@ -312,7 +312,7 @@ func TestStorageOpenClose(t *testing.T) {
MaxHourlySeries: 1e5,
MaxDailySeries: 1e6,
}
for i := 0; i < 10; i++ {
for range 10 {
s := MustOpenStorage(path, opts)
s.MustClose()
}
@@ -326,7 +326,7 @@ func TestStorageRandTimestamps(t *testing.T) {
}
s := MustOpenStorage(path, opts)
t.Run("serial", func(t *testing.T) {
for i := 0; i < 3; i++ {
for i := range 3 {
if err := testStorageRandTimestamps(s); err != nil {
t.Fatalf("error on iteration %d: %s", i, err)
}
@@ -336,17 +336,17 @@ func TestStorageRandTimestamps(t *testing.T) {
})
t.Run("concurrent", func(t *testing.T) {
ch := make(chan error, 3)
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
go func() {
var err error
for i := 0; i < 2; i++ {
for range 2 {
err = testStorageRandTimestamps(s)
}
ch <- err
}()
}
tt := time.NewTimer(time.Second * 10)
for i := 0; i < cap(ch); i++ {
for i := range cap(ch) {
select {
case err := <-ch:
if err != nil {
@@ -367,14 +367,14 @@ func testStorageRandTimestamps(s *Storage) error {
const addsCount = 3
rng := rand.New(rand.NewSource(1))
for i := 0; i < addsCount; i++ {
for range addsCount {
var mrs []MetricRow
var mn MetricName
mn.Tags = []Tag{
{[]byte("job"), []byte("webservice")},
{[]byte("instance"), []byte("1.2.3.4")},
}
for j := 0; j < rowsPerAdd; j++ {
for range int(rowsPerAdd) {
mn.MetricGroup = []byte(fmt.Sprintf("metric_%d", rng.Intn(100)))
metricNameRaw := mn.marshalRaw(nil)
timestamp := currentTime - int64((rng.Float64()-0.2)*float64(2*s.retentionMsecs))
@@ -542,8 +542,8 @@ func TestStorageDeleteSeries(t *testing.T) {
}
t.Run("serial", func(t *testing.T) {
for i := 0; i < 3; i++ {
if err = testStorageDeleteSeries(s, 0); err != nil {
for i := range 3 {
if err := testStorageDeleteSeries(s, 0); err != nil {
t.Fatalf("unexpected error on iteration %d: %s", i, err)
}
@@ -556,10 +556,10 @@ func TestStorageDeleteSeries(t *testing.T) {
t.Run("concurrent", func(t *testing.T) {
ch := make(chan error, 3)
for i := 0; i < cap(ch); i++ {
for i := range cap(ch) {
go func(workerNum int) {
var err error
for j := 0; j < 2; j++ {
for range 2 {
err = testStorageDeleteSeries(s, workerNum)
if err != nil {
break
@@ -569,7 +569,7 @@ func TestStorageDeleteSeries(t *testing.T) {
}(i)
}
tt := time.NewTimer(30 * time.Second)
for i := 0; i < cap(ch); i++ {
for i := range cap(ch) {
select {
case err := <-ch:
if err != nil {
@@ -603,7 +603,7 @@ func testStorageDeleteSeries(s *Storage, workerNum int) error {
lnsAll := make(map[string]bool)
lnsAll["__name__"] = true
for i := 0; i < metricsCount; i++ {
for i := range metricsCount {
var mrs []MetricRow
var mn MetricName
job := fmt.Sprintf("job_%d_%d", i, workerNum)
@@ -619,7 +619,7 @@ func testStorageDeleteSeries(s *Storage, workerNum int) error {
mn.MetricGroup = []byte(fmt.Sprintf("metric_%d_%d", i, workerNum))
metricNameRaw := mn.marshalRaw(nil)
for j := 0; j < rowsPerMetric; j++ {
for range rowsPerMetric {
timestamp := rng.Int63n(1e10)
value := rng.NormFloat64() * 1e6
@@ -667,7 +667,7 @@ func testStorageDeleteSeries(s *Storage, workerNum int) error {
sr.MustClose()
return n
}
for i := 0; i < metricsCount; i++ {
for i := range metricsCount {
tfs := NewTagFilters()
if err := tfs.Add(nil, []byte("metric_.+"), false, true); err != nil {
return fmt.Errorf("cannot add regexp tag filter: %w", err)
@@ -1353,12 +1353,12 @@ func TestStorageRegisterMetricNamesConcurrent(t *testing.T) {
path := "TestStorageRegisterMetricNamesConcurrent"
s := MustOpenStorage(path, OpenOptions{})
ch := make(chan error, 3)
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
go func() {
ch <- testStorageRegisterMetricNames(s)
}()
}
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
select {
case err := <-ch:
if err != nil {
@@ -1377,7 +1377,7 @@ func testStorageRegisterMetricNames(s *Storage) error {
const addsCount = 10
addIDsMap := make(map[string]struct{})
for i := 0; i < addsCount; i++ {
for i := range addsCount {
var mrs []MetricRow
var mn MetricName
addID := fmt.Sprintf("%d", i)
@@ -1388,7 +1388,7 @@ func testStorageRegisterMetricNames(s *Storage) error {
{[]byte("add_id"), []byte(addID)},
}
now := timestampFromTime(time.Now())
for j := 0; j < metricsPerAdd; j++ {
for j := range int(metricsPerAdd) {
mn.MetricGroup = []byte(fmt.Sprintf("metric_%d", j))
metricNameRaw := mn.marshalRaw(nil)
@@ -1517,13 +1517,13 @@ func TestStorageAddRowsConcurrent(t *testing.T) {
}
s := MustOpenStorage(path, opts)
ch := make(chan error, 3)
for i := 0; i < cap(ch); i++ {
for i := range cap(ch) {
go func(n int) {
rLocal := rand.New(rand.NewSource(int64(n)))
ch <- testStorageAddRows(rLocal, s)
}(i)
}
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
select {
case err := <-ch:
if err != nil {
@@ -1548,7 +1548,7 @@ func testGenerateMetricRowsWithPrefix(rng *rand.Rand, rows uint64, prefix string
{[]byte("job"), []byte("webservice")},
{[]byte("instance"), []byte("1.2.3.4")},
}
for i := 0; i < int(rows); i++ {
for i := range int(rows) {
mn.MetricGroup = []byte(fmt.Sprintf("%s_%d", prefix, i))
metricNameRaw := mn.marshalRaw(nil)
timestamp := rng.Int63n(tr.MaxTimestamp-tr.MinTimestamp) + tr.MinTimestamp
@@ -1570,7 +1570,7 @@ func testStorageAddRows(rng *rand.Rand, s *Storage) error {
maxTimestamp := timestampFromTime(time.Now())
minTimestamp := maxTimestamp - s.retentionMsecs + 3600*1000
for i := 0; i < addsCount; i++ {
for range addsCount {
mrs := testGenerateMetricRows(rng, rowsPerAdd, minTimestamp, maxTimestamp)
s.AddRows(mrs, defaultPrecisionBits)
}
@@ -1766,7 +1766,7 @@ func TestStorageDeleteStaleSnapshots(t *testing.T) {
const addsCount = 10
maxTimestamp := timestampFromTime(time.Now())
minTimestamp := maxTimestamp - s.retentionMsecs
for i := 0; i < addsCount; i++ {
for range addsCount {
mrs := testGenerateMetricRows(rng, rowsPerAdd, minTimestamp, maxTimestamp)
s.AddRows(mrs, defaultPrecisionBits)
}
@@ -2947,7 +2947,7 @@ func TestStorageGetTSDBStatusWithoutPerDayIndex(t *testing.T) {
MinTimestamp: time.Date(2024, 1, day, 0, 0, 0, 0, time.UTC).UnixMilli(),
MaxTimestamp: time.Date(2024, 1, day, 23, 59, 59, 999, time.UTC).UnixMilli(),
}
for row := 0; row < rows; row++ {
for row := range rows {
name := fmt.Sprintf("metric_%d", rows*day+row)
mn := &MetricName{
MetricGroup: []byte(name),
@@ -2997,7 +2997,7 @@ func TestStorageSearchMetricNamesWithoutPerDayIndex(t *testing.T) {
MaxTimestamp: time.Date(2024, 1, day, 23, 59, 59, 999, time.UTC).UnixMilli(),
}
var want []string
for row := 0; row < rows; row++ {
for row := range rows {
name := fmt.Sprintf("metric_%d", rows*day+row)
mn := &MetricName{
MetricGroup: []byte(name),
@@ -3058,7 +3058,7 @@ func TestStorageSearchLabelNamesWithoutPerDayIndex(t *testing.T) {
MaxTimestamp: time.Date(2024, 1, day, 23, 59, 59, 999, time.UTC).UnixMilli(),
}
var want []string
for row := 0; row < rows; row++ {
for row := range rows {
labelName := fmt.Sprintf("job_%d", rows*day+row)
mn := &MetricName{
MetricGroup: []byte("metric"),
@@ -3113,7 +3113,7 @@ func TestStorageSearchLabelValuesWithoutPerDayIndex(t *testing.T) {
MaxTimestamp: time.Date(2024, 1, day, 23, 59, 59, 999, time.UTC).UnixMilli(),
}
var want []string
for row := 0; row < rows; row++ {
for row := range rows {
labelValue := fmt.Sprintf("webservice_%d", rows*day+row)
mn := &MetricName{
MetricGroup: []byte("metric"),
@@ -3166,7 +3166,7 @@ func TestStorageSearchTagValueSuffixesWithoutPerDayIndex(t *testing.T) {
MinTimestamp: time.Date(2024, 1, day, 0, 0, 0, 0, time.UTC).UnixMilli(),
MaxTimestamp: time.Date(2024, 1, day, 23, 59, 59, 999, time.UTC).UnixMilli(),
}
for row := 0; row < rows; row++ {
for row := range rows {
metricName := fmt.Sprintf("%sday%d.row%d", tagValuePrefix, day, row)
mn := &MetricName{
MetricGroup: []byte(metricName),
@@ -3216,7 +3216,7 @@ func TestStorageSearchGraphitePathsWithoutPerDayIndex(t *testing.T) {
MaxTimestamp: time.Date(2024, 1, day, 23, 59, 59, 999, time.UTC).UnixMilli(),
}
want := make([]string, rows)
for row := 0; row < rows; row++ {
for row := range rows {
metricName := fmt.Sprintf("day%d.row%d", day, row)
mn := &MetricName{
MetricGroup: []byte(metricName),
@@ -3266,7 +3266,7 @@ func TestStorageQueryWithoutPerDayIndex(t *testing.T) {
MaxTimestamp: time.Date(2024, 1, day, 23, 59, 59, 999, time.UTC).UnixMilli(),
}
var want []MetricRow
for row := 0; row < rows; row++ {
for row := range rows {
seqNumber := rows*day + row
name := fmt.Sprintf("metric_%d", seqNumber)
mn := &MetricName{

View File

@@ -40,7 +40,7 @@ func BenchmarkStorageAddRows(b *testing.B) {
}
for pb.Next() {
offset := int(globalOffset.Add(uint64(numRows)))
for i := 0; i < numRows; i++ {
for i := range numRows {
mr := &mrs[i]
mr.MetricNameRaw = mn.marshalRaw(mr.MetricNameRaw[:0])
mr.Timestamp = int64(offset + i)

View File

@@ -128,7 +128,7 @@ func testTableSearchEx(t *testing.T, rng *rand.Rand, trData, trSearch TimeRange,
// Generate tsids to search.
var tsids []TSID
var tsid TSID
for i := 0; i < 25; i++ {
for range 25 {
tsid.MetricID = uint64(rng.Intn(tsidsCount * 2))
tsids = append(tsids, tsid)
}
@@ -144,13 +144,13 @@ func testTableSearchEx(t *testing.T, rng *rand.Rand, trData, trSearch TimeRange,
var ptr TimeRange
ptr.fromPartitionTimestamp(trData.MinTimestamp)
var rowss [][]rawRow
for i := 0; i < partitionsCount; i++ {
for range partitionsCount {
partsCount := rng.Intn(maxPartsPerPartition) + 1
for j := 0; j < partsCount; j++ {
for range partsCount {
var rows []rawRow
timestamp := ptr.MinTimestamp
rowsCount := rng.Intn(maxRowsPerPart) + 1
for k := 0; k < rowsCount; k++ {
for range rowsCount {
r.TSID.MetricID = uint64(rng.Intn(tsidsCount))
r.Timestamp = timestamp
r.Value = float64(int(rng.NormFloat64() * 1e5))
@@ -211,12 +211,12 @@ func testTableSearch(t *testing.T, tb *table, tsids []TSID, tr TimeRange, rbsExp
}
ch := make(chan error, 5)
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
go func() {
ch <- testTableSearchSerial(tb, tsids, tr, rbsExpected, rowsCountExpected)
}()
}
for i := 0; i < cap(ch); i++ {
for range cap(ch) {
select {
case err := <-ch:
if err != nil {

View File

@@ -81,7 +81,7 @@ func createBenchTable(b *testing.B, path string, startTimestamp int64, rowsPerIn
rows := make([]rawRow, rowsPerInsert)
value := float64(100)
for insertsCount.Add(-1) >= 0 {
for j := 0; j < rowsPerInsert; j++ {
for j := range rowsPerInsert {
ts := timestamp.Add(uint64(10 + rng.Int63n(2)))
value += float64(int(rng.NormFloat64() * 5))

View File

@@ -24,7 +24,7 @@ func TestTableOpenClose(t *testing.T) {
tb.MustClose()
// Re-open created table multiple times.
for i := 0; i < 10; i++ {
for range 10 {
tb := mustOpenTable(path, strg)
tb.MustClose()
}

View File

@@ -28,7 +28,7 @@ func benchmarkTableAddRows(b *testing.B, rowsPerInsert, tsidsCount int) {
timestamp := startTimestamp
value := float64(100)
rng := rand.New(rand.NewSource(1))
for i := 0; i < rowsPerInsert; i++ {
for i := range rowsPerInsert {
r := &rows[i]
r.PrecisionBits = defaultPrecisionBits
r.TSID.MetricID = uint64(rng.Intn(tsidsCount) + 1)
@@ -47,11 +47,11 @@ func benchmarkTableAddRows(b *testing.B, rowsPerInsert, tsidsCount int) {
b.SetBytes(int64(rowsCountExpected))
tablePath := "benchmarkTableAddRows"
strg := newTestStorage()
for i := 0; i < b.N; i++ {
for range b.N {
tb := mustOpenTable(tablePath, strg)
workCh := make(chan struct{}, insertsCount)
for j := 0; j < insertsCount; j++ {
for range insertsCount {
workCh <- struct{}{}
}
close(workCh)
@@ -59,7 +59,7 @@ func benchmarkTableAddRows(b *testing.B, rowsPerInsert, tsidsCount int) {
doneCh := make(chan struct{})
gomaxprocs := cgroup.AvailableCPUs()
for j := 0; j < gomaxprocs; j++ {
for j := range gomaxprocs {
go func(goroutineID int) {
// Make per-goroutine rows copy with distinct timestamps.
rowsCopy := append([]rawRow{}, rows...)
@@ -84,7 +84,7 @@ func benchmarkTableAddRows(b *testing.B, rowsPerInsert, tsidsCount int) {
}(j)
}
for j := 0; j < gomaxprocs; j++ {
for range gomaxprocs {
<-doneCh
}

View File

@@ -678,7 +678,7 @@ func TestGetCommonPrefix(t *testing.T) {
func TestGetRegexpFromCache(t *testing.T) {
f := func(s string, orValuesExpected, expectedMatches, expectedMismatches []string, suffixExpected string) {
t.Helper()
for i := 0; i < 3; i++ {
for range 3 {
rcv, err := getRegexpFromCache(s)
if err != nil {
t.Fatalf("unexpected error for s=%q: %s", s, err)

View File

@@ -7,7 +7,7 @@ import (
)
func TestTimeRangeFromPartition(t *testing.T) {
for i := 0; i < 24*30*365; i++ {
for i := range 24 * 30 * 365 {
testTimeRangeFromPartition(t, time.Now().Add(time.Hour*time.Duration(i)))
}
}

View File

@@ -82,7 +82,7 @@ func TestTSIDMarshalUnmarshal(t *testing.T) {
var tsid TSID
testTSIDMarshalUnmarshal(t, &tsid)
for i := 0; i < 1000; i++ {
for range 1000 {
initTestTSID(&tsid)
testTSIDMarshalUnmarshal(t, &tsid)