From db380a8371401865cdad9c39a78842f9c7316a21 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Fri, 16 Jan 2015 08:26:26 +0000 Subject: [PATCH] ignore duplicate deletes in config --- node/node.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/node/node.go b/node/node.go index 036542a0..dc562285 100644 --- a/node/node.go +++ b/node/node.go @@ -83,11 +83,16 @@ func (c *clusterConfig) setMountIfChanged(m *autoradio.Mount) bool { return true } -// Delete a mount (in-memory only). -func (c *clusterConfig) delMount(name string) { +// Delete a mount (in-memory only). Returns true if the mount existed +// in our configuration and was deleted successfully. +func (c *clusterConfig) delMount(name string) bool { c.lock.Lock() defer c.lock.Unlock() - delete(c.mounts, name) + if _, ok := c.mounts[name]; ok { + delete(c.mounts, name) + return true + } + return false } // Keeps the in-memory service configuration in sync with the etcd @@ -163,7 +168,11 @@ func (w *configWatcher) watcher(index uint64, stop chan bool) { case "delete": mountName := keyToMount(resp.Node.Key) log.Printf("deleted mount %s", mountName) - w.config.delMount(mountName) + if !w.config.delMount(mountName) { + // Do not trigger an update if the + // operation had no effect. + continue + } case "set", "create", "update": if !w.updateMount(resp.Node.Key, resp.Node.Value, index) { // Do not trigger an update if the -- GitLab