From 71befa298658925555841a2a98802210954358ce Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 19 Feb 2020 17:42:09 -0600 Subject: [PATCH] mon: stash newer map on bootstrap when addr doesn't match If we have to respawn because a newer monmap comes along where our addr or rank changes, we need to use that on restart in order to make progress. Stash the newer map in a temporary location and use it when we restart. Don't bother cleaning up. Having this map here is harmless, since we only use it if it is newer than what is in paxos. Fixes: https://tracker.ceph.com/issues/44076 Signed-off-by: Sage Weil --- src/ceph_mon.cc | 19 +++++++++++++++++++ src/mon/Monitor.cc | 13 +++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index 117a94dc55c..f56d6914da5 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -61,6 +61,7 @@ int obtain_monmap(MonitorDBStore &store, bufferlist &bl) dout(10) << __func__ << dendl; /* * the monmap may be in one of three places: + * 'mon_sync:temp_newer_monmap' - stashed newer map for bootstrap * 'monmap:' - the monmap we'd really like to have * 'mon_sync:latest_monmap' - last monmap backed up for the last sync * 'mkfs:monmap' - a monmap resulting from mkfs @@ -74,6 +75,24 @@ int obtain_monmap(MonitorDBStore &store, bufferlist &bl) ceph_assert(bl.length() > 0); dout(10) << __func__ << " read last committed monmap ver " << latest_ver << dendl; + + // see if there is stashed newer map (see bootstrap()) + if (store.exists("mon_sync", "temp_newer_monmap")) { + bufferlist bl2; + int err = store.get("mon_sync", "temp_newer_monmap", bl2); + ceph_assert(err == 0); + ceph_assert(bl2.length() > 0); + MonMap b; + b.decode(bl2); + if (b.get_epoch() > latest_ver) { + dout(10) << __func__ << " using stashed monmap " << b.get_epoch() + << " instead" << dendl; + bl.claim(bl2); + } else { + dout(10) << __func__ << " ignoring stashed monmap " << b.get_epoch() + << dendl; + } + } return 0; } } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 469cc17e335..d8e2bb0f69e 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -1153,6 +1153,19 @@ void Monitor::bootstrap() << messenger->get_myaddrs() << ", monmap is " << monmap->get_addrs(newrank) << ", respawning" << dendl; + + if (monmap->get_epoch()) { + // store this map in temp mon_sync location so that we use it on + // our next startup + derr << " stashing newest monmap " << monmap->get_epoch() + << " for next startup" << dendl; + bufferlist bl; + monmap->encode(bl, -1); + auto t(std::make_shared()); + t->put("mon_sync", "temp_newer_monmap", bl); + store->apply_transaction(t); + } + respawn(); } if (newrank != rank) { -- 2.47.3