Configuration Reload

Started by
2 comments, last by Kylotan 15 years, 5 months ago
1. I am using a std::map to store some values of keys 2. On startup of my function i am loading values to my map 3. I am storing values to my map by a http call which is returning the key and values from a file. 4. Now i have changed my configuration file and i want to reload the config map without restarting my process 5. lots of places i am already accessing this map How safely i can reload my configurations? Please need some idea and help Regards, Samba
Advertisement
It's safe to do it anywhere, if you are running single-threaded, and you have copied values out of the map rather than holding iterators or pointers to elements.
Quote:Original post by Kylotan
It's safe to do it anywhere


Not really, changing configuration may mean a lot. Consider "server.port" being changed. It requires you to shut down all sockets, recreate them, taking into consideration failures, then rewire the handlers, take care of timeouts, failed services, potentially cascading failure if port is mis-configured.

What you need is some form of configuration mechanism. All configurable components must implement some for of an interface, such as:
IConfigurable {  void applyConfiguration(Config & c);}class Configuration {  void install(IConfigurable * cfg);  void remove(IConfigurable * cfg);  void reloadConfiguration() {    for (every cfg in configurables) {      cfg->applyConfiguration(new_config);    }  }};


When such a component starts, it registers itself with configuration system. Whenever this configuration changes, applyConfiguration is called, and each implementor of this interface is responsible of properly handling any changes.

Note that if any component incorrectly implements IConfigurable, you'll be left with broken state. This is all complicated further by inter-connected components, where one may depend on another, yet configuration may remove one of the required components.
Quote:Original post by Antheus
Quote:Original post by Kylotan
It's safe to do it anywhere


Not really, changing configuration may mean a lot.

I suppose I was focusing on the safety of the std::map, since I thought that was the focus of the question. I guess the rest depends exactly on what is being configured.

This topic is closed to new replies.

Advertisement