[lxc-devel] [lxd/master] lxc/container: Fixes minute rollover issue in scheduled snapshots

tomponline on Github lxc-bot at linuxcontainers.org
Fri May 17 08:25:32 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 376 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190517/f24ac2a1/attachment.bin>
-------------- next part --------------
From 71fe696be005e2e96363f46129ace145d60a7911 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 17 May 2019 09:24:21 +0100
Subject: [PATCH] lxc/container: Fixes minute rollover issue in scheduled
 snapshots

Fixes #5761

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/container.go | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lxd/container.go b/lxd/container.go
index 7295d06917..e935dde899 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -1635,10 +1635,18 @@ func autoCreateContainerSnapshotsTask(d *Daemon) (task.Func, task.Schedule) {
 
 			// Check if it's time to snapshot
 			now := time.Now()
+
+			// Truncate the time now back to the start of the minute, before passing to
+			// the cron scheduler, as it will add 1s to the scheduled time and we don't
+			// want the next scheduled time to roll over to the next minute and break
+			// the time comparison below.
+			now = now.Truncate(time.Minute)
+
+			// Calculate the next scheduled time based on the snapshots.schedule
+			// pattern and the time now.
 			next := sched.Next(now)
 
 			// Ignore everything that is more precise than minutes.
-			now = now.Truncate(time.Minute)
 			next = next.Truncate(time.Minute)
 
 			if !now.Equal(next) {


More information about the lxc-devel mailing list