lib/storage: Remove the effect of time zone on next retention period (#2568) (#2574)

This commit is contained in:
阳明 2022-05-25 20:08:24 +08:00 committed by Aliaksandr Valialkin
parent 05e47482a5
commit e4df648ea0
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -1101,12 +1101,16 @@ var saveCacheLock sync.Mutex
func nextRetentionDuration(retentionMsecs int64) time.Duration {
// Round retentionMsecs to days. This guarantees that per-day inverted index works as expected.
retentionMsecs = ((retentionMsecs + msecPerDay - 1) / msecPerDay) * msecPerDay
t := time.Now().UnixNano() / 1e6
now := time.Now()
t := now.UnixNano() / 1e6
deadline := ((t + retentionMsecs - 1) / retentionMsecs) * retentionMsecs
// Schedule the deadline to +4 hours from the next retention period start.
// This should prevent from possible double deletion of indexdb
// due to time drift - see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/248 .
deadline += 4 * 3600 * 1000
// The effect of time zone on retention period is moved out
_, offset := now.Zone()
deadline -= int64(offset) * 1000
return time.Duration(deadline-t) * time.Millisecond
}