The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6259
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) === Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From b91cfd8036069ec97714a0d7b64a54de3c7e8010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Sun, 29 Sep 2019 21:55:35 -0400 Subject: [PATCH] lxd/db: Flush any leftover operation on startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxd/db/db.go | 36 ++++++++++++++++++++++++++---------- lxd/db/operations.go | 10 ++++++++++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/lxd/db/db.go b/lxd/db/db.go index 40fd7ad876..3c769fd623 100644 --- a/lxd/db/db.go +++ b/lxd/db/db.go @@ -267,24 +267,40 @@ func OpenCluster(name string, store driver.NodeStore, address, dir string, timeo stmts: stmts, } - // Figure out the ID of this node. err = cluster.Transaction(func(tx *ClusterTx) error { + // Figure out the ID of this node. nodes, err := tx.Nodes() if err != nil { - return errors.Wrap(err, "failed to fetch nodes") + return errors.Wrap(err, "Failed to fetch nodes") } + + nodeID := int64(-1) if len(nodes) == 1 && nodes[0].Address == "0.0.0.0" { // We're not clustered - cluster.NodeID(1) - return nil - } - for _, node := range nodes { - if node.Address == address { - cluster.nodeID = node.ID - return nil + nodeID = 1 + } else { + for _, node := range nodes { + if node.Address == address { + nodeID = node.ID + break + } } } - return fmt.Errorf("no node registered with address %s", address) + + if nodeID < 0 { + return fmt.Errorf("No node registered with address %s", address) + } + + // Set the local node ID + cluster.NodeID(nodeID) + + // Delete any operation tied to this node + err = tx.OperationFlush(nodeID) + if err != nil { + return err + } + + return nil }) if err != nil { return nil, err diff --git a/lxd/db/operations.go b/lxd/db/operations.go index 58e697ee53..e3c3e564c0 100644 --- a/lxd/db/operations.go +++ b/lxd/db/operations.go @@ -315,6 +315,16 @@ func (c *ClusterTx) OperationRemove(uuid string) error { return nil } +// OperationFlush removes all operations for the given node. +func (c *ClusterTx) OperationFlush(nodeID int64) error { + _, err := c.tx.Exec("DELETE FROM operations WHERE node_id=?", nodeID) + if err != nil { + return err + } + + return nil +} + // Operations returns all operations in the cluster, filtered by the given clause. func (c *ClusterTx) operations(where string, args ...interface{}) ([]Operation, error) { operations := []Operation{}
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel