mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: fix TestUpdateCurrHourMetricIDs test when it runs on the first hour of the day by UTC
This commit is contained in:
parent
1d6068821e
commit
800be3d7d3
2 changed files with 60 additions and 10 deletions
|
@ -2362,7 +2362,7 @@ func (s *Storage) updateNextDayMetricIDs(date uint64) {
|
|||
if e.date == date {
|
||||
pendingMetricIDs.Union(&e.v)
|
||||
} else {
|
||||
// Do not add pendingMetricIDs from the previous day to the cyrrent day,
|
||||
// Do not add pendingMetricIDs from the previous day to the current day,
|
||||
// since this may result in missing registration of the metricIDs in the per-day inverted index.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3309
|
||||
pendingMetricIDs = &uint64set.Set{}
|
||||
|
@ -2390,14 +2390,15 @@ func (s *Storage) updateCurrHourMetricIDs(hour uint64) {
|
|||
var m *uint64set.Set
|
||||
if hm.hour == hour {
|
||||
m = hm.m.Clone()
|
||||
} else {
|
||||
m = &uint64set.Set{}
|
||||
}
|
||||
if hour%24 != 0 {
|
||||
// Do not add pending metricIDs from the previous hour to the current hour on the next day,
|
||||
// since this may result in missing registration of the metricIDs in the per-day inverted index.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3309
|
||||
m.Union(newMetricIDs)
|
||||
} else {
|
||||
m = newMetricIDs
|
||||
if hour%24 == 0 {
|
||||
// Do not add pending metricIDs from the previous hour to the current hour on the next day,
|
||||
// since this may result in missing registration of the metricIDs in the per-day inverted index.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3309
|
||||
m = &uint64set.Set{}
|
||||
}
|
||||
}
|
||||
hmNew := &hourMetricIDs{
|
||||
m: m,
|
||||
|
|
|
@ -157,9 +157,12 @@ func TestUpdateCurrHourMetricIDs(t *testing.T) {
|
|||
t.Run("empty_pending_metric_ids_stale_curr_hour", func(t *testing.T) {
|
||||
s := newStorage()
|
||||
hour := fasttime.UnixHour()
|
||||
if hour%24 == 0 {
|
||||
hour++
|
||||
}
|
||||
hmOrig := &hourMetricIDs{
|
||||
m: &uint64set.Set{},
|
||||
hour: 123,
|
||||
hour: hour - 1,
|
||||
}
|
||||
hmOrig.m.Add(12)
|
||||
hmOrig.m.Add(34)
|
||||
|
@ -230,9 +233,12 @@ func TestUpdateCurrHourMetricIDs(t *testing.T) {
|
|||
s.pendingHourEntries = pendingHourEntries
|
||||
|
||||
hour := fasttime.UnixHour()
|
||||
if hour%24 == 0 {
|
||||
hour++
|
||||
}
|
||||
hmOrig := &hourMetricIDs{
|
||||
m: &uint64set.Set{},
|
||||
hour: 123,
|
||||
hour: hour - 1,
|
||||
}
|
||||
hmOrig.m.Add(12)
|
||||
hmOrig.m.Add(34)
|
||||
|
@ -307,6 +313,49 @@ func TestUpdateCurrHourMetricIDs(t *testing.T) {
|
|||
t.Fatalf("unexpected s.pendingHourEntries.Len(); got %d; want %d", s.pendingHourEntries.Len(), 0)
|
||||
}
|
||||
})
|
||||
t.Run("nonempty_pending_metric_ids_valid_curr_hour_start_of_day", func(t *testing.T) {
|
||||
s := newStorage()
|
||||
pendingHourEntries := &uint64set.Set{}
|
||||
pendingHourEntries.Add(343)
|
||||
pendingHourEntries.Add(32424)
|
||||
pendingHourEntries.Add(8293432)
|
||||
s.pendingHourEntries = pendingHourEntries
|
||||
|
||||
hour := fasttime.UnixHour()
|
||||
hour -= hour % 24
|
||||
hmOrig := &hourMetricIDs{
|
||||
m: &uint64set.Set{},
|
||||
hour: hour,
|
||||
}
|
||||
hmOrig.m.Add(12)
|
||||
hmOrig.m.Add(34)
|
||||
s.currHourMetricIDs.Store(hmOrig)
|
||||
s.updateCurrHourMetricIDs(hour)
|
||||
hmCurr := s.currHourMetricIDs.Load().(*hourMetricIDs)
|
||||
if hmCurr.hour != hour {
|
||||
t.Fatalf("unexpected hmCurr.hour; got %d; want %d", hmCurr.hour, hour)
|
||||
}
|
||||
m := pendingHourEntries.Clone()
|
||||
hmOrig.m.ForEach(func(part []uint64) bool {
|
||||
for _, metricID := range part {
|
||||
m.Add(metricID)
|
||||
}
|
||||
return true
|
||||
})
|
||||
if !hmCurr.m.Equal(m) {
|
||||
t.Fatalf("unexpected hm.m; got %v; want %v", hmCurr.m, m)
|
||||
}
|
||||
|
||||
hmPrev := s.prevHourMetricIDs.Load().(*hourMetricIDs)
|
||||
hmEmpty := &hourMetricIDs{}
|
||||
if !reflect.DeepEqual(hmPrev, hmEmpty) {
|
||||
t.Fatalf("unexpected hmPrev; got %v; want %v", hmPrev, hmEmpty)
|
||||
}
|
||||
|
||||
if s.pendingHourEntries.Len() != 0 {
|
||||
t.Fatalf("unexpected s.pendingHourEntries.Len(); got %d; want %d", s.pendingHourEntries.Len(), 0)
|
||||
}
|
||||
})
|
||||
t.Run("nonempty_pending_metric_ids_from_previous_hour_new_day", func(t *testing.T) {
|
||||
s := newStorage()
|
||||
|
||||
|
|
Loading…
Reference in a new issue