mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: fix possible test failure in TestStorageAddRowsConcurrent
The number of parts in the snapshot partition may be zero if concurrent goroutine just started creating new partition, but didn't put data into it yet when the current goroutine made a snapshot.
This commit is contained in:
parent
4ba19f6b32
commit
3b50b94f7a
1 changed files with 6 additions and 4 deletions
|
@ -988,7 +988,7 @@ func testStorageAddRows(rng *rand.Rand, s *Storage) error {
|
||||||
const addsCount = 10
|
const addsCount = 10
|
||||||
|
|
||||||
maxTimestamp := timestampFromTime(time.Now())
|
maxTimestamp := timestampFromTime(time.Now())
|
||||||
minTimestamp := maxTimestamp - s.retentionMsecs
|
minTimestamp := maxTimestamp - s.retentionMsecs + 3600*1000
|
||||||
for i := 0; i < addsCount; i++ {
|
for i := 0; i < addsCount; i++ {
|
||||||
mrs := testGenerateMetricRows(rng, rowsPerAdd, minTimestamp, maxTimestamp)
|
mrs := testGenerateMetricRows(rng, rowsPerAdd, minTimestamp, maxTimestamp)
|
||||||
if err := s.AddRows(mrs, defaultPrecisionBits); err != nil {
|
if err := s.AddRows(mrs, defaultPrecisionBits); err != nil {
|
||||||
|
@ -1030,7 +1030,9 @@ func testStorageAddRows(rng *rand.Rand, s *Storage) error {
|
||||||
return fmt.Errorf("snapshot %q must contain at least %d rows; got %d", snapshotPath, minRowsExpected, rowsCount)
|
return fmt.Errorf("snapshot %q must contain at least %d rows; got %d", snapshotPath, minRowsExpected, rowsCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that force merge for the snapshot leaves only a single part per partition.
|
// Verify that force merge for the snapshot leaves at most a single part per partition.
|
||||||
|
// Zero parts are possible if the snapshot is created just after the partition has been created
|
||||||
|
// by concurrent goroutine, but it didn't put the data into it yet.
|
||||||
if err := s1.ForceMergePartitions(""); err != nil {
|
if err := s1.ForceMergePartitions(""); err != nil {
|
||||||
return fmt.Errorf("error when force merging partitions: %w", err)
|
return fmt.Errorf("error when force merging partitions: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -1039,9 +1041,9 @@ func testStorageAddRows(rng *rand.Rand, s *Storage) error {
|
||||||
pws := ptw.pt.GetParts(nil, true)
|
pws := ptw.pt.GetParts(nil, true)
|
||||||
numParts := len(pws)
|
numParts := len(pws)
|
||||||
ptw.pt.PutParts(pws)
|
ptw.pt.PutParts(pws)
|
||||||
if numParts != 1 {
|
if numParts > 1 {
|
||||||
s1.tb.PutPartitions(ptws)
|
s1.tb.PutPartitions(ptws)
|
||||||
return fmt.Errorf("unexpected number of parts for partition %q after force merge; got %d; want 1", ptw.pt.name, numParts)
|
return fmt.Errorf("unexpected number of parts for partition %q after force merge; got %d; want at most 1", ptw.pt.name, numParts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s1.tb.PutPartitions(ptws)
|
s1.tb.PutPartitions(ptws)
|
||||||
|
|
Loading…
Reference in a new issue