From 6284fdce794b73adcc757fee910e975b6b4bd054 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Wed, 19 Jun 2013 02:36:44 +0100 Subject: [PATCH] mon: Monitor: obtain latest monmap on sync store init 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 Reviewed-by: Sage Weil --- src/mon/Monitor.cc | 66 +++++++++++++++++++++++++++++++++++++--------- src/mon/Monitor.h | 1 + 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 293f1741fe0ee..9e910f52e7a76 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -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); } diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 6db49a9989a09..259b95269a388 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -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(); -- 2.39.5