[lxc-devel] [lxd/master] lxd/db: Fix multi-arch cached images

stgraber on Github lxc-bot at linuxcontainers.org
Wed Jan 15 04:57:30 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200114/6ec75c4a/attachment.bin>
-------------- next part --------------
From d77f8852f641cde03cc91bf65f94d525fb36ac13 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 14 Jan 2020 23:56:40 -0500
Subject: [PATCH] lxd/db: Fix multi-arch cached images
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/daemon_images.go       | 9 ++++++---
 lxd/db/db_internal_test.go | 4 ++--
 lxd/db/images.go           | 8 ++++----
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/lxd/daemon_images.go b/lxd/daemon_images.go
index 4609621d77..4441a65dd5 100644
--- a/lxd/daemon_images.go
+++ b/lxd/daemon_images.go
@@ -97,9 +97,12 @@ func (d *Daemon) ImageDownload(op *operations.Operation, server string, protocol
 		return nil, err
 	}
 	if preferCached && interval > 0 && alias != fp {
-		cachedFingerprint, err := d.cluster.ImageSourceGetCachedFingerprint(server, protocol, alias, imageType)
-		if err == nil && cachedFingerprint != fp {
-			fp = cachedFingerprint
+		for _, architecture := range d.os.Architectures {
+			cachedFingerprint, err := d.cluster.ImageSourceGetCachedFingerprint(server, protocol, alias, imageType, architecture)
+			if err == nil && cachedFingerprint != fp {
+				fp = cachedFingerprint
+				break
+			}
 		}
 	}
 
diff --git a/lxd/db/db_internal_test.go b/lxd/db/db_internal_test.go
index 6b411081f9..13c28f7069 100644
--- a/lxd/db/db_internal_test.go
+++ b/lxd/db/db_internal_test.go
@@ -254,7 +254,7 @@ func (s *dbTestSuite) Test_ImageSourceGetCachedFingerprint() {
 	err = s.db.ImageSourceInsert(imageID, "server.remote", "simplestreams", "", "test")
 	s.Nil(err)
 
-	fingerprint, err := s.db.ImageSourceGetCachedFingerprint("server.remote", "simplestreams", "test", "container")
+	fingerprint, err := s.db.ImageSourceGetCachedFingerprint("server.remote", "simplestreams", "test", "container", 0)
 	s.Nil(err)
 	s.Equal(fingerprint, "fingerprint")
 }
@@ -266,7 +266,7 @@ func (s *dbTestSuite) Test_ImageSourceGetCachedFingerprint_no_match() {
 	err = s.db.ImageSourceInsert(imageID, "server.remote", "simplestreams", "", "test")
 	s.Nil(err)
 
-	_, err = s.db.ImageSourceGetCachedFingerprint("server.remote", "lxd", "test", "container")
+	_, err = s.db.ImageSourceGetCachedFingerprint("server.remote", "lxd", "test", "container", 0)
 	s.Equal(err, ErrNoSuchObject)
 }
 
diff --git a/lxd/db/images.go b/lxd/db/images.go
index 4fd1fbfc26..d8916d14f6 100644
--- a/lxd/db/images.go
+++ b/lxd/db/images.go
@@ -182,7 +182,7 @@ func (c *Cluster) ImageSourceGet(imageID int) (int, api.ImageSource, error) {
 // ImageSourceGetCachedFingerprint tries to find a source entry of a locally
 // cached image that matches the given remote details (server, protocol and
 // alias). Return the fingerprint linked to the matching entry, if any.
-func (c *Cluster) ImageSourceGetCachedFingerprint(server string, protocol string, alias string, typeName string) (string, error) {
+func (c *Cluster) ImageSourceGetCachedFingerprint(server string, protocol string, alias string, typeName string, architecture int) (string, error) {
 	imageType := instancetype.Any
 	if typeName != "" {
 		var err error
@@ -207,13 +207,13 @@ func (c *Cluster) ImageSourceGetCachedFingerprint(server string, protocol string
 			FROM images_source
 			INNER JOIN images
 			ON images_source.image_id=images.id
-			WHERE server=? AND protocol=? AND alias=? AND auto_update=1
+			WHERE server=? AND protocol=? AND alias=? AND auto_update=1 AND images.architecture=?
 `
 
-	arg1 := []interface{}{server, protocolInt, alias}
+	arg1 := []interface{}{server, protocolInt, alias, architecture}
 	if imageType != instancetype.Any {
 		q += "AND images.type=?\n"
-		arg1 = []interface{}{server, protocolInt, alias, imageType}
+		arg1 = []interface{}{server, protocolInt, alias, architecture, imageType}
 	}
 
 	q += "ORDER BY creation_date DESC"


More information about the lxc-devel mailing list