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
dfe4816e8c
commit
89ccf19b70
3 changed files with 7 additions and 6 deletions
|
@ -1585,7 +1585,7 @@ func TestIndexDBRepopulateAfterRotation(t *testing.T) {
|
|||
prevGeneration := db.generation
|
||||
|
||||
// force index rotation
|
||||
s.mustRotateIndexDB()
|
||||
s.mustRotateIndexDB(time.Now())
|
||||
|
||||
// check tsidCache wasn't reset after the rotation
|
||||
var cs2 fastcache.Stats
|
||||
|
|
|
@ -707,8 +707,8 @@ func (s *Storage) retentionWatcher() {
|
|||
select {
|
||||
case <-s.stop:
|
||||
return
|
||||
case <-time.After(time.Second * time.Duration(d)):
|
||||
s.mustRotateIndexDB()
|
||||
case currentTime := <-time.After(time.Second * time.Duration(d)):
|
||||
s.mustRotateIndexDB(currentTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -765,14 +765,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
|
||||
newTableName := nextIndexDBTableName()
|
||||
idbNewPath := filepath.Join(s.path, indexdbDirname, newTableName)
|
||||
idbNew := mustOpenIndexDB(idbNewPath, s, &s.isReadOnly)
|
||||
|
||||
// Update nextRotationTimestamp
|
||||
atomic.AddInt64(&s.nextRotationTimestamp, s.retentionMsecs/1000)
|
||||
nextRotationTimestamp := currentTime.UnixMilli() + s.retentionMsecs/1000
|
||||
atomic.StoreInt64(&s.nextRotationTimestamp, nextRotationTimestamp)
|
||||
|
||||
// Set idbNext to idbNew
|
||||
idbNext := s.idbNext.Load()
|
||||
|
|
|
@ -1238,7 +1238,7 @@ func TestStorageRotateIndexDB(t *testing.T) {
|
|||
return
|
||||
default:
|
||||
time.Sleep(time.Millisecond)
|
||||
s.mustRotateIndexDB()
|
||||
s.mustRotateIndexDB(time.Now())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in a new issue