[lxc-devel] [lxd/master] Increase database timeout when creating indexes in db update 12
freeekanayaka on Github
lxc-bot at linuxcontainers.org
Mon Oct 15 09:30:52 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 446 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181015/d6863374/attachment.bin>
-------------- next part --------------
From 6137252f6012e54a5128389e2ba9f1d76f3fbc68 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Mon, 15 Oct 2018 11:27:46 +0200
Subject: [PATCH] Increase database timeout when creating indexes in db update
12
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/cluster/update.go | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lxd/db/cluster/update.go b/lxd/db/cluster/update.go
index 288ef99f5b..91101840a3 100644
--- a/lxd/db/cluster/update.go
+++ b/lxd/db/cluster/update.go
@@ -1,8 +1,10 @@
package cluster
import (
+ "context"
"database/sql"
"fmt"
+ "time"
"github.com/lxc/lxd/lxd/db/query"
"github.com/lxc/lxd/lxd/db/schema"
@@ -78,6 +80,11 @@ func updateFromV11(tx *sql.Tx) error {
return errors.Wrap(err, "Failed to count rows in current tables")
}
+ // Use a large timeout since the update might take a while, due to the
+ // new indexes being created.
+ ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
+ defer cancel()
+
stmts := fmt.Sprintf(`
CREATE TABLE projects (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
@@ -390,7 +397,7 @@ CREATE INDEX images_project_id_idx ON images (project_id);
CREATE INDEX images_aliases_project_id_idx ON images_aliases (project_id);
CREATE INDEX profiles_project_id_idx ON profiles (project_id);
`)
- _, err = tx.Exec(stmts)
+ _, err = tx.ExecContext(ctx, stmts)
if err != nil {
return errors.Wrap(err, "Failed to add project_id column")
}
More information about the lxc-devel
mailing list