mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: protect from time drift during indexdb rotation
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/248
This commit is contained in:
parent
cf85c567d1
commit
5a62415bec
2 changed files with 6 additions and 4 deletions
|
@ -655,7 +655,10 @@ func nextRetentionDuration(retentionMonths int) time.Duration {
|
|||
n -= n % retentionMonths
|
||||
y := n / 12
|
||||
m := time.Month((n % 12) + 1)
|
||||
deadline := time.Date(y, m, 1, 0, 0, 0, 0, time.UTC)
|
||||
// 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 := time.Date(y, m, 1, 4, 0, 0, 0, time.UTC)
|
||||
return deadline.Sub(t)
|
||||
}
|
||||
|
||||
|
|
|
@ -342,10 +342,9 @@ func TestMetricRowMarshalUnmarshal(t *testing.T) {
|
|||
|
||||
func TestNextRetentionDuration(t *testing.T) {
|
||||
for retentionMonths := 1; retentionMonths < 360; retentionMonths++ {
|
||||
currTime := time.Now().UTC()
|
||||
|
||||
d := nextRetentionDuration(retentionMonths)
|
||||
if d < 0 {
|
||||
if d <= 0 {
|
||||
currTime := time.Now().UTC()
|
||||
nextTime := time.Now().UTC().Add(d)
|
||||
t.Fatalf("unexected retention duration for retentionMonths=%d; got %s; must be %s + %d months", retentionMonths, nextTime, currTime, retentionMonths)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue