]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: Monitor: obtain latest monmap on sync store init
authorJoao Eduardo Luis <joao.luis@inktank.com>
Wed, 19 Jun 2013 01:36:44 +0000 (02:36 +0100)
committerSage Weil <sage@inktank.com>
Wed, 19 Jun 2013 04:58:19 +0000 (21:58 -0700)
Always use the highest version amongst all the typically available
monmaps: whatever we have in memory, whatever we have under the
MonmapMonitor's store, and whatever we have backed up from a previous
sync.  This ensures we always use the newest version we came across
with.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
src/mon/Monitor.cc
src/mon/Monitor.h

index 293f1741fe0ee6557fba3414440723691b492853..9e910f52e7a76f42dd73ce0e1b81d034dc67f746 100644 (file)
@@ -1341,30 +1341,70 @@ void Monitor::sync_requester_abort()
   bootstrap();
 }
 
-/**
- *
- */
-void Monitor::sync_store_init()
+void Monitor::sync_obtain_latest_monmap(bufferlist &bl)
 {
-  MonitorDBStore::Transaction t;
-  t.put("mon_sync", "in_sync", 1);
+  dout(1) << __func__ << dendl;
 
-  bufferlist latest_monmap;
-  int err = monmon()->get_monmap(latest_monmap);
+  MonMap latest_monmap;
+
+  // Grab latest monmap from MonmapMonitor
+  bufferlist monmon_bl;
+  int err = monmon()->get_monmap(monmon_bl);
   if (err < 0) {
     if (err != -ENOENT) {
       derr << __func__
            << " something wrong happened while reading the store: "
            << cpp_strerror(err) << dendl;
       assert(0 == "error reading the store");
-      return; // this is moot
-    } else {
-      dout(10) << __func__ << " backup current monmap" << dendl;
-      monmap->encode(latest_monmap, CEPH_FEATURES_ALL);
     }
+  } else {
+    latest_monmap.decode(monmon_bl);
+  }
+
+  // Grab last backed up monmap (if any) and compare epochs
+  if (store->exists("mon_sync", "latest_monmap")) {
+    bufferlist backup_bl;
+    int err = store->get("mon_sync", "latest_monmap", backup_bl);
+    if (err < 0) {
+      assert(err != -ENOENT);
+      derr << __func__
+           << " something wrong happened while reading the store: "
+           << cpp_strerror(err) << dendl;
+      assert(0 == "error reading the store");
+    }
+    assert(backup_bl.length() > 0);
+
+    MonMap backup_monmap;
+    backup_monmap.decode(backup_bl);
+
+    if (backup_monmap.epoch > latest_monmap.epoch)
+      latest_monmap = backup_monmap;
   }
 
-  t.put("mon_sync", "latest_monmap", latest_monmap);
+  // Check if our current monmap's epoch is greater than the one we've
+  // got so far.
+  if (monmap->epoch > latest_monmap.epoch)
+    latest_monmap = *monmap;
+
+  assert(latest_monmap.epoch > 0);
+  dout(1) << __func__ << " obtained monmap e" << latest_monmap.epoch << dendl;
+
+  latest_monmap.encode(bl, CEPH_FEATURES_ALL);
+}
+
+/**
+ *
+ */
+void Monitor::sync_store_init()
+{
+  MonitorDBStore::Transaction t;
+  t.put("mon_sync", "in_sync", 1);
+
+  bufferlist backup_monmap;
+  sync_obtain_latest_monmap(backup_monmap);
+  assert(backup_monmap.length() > 0);
+
+  t.put("mon_sync", "latest_monmap", backup_monmap);
 
   store->apply_transaction(t);
 }
index 6db49a9989a096c14eb35cb463675161f97bde3c..259b95269a38877ab22819d79c3768ec60dc05b6 100644 (file)
@@ -363,6 +363,7 @@ private:
     }
   };
 
+  void sync_obtain_latest_monmap(bufferlist &bl);
   void sync_store_init();
   void sync_store_cleanup();
   bool is_sync_on_going();