[lxc-devel] [lxd/master] Improve internal debugging functions
stgraber on Github
lxc-bot at linuxcontainers.org
Mon Apr 1 21:39:32 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190401/3966d4bb/attachment.bin>
-------------- next part --------------
From d9c9d245dc1eee5779c851663b65c92dc381fef1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 29 Mar 2019 22:34:28 -0400
Subject: [PATCH 1/3] lxd/internal: Have GC endpoint release memory
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/api_internal.go | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lxd/api_internal.go b/lxd/api_internal.go
index b5206797fc..5a6ff0ed22 100644
--- a/lxd/api_internal.go
+++ b/lxd/api_internal.go
@@ -26,6 +26,7 @@ import (
"github.com/lxc/lxd/shared/osarch"
log "github.com/lxc/lxd/shared/log15"
+ runtimeDebug "runtime/debug"
)
var apiInternal = []Command{
@@ -990,6 +991,7 @@ func internalImport(d *Daemon, r *http.Request) Response {
func internalGC(d *Daemon, r *http.Request) Response {
logger.Infof("Started forced garbage collection run")
runtime.GC()
+ runtimeDebug.FreeOSMemory()
logger.Infof("Completed forced garbage collection run")
return EmptySyncResponse
From 0f9fd8926331f2c94adbac8045ffd102973c7b74 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 1 Apr 2019 17:24:36 -0400
Subject: [PATCH 2/3] lxd/cluster: Export Snapshot function
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/cluster/gateway.go | 5 +++++
lxd/cluster/raft.go | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/lxd/cluster/gateway.go b/lxd/cluster/gateway.go
index 543f53d2d3..5703da77d5 100644
--- a/lxd/cluster/gateway.go
+++ b/lxd/cluster/gateway.go
@@ -243,6 +243,11 @@ func (g *Gateway) HandlerFuncs() map[string]http.HandlerFunc {
}
}
+// Snapshot can be used to manually trigger a RAFT snapshot
+func (g *Gateway) Snapshot() error {
+ return g.raft.Snapshot()
+}
+
// WaitUpgradeNotification waits for a notification from another node that all
// nodes in the cluster should now have been upgraded and have matching schema
// and API versions.
diff --git a/lxd/cluster/raft.go b/lxd/cluster/raft.go
index 5ac00f4919..13b97f432a 100644
--- a/lxd/cluster/raft.go
+++ b/lxd/cluster/raft.go
@@ -297,6 +297,11 @@ func (i *raftInstance) Shutdown() error {
return nil
}
+// Snapshot can be used to manually trigger a RAFT snapshot
+func (i *raftInstance) Snapshot() error {
+ return i.raft.Snapshot().Error()
+}
+
// Create an in-memory raft transport.
func raftMemoryTransport() raft.Transport {
_, transport := raft.NewInmemTransport("0")
From 03484e10bf5b8bdc18a3019ed36ffd89cf5fd0cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 1 Apr 2019 17:30:02 -0400
Subject: [PATCH 3/3] lxd/internal: Expose raft-snapshot
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/api_internal.go | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/lxd/api_internal.go b/lxd/api_internal.go
index 5a6ff0ed22..dfec648fc4 100644
--- a/lxd/api_internal.go
+++ b/lxd/api_internal.go
@@ -41,6 +41,7 @@ var apiInternal = []Command{
internalClusterPromoteCmd,
internalClusterContainerMovedCmd,
internalGarbageCollectorCmd,
+ internalRAFTSnapshotCmd,
}
var internalShutdownCmd = Command{
@@ -79,6 +80,11 @@ var internalGarbageCollectorCmd = Command{
get: internalGC,
}
+var internalRAFTSnapshotCmd = Command{
+ name: "raft-snapshot",
+ get: internalRAFTSnapshot,
+}
+
func internalWaitReady(d *Daemon, r *http.Request) Response {
select {
case <-d.readyChan:
@@ -996,3 +1002,16 @@ func internalGC(d *Daemon, r *http.Request) Response {
return EmptySyncResponse
}
+
+func internalRAFTSnapshot(d *Daemon, r *http.Request) Response {
+ logger.Infof("Started forced RAFT snapshot")
+ err := d.gateway.Snapshot()
+ if err != nil {
+ logger.Errorf("Failed forced RAFT snapshot: %v", err)
+ return InternalError(err)
+ }
+
+ logger.Infof("Completed forced RAFT snapshot")
+
+ return EmptySyncResponse
+}
More information about the lxc-devel
mailing list