mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: update nextRotationTimestamp relative to the timestamp of the indexdb rotation
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1401 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4563
This commit is contained in:
parent
c25f053945
commit
9082a84566
3 changed files with 7 additions and 6 deletions
|
@ -1479,7 +1479,7 @@ func TestIndexDBRepopulateAfterRotation(t *testing.T) {
|
||||||
prevGeneration := db.generation
|
prevGeneration := db.generation
|
||||||
|
|
||||||
// force index rotation
|
// force index rotation
|
||||||
s.mustRotateIndexDB()
|
s.mustRotateIndexDB(time.Now())
|
||||||
|
|
||||||
// check tsidCache wasn't reset after the rotation
|
// check tsidCache wasn't reset after the rotation
|
||||||
var cs2 fastcache.Stats
|
var cs2 fastcache.Stats
|
||||||
|
|
|
@ -692,8 +692,8 @@ func (s *Storage) retentionWatcher() {
|
||||||
select {
|
select {
|
||||||
case <-s.stop:
|
case <-s.stop:
|
||||||
return
|
return
|
||||||
case <-time.After(time.Second * time.Duration(d)):
|
case currentTime := <-time.After(time.Second * time.Duration(d)):
|
||||||
s.mustRotateIndexDB()
|
s.mustRotateIndexDB(currentTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -750,14 +750,15 @@ func (s *Storage) nextDayMetricIDsUpdater() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) mustRotateIndexDB() {
|
func (s *Storage) mustRotateIndexDB(currentTime time.Time) {
|
||||||
// Create new indexdb table, which will be used as idbNext
|
// Create new indexdb table, which will be used as idbNext
|
||||||
newTableName := nextIndexDBTableName()
|
newTableName := nextIndexDBTableName()
|
||||||
idbNewPath := filepath.Join(s.path, indexdbDirname, newTableName)
|
idbNewPath := filepath.Join(s.path, indexdbDirname, newTableName)
|
||||||
idbNew := mustOpenIndexDB(idbNewPath, s, &s.isReadOnly)
|
idbNew := mustOpenIndexDB(idbNewPath, s, &s.isReadOnly)
|
||||||
|
|
||||||
// Update nextRotationTimestamp
|
// Update nextRotationTimestamp
|
||||||
atomic.AddInt64(&s.nextRotationTimestamp, s.retentionMsecs/1000)
|
nextRotationTimestamp := currentTime.UnixMilli() + s.retentionMsecs/1000
|
||||||
|
atomic.StoreInt64(&s.nextRotationTimestamp, nextRotationTimestamp)
|
||||||
|
|
||||||
// Set idbNext to idbNew
|
// Set idbNext to idbNew
|
||||||
idbNext := s.idbNext.Load()
|
idbNext := s.idbNext.Load()
|
||||||
|
|
|
@ -1094,7 +1094,7 @@ func TestStorageRotateIndexDB(t *testing.T) {
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
s.mustRotateIndexDB()
|
s.mustRotateIndexDB(time.Now())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue