From: Sage Weil Date: Mon, 5 Mar 2018 01:24:20 +0000 (-0600) Subject: mon/ConfigMonitor: maintain history of all config changes X-Git-Tag: v13.1.0~385^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0f7707625305116df4097481387ed842ca67a6ba;p=ceph.git mon/ConfigMonitor: maintain history of all config changes Signed-off-by: Sage Weil --- diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index 6614919662f6..0ccd523c3d82 100644 --- a/src/mon/ConfigMonitor.cc +++ b/src/mon/ConfigMonitor.cc @@ -22,6 +22,7 @@ static ostream& _prefix(std::ostream *_dout, const Monitor *mon, } const string KEY_PREFIX("config/"); +const string HISTORY_PREFIX("config-history/"); ConfigMonitor::ConfigMonitor(Monitor *m, Paxos *p, const string& service_name) : PaxosService(m, p, service_name) { @@ -54,6 +55,7 @@ void ConfigMonitor::create_pending() { dout(10) << " " << version << dendl; pending.clear(); + pending_description.clear(); } void ConfigMonitor::encode_pending(MonitorDBStore::TransactionRef t) @@ -63,11 +65,28 @@ void ConfigMonitor::encode_pending(MonitorDBStore::TransactionRef t) // TODO: record changed sections (osd, mds.foo, rack:bar, ...) + string history = HISTORY_PREFIX + stringify(version+1) + "/"; + { + bufferlist metabl; + ::encode(ceph_clock_now(), metabl); + ::encode(pending_description, metabl); + t->put(CONFIG_PREFIX, history, metabl); + } for (auto& p : pending) { string key = KEY_PREFIX + p.first; + auto q = current.find(p.first); + if (q != current.end()) { + if (p.second && *p.second == q->second) { + continue; + } + t->put(CONFIG_PREFIX, history + "-" + p.first, q->second); + } else if (!p.second) { + continue; + } if (p.second) { dout(20) << __func__ << " set " << key << dendl; t->put(CONFIG_PREFIX, key, *p.second); + t->put(CONFIG_PREFIX, history + "+" + p.first, *p.second); } else { dout(20) << __func__ << " rm " << key << dendl; t->erase(CONFIG_PREFIX, key); @@ -518,11 +537,14 @@ void ConfigMonitor::load_config() KeyValueDB::Iterator it = mon->store->get_iterator(CONFIG_PREFIX); it->lower_bound(KEY_PREFIX); config_map.clear(); + current.clear(); while (it->valid() && it->key().compare(0, KEY_PREFIX.size(), KEY_PREFIX) == 0) { string key = it->key().substr(KEY_PREFIX.size()); string value = it->value().to_str(); + current[key] = it->value(); + auto last_slash = key.rfind('/'); string name; string who; diff --git a/src/mon/ConfigMonitor.h b/src/mon/ConfigMonitor.h index 33e6054c831d..e705534186c9 100644 --- a/src/mon/ConfigMonitor.h +++ b/src/mon/ConfigMonitor.h @@ -15,6 +15,9 @@ class ConfigMonitor : public PaxosService version_t version = 0; ConfigMap config_map; map> pending; + string pending_description; + + map current; public: ConfigMonitor(Monitor *m, Paxos *p, const string& service_name);