]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmon: add --inject-monmap option
authorSage Weil <sage@newdream.net>
Tue, 29 Mar 2011 18:58:13 +0000 (11:58 -0700)
committerSage Weil <sage@newdream.net>
Tue, 29 Mar 2011 18:58:13 +0000 (11:58 -0700)
This lets you manually inject a monmap into a down monitor.  This is useful
in cases where you need to change the monmap but aren't able to get a
quorum with the old map.

Signed-off-by: Sage Weil <sage@newdream.net>
src/cmon.cc
src/mon/MonMap.h

index 96ed18deb7f4d17b0fd629b439f36ba1d7dfde7c..bdf7bf328f91a1731d98202b1a3bcfd1f48e3934 100644 (file)
@@ -56,6 +56,7 @@ int main(int argc, const char **argv)
 
   bool mkfs = false;
   const char *osdmapfn = 0;
+  const char *inject_monmap = 0;
 
   vector<const char*> args;
   argv_to_vec(argc, argv, args);
@@ -69,6 +70,8 @@ int main(int argc, const char **argv)
       mkfs = true;
     } else if (CONF_ARG_EQ("osdmap", '\0')) {
       CONF_SAFE_SET_ARG_VAL(&osdmapfn, OPT_STR);
+    } else if (CONF_ARG_EQ("inject_monmap", '\0')) {
+      CONF_SAFE_SET_ARG_VAL(&inject_monmap, OPT_STR);
     } else
       usage();
   }
@@ -163,6 +166,43 @@ int main(int argc, const char **argv)
   }
 
 
+  // inject new monmap?
+  if (inject_monmap) {
+    bufferlist bl;
+    int r = bl.read_file(inject_monmap);
+    if (r) {
+      cerr << "unable to read monmap from " << inject_monmap << std::endl;
+      exit(1);
+    }
+
+    // get next version
+    version_t v = store.get_int("monmap", "last_committed");
+    cout << "last committed monmap epoch is " << v << ", injected map will be " << (v+1) << std::endl;
+    v++;
+
+    // set the version
+    MonMap tmp;
+    tmp.decode(bl);
+    if (tmp.get_epoch() != v) {
+      cout << "changing monmap epoch from " << tmp.get_epoch() << " to " << v << std::endl;
+      tmp.set_epoch(v);
+    }
+    bufferlist mapbl;
+    test.encode(mapbl);
+    bufferlist final;
+    ::encode(v, final);
+    ::encode(mapbl, final);
+
+    // save it
+    store.put_bl_sn(mapbl, "monmap", v);
+    store.put_bl_ss(final, "monmap", "latest");
+    store.put_int(v, "monmap", "last_committed");
+
+    cout << "done." << std::endl;
+    exit(0);
+  }
+
+
   // monmap?
   MonMap monmap;
   {
index ddf49b435f9d7ba7327d19a798f6ad9f9da5baaa..03e87c96a70b20e4dc1f8b42862a15d57581a7cf 100644 (file)
@@ -71,6 +71,7 @@ class MonMap {
   }
 
   epoch_t get_epoch() { return epoch; }
+  void set_epoch(epoch_t e) { epoch = e; }
 
   void add(const string &name, const entity_addr_t &addr) {
     assert(mon_addr.count(name) == 0);