From c92b196d2ee8bcc50c79e05ea79ddd70cf39fbca Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Fri, 25 Mar 2016 01:10:03 -0700 Subject: [PATCH] Reload config should initialize only the appropriate datastore With the current implementation, a config relaod event causes all the datastores to reinitialize and that impacts objects with Persist=false such as none and host network. Signed-off-by: Madhu Venugopal --- libnetwork/controller.go | 7 +++---- libnetwork/store.go | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libnetwork/controller.go b/libnetwork/controller.go index 0703a64cb4..0b5ee8746c 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -218,6 +218,9 @@ func (c *controller) ReloadConfiguration(cfgOptions ...config.Option) error { return types.ForbiddenErrorf("cannot accept new configuration because it modifies an existing datastore client") } } else { + if err := c.initScopedStore(s, nSCfg); err != nil { + return err + } update = true } } @@ -229,10 +232,6 @@ func (c *controller) ReloadConfiguration(cfgOptions ...config.Option) error { c.cfg = cfg c.Unlock() - if err := c.initStores(); err != nil { - return err - } - if c.discovery == nil && c.cfg.Cluster.Watcher != nil { if err := c.initDiscovery(c.cfg.Cluster.Watcher); err != nil { log.Errorf("Failed to Initialize Discovery after configuration update: %v", err) diff --git a/libnetwork/store.go b/libnetwork/store.go index 41dd21b746..2c439dcbd4 100644 --- a/libnetwork/store.go +++ b/libnetwork/store.go @@ -7,6 +7,18 @@ import ( "github.com/docker/libnetwork/datastore" ) +func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error { + store, err := datastore.NewDataStore(scope, scfg) + if err != nil { + return err + } + c.Lock() + c.stores = append(c.stores, store) + c.Unlock() + + return nil +} + func (c *controller) initStores() error { c.Lock() if c.cfg == nil { @@ -18,13 +30,9 @@ func (c *controller) initStores() error { c.Unlock() for scope, scfg := range scopeConfigs { - store, err := datastore.NewDataStore(scope, scfg) - if err != nil { + if err := c.initScopedStore(scope, scfg); err != nil { return err } - c.Lock() - c.stores = append(c.stores, store) - c.Unlock() } c.startWatch()