[lxc-devel] [lxd/master] lxd: New command line option to trace SQL statements

freeekanayaka on Github lxc-bot at linuxcontainers.org
Thu May 28 08:26:36 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 420 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200528/43f9a9df/attachment.bin>
-------------- next part --------------
From c91e018f4f873993b02b69ed03a3bcb57ff65976 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Wed, 27 May 2020 13:20:11 +0100
Subject: [PATCH] lxd: New command line option to trace SQL statements

This can be enabled with "lxd --debug --trace database"

Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
 lxd/daemon.go | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lxd/daemon.go b/lxd/daemon.go
index f001f164d6..0655b0bc98 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -17,6 +17,7 @@ import (
 	"time"
 
 	"github.com/CanonicalLtd/candidclient"
+	dqliteclient "github.com/canonical/go-dqlite/client"
 	"github.com/canonical/go-dqlite/driver"
 	"github.com/gorilla/mux"
 	"github.com/pkg/errors"
@@ -790,14 +791,21 @@ func (d *Daemon) init() error {
 			contextTimeout = time.Minute
 		}
 
-		d.cluster, err = db.OpenCluster(
-			"db.bin", store, clusterAddress, dir,
-			d.config.DqliteSetupTimeout, dump,
+		options := []driver.Option{
 			driver.WithDialFunc(d.gateway.DialFunc()),
 			driver.WithContext(d.gateway.Context()),
-			driver.WithConnectionTimeout(10*time.Second),
+			driver.WithConnectionTimeout(10 * time.Second),
 			driver.WithContextTimeout(contextTimeout),
 			driver.WithLogFunc(cluster.DqliteLog),
+		}
+
+		if shared.StringInSlice("database", trace) {
+			options = append(options, driver.WithTracing(dqliteclient.LogDebug))
+		}
+
+		d.cluster, err = db.OpenCluster(
+			"db.bin", store, clusterAddress, dir,
+			d.config.DqliteSetupTimeout, dump, options...,
 		)
 		if err == nil {
 			break


More information about the lxc-devel mailing list