[lxc-devel] [lxd/master] lxd/cluster: Fix schema upgrades

stgraber on Github lxc-bot at linuxcontainers.org
Sat Dec 22 20:07:43 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 997 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181222/19fd82bb/attachment.bin>
-------------- next part --------------
From f1878ca74be8fb3e763ad390c3e3c3e4fe295812 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sat, 22 Dec 2018 15:03:57 -0500
Subject: [PATCH] lxd/cluster: Fix schema upgrades
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

While working on LXD 3.0 deb to LXD 3.8 snap upgrades, I ran into an
issue where loading the prepared statements was erroring out, causing
the daemon to exit.

That happens when the first node upgrades as the rest of the cluster is
still on the older schema version, causing the schema upgrade code to be
skipped. The prepared statements were then loaded regardless, causing
the crash when preparing them.

Instead, as soon as we know that the DB hasn't been upgraded, return and
let the retry logic happen. Once the remaining nodes have upgraded, the
schema update will happen and the prepared statements will be
re-processed.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/db/db.go | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lxd/db/db.go b/lxd/db/db.go
index b5718e8349..2a19ec6f24 100644
--- a/lxd/db/db.go
+++ b/lxd/db/db.go
@@ -213,6 +213,15 @@ func OpenCluster(name string, store dqlite.ServerStore, address, dir string, tim
 	db.SetMaxOpenConns(1)
 	db.SetMaxIdleConns(1)
 
+	if !nodesVersionsMatch {
+		cluster := &Cluster{
+			db:    db,
+			stmts: map[int]*sql.Stmt{},
+		}
+
+		return cluster, ErrSomeNodesAreBehind
+	}
+
 	stmts, err := cluster.PrepareStmts(db)
 	if err != nil {
 		return nil, errors.Wrap(err, "Failed to prepare statements")
@@ -246,10 +255,6 @@ func OpenCluster(name string, store dqlite.ServerStore, address, dir string, tim
 		return nil, err
 	}
 
-	if !nodesVersionsMatch {
-		err = ErrSomeNodesAreBehind
-	}
-
 	return cluster, err
 }
 


More information about the lxc-devel mailing list