]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigMap: add ConfigChangeSet
authorSage Weil <sage@redhat.com>
Mon, 5 Mar 2018 14:35:45 +0000 (08:35 -0600)
committerSage Weil <sage@redhat.com>
Sat, 17 Mar 2018 16:09:03 +0000 (11:09 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/ConfigMap.cc
src/mon/ConfigMap.h
src/mon/ConfigMonitor.cc

index 3ac72f6dd342af09934a48e01f6d3d9314d110dd..bd4fd0c0bef62ed9a3b17e9e0ed2b428a6f79a8a 100644 (file)
@@ -168,3 +168,43 @@ bool ConfigMap::parse_mask(
   }
   return true;
 }
+
+
+// --------------
+
+void ConfigChangeSet::dump(Formatter *f) const
+{
+  f->dump_int("version", version);
+  f->dump_stream("timestamp") << stamp;
+  f->dump_string("name", name);
+  f->open_array_section("changes");
+  for (auto& i : diff) {
+    f->open_object_section("change");
+    f->dump_string("name", i.first);
+    if (i.second.first) {
+      f->dump_string("previous_value", *i.second.first);
+    }
+    if (i.second.second) {
+      f->dump_string("new_value", *i.second.second);
+    }
+    f->close_section();
+  }
+  f->close_section();
+}
+
+void ConfigChangeSet::print(ostream& out) const
+{
+  out << "--- " << version << " --- " << stamp;
+  if (name.size()) {
+    out << " --- " << name;
+  }
+  out << " ---\n";
+  for (auto& i : diff) {
+    if (i.second.first) {
+      out << "- " << i.first << " = " << *i.second.first << "\n";
+    }
+    if (i.second.second) {
+      out << "+ " << i.first << " = " << *i.second.second << "\n";
+    }
+  }
+}
index 02b4d9d9e7c57e94f412bc7a3ae2af49ae2e6155..c4b1abf7f7a367bf09105a07fc49af21e27e0b52 100644 (file)
@@ -7,6 +7,7 @@
 #include <ostream>
 #include <string>
 
+#include "include/utime.h"
 #include "common/options.h"
 #include "common/entity_name.h"
 
@@ -125,3 +126,16 @@ struct ConfigMap {
     std::string *section,
     OptionMask *mask);
 };
+
+
+struct ConfigChangeSet {
+  version_t version;
+  utime_t stamp;
+  string name;
+
+  // key -> (old value, new value)
+  map<string,pair<boost::optional<string>,boost::optional<string>>> diff;
+
+  void dump(Formatter *f) const;
+  void print(ostream& out) const;
+};
index 85b45c8deb05a7e2dc6599a616a7b44c31c7c195..da2de3cd7fb8b3b46275cad3b5a91183a740a215 100644 (file)
@@ -630,6 +630,36 @@ void ConfigMonitor::load_config()
   }
 }
 
+void ConfigMonitor::load_changeset(version_t v, ConfigChangeSet *ch)
+{
+  ch->version = v;
+  string prefix = HISTORY_PREFIX + stringify(v) + "/";
+  KeyValueDB::Iterator it = mon->store->get_iterator(CONFIG_PREFIX);
+  it->lower_bound(prefix);
+  while (it->valid() && it->key().find(prefix) == 0) {
+    if (it->key() == prefix) {
+      bufferlist bl = it->value();
+      auto p = bl.begin();
+      try {
+       decode(ch->stamp, p);
+       decode(ch->name, p);
+      }
+      catch (buffer::error& e) {
+       derr << __func__ << " failure decoding changeset " << v << dendl;
+      }
+    } else {
+      char op = it->key()[prefix.length()];
+      string key = it->key().substr(prefix.length() + 1);
+      if (op == '-') {
+       ch->diff[key].first = it->value().to_str();
+      } else if (op == '+') {
+       ch->diff[key].second = it->value().to_str();
+      }
+    }
+    it->next();
+  }
+}
+
 bool ConfigMonitor::refresh_config(MonSession *s)
 {
   const OSDMap& osdmap = mon->osdmon()->osdmap;