The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7829

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===

From 024e87531934c3125f5a28eaa1d1cf5390debc09 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Mon, 31 Aug 2020 13:35:45 +0200
Subject: [PATCH] lxd/db/cluster: Fix incorrect storage volume node IDs

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 lxd/db/cluster/schema.go |  2 +-
 lxd/db/cluster/update.go | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/lxd/db/cluster/schema.go b/lxd/db/cluster/schema.go
index 688575a342..de1981674d 100644
--- a/lxd/db/cluster/schema.go
+++ b/lxd/db/cluster/schema.go
@@ -573,5 +573,5 @@ CREATE TABLE storage_volumes_snapshots_config (
     UNIQUE (storage_volume_snapshot_id, key)
 );
 
-INSERT INTO schema (version, updated_at) VALUES (35, strftime("%s"))
+INSERT INTO schema (version, updated_at) VALUES (36, strftime("%s"))
 `
diff --git a/lxd/db/cluster/update.go b/lxd/db/cluster/update.go
index cf7bf3f008..b6bce4a2dc 100644
--- a/lxd/db/cluster/update.go
+++ b/lxd/db/cluster/update.go
@@ -72,6 +72,34 @@ var updates = map[int]schema.Update{
        33: updateFromV32,
        34: updateFromV33,
        35: updateFromV34,
+       36: updateFromV35,
+}
+
+// This fixes node IDs of storage volumes on non-remote pools which were
+// wrongly set to NULL.
+func updateFromV35(tx *sql.Tx) error {
+       stmts := `
+WITH storage_volumes_tmp (id, node_id)
+AS (
+  SELECT storage_volumes.id, storage_pools_nodes.node_id
+  FROM storage_volumes
+       JOIN storage_pools_nodes ON 
storage_pools_nodes.storage_pool_id=storage_volumes.storage_pool_id
+       JOIN storage_pools ON storage_pools.id=storage_volumes.storage_pool_id
+  WHERE storage_pools.driver NOT IN ("ceph", "cephfs"))
+UPDATE storage_volumes
+SET node_id=(
+  SELECT storage_volumes_tmp.node_id
+  FROM storage_volumes_tmp
+  WHERE storage_volumes.id=storage_volumes_tmp.id)
+WHERE id IN (SELECT id FROM storage_volumes_tmp) AND node_id IS NULL
+`
+
+       _, err := tx.Exec(stmts)
+       if err != nil {
+               return err
+       }
+
+       return nil
 }
 
 // Remove multiple entries of the same volume when using remote storage.
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to