mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01: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
@ -1479,7 +1479,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
|
||||
|
@ -692,8 +692,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
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()
|
||||
|
@ -1094,7 +1094,7 @@ func TestStorageRotateIndexDB(t *testing.T) {
|
||||
return
|
||||
default:
|
||||
time.Sleep(time.Millisecond)
|
||||
s.mustRotateIndexDB()
|
||||
s.mustRotateIndexDB(time.Now())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user