diff options
author | Joao Eduardo Luis <joao.luis@inktank.com> | 2013-06-19 02:36:44 +0100 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-06-18 22:01:00 -0700 |
commit | f8f83e78218ee5b8602cfe6758caf2ecd3e06602 (patch) | |
tree | bff3a7000e4484a5bd12effa8d998ebae953796e | |
parent | 41e1a6beeef69136fe6ec3f31d07ea8c33d64cba (diff) | |
download | ceph-f8f83e78218ee5b8602cfe6758caf2ecd3e06602.tar.gz |
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 <joao.luis@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
(cherry picked from commit 6284fdce794b73adcc757fee910e975b6b4bd054)
-rw-r--r-- | src/mon/Monitor.cc | 66 | ||||
-rw-r--r-- | 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 3ecff6a513a..9543885deaa 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -1332,30 +1332,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 2c1125728df..74a94be4e0a 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -361,6 +361,7 @@ private: } }; + void sync_obtain_latest_monmap(bufferlist &bl); void sync_store_init(); void sync_store_cleanup(); bool is_sync_on_going(); |