From: Sage Weil Date: Thu, 20 Jun 2013 21:12:16 +0000 (-0700) Subject: mon/PaxosService: move upgrade_format() machinery into PaxosService X-Git-Tag: v0.67-rc1~175^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=950c0f353be1055d328b45bf72a70a29bf235a02;p=ceph.git mon/PaxosService: move upgrade_format() machinery into PaxosService We originally did this in AuthMonitor, but it is perfect for PGMonitor too, so make it generic. Signed-off-by: Sage Weil --- diff --git a/src/mon/AuthMonitor.cc b/src/mon/AuthMonitor.cc index 9adadf183788..46e81b661e0c 100644 --- a/src/mon/AuthMonitor.cc +++ b/src/mon/AuthMonitor.cc @@ -87,8 +87,6 @@ void AuthMonitor::on_active() /* check_rotate(); */ - - upgrade_format(); } void AuthMonitor::create_initial() @@ -200,8 +198,6 @@ void AuthMonitor::update_from_paxos(bool *need_bootstrap) if (last_allocated_id == 0) last_allocated_id = max_global_id; - format_version = get_value("format_version"); - dout(10) << "update_from_paxos() last_allocated_id=" << last_allocated_id << " max_global_id=" << max_global_id << " format_version " << format_version @@ -253,10 +249,6 @@ void AuthMonitor::encode_pending(MonitorDBStore::Transaction *t) for (p = pending_auth.begin(); p != pending_auth.end(); ++p) p->encode(bl, mon->get_quorum_features()); - if (format_version > 0) { - t->put(get_service_name(), "format_version", format_version); - } - version_t version = get_last_committed() + 1; put_version(t, version, bl); put_last_committed(t, version); diff --git a/src/mon/AuthMonitor.h b/src/mon/AuthMonitor.h index ab52833daec7..bdae645d8d0b 100644 --- a/src/mon/AuthMonitor.h +++ b/src/mon/AuthMonitor.h @@ -112,8 +112,6 @@ private: uint64_t max_global_id; uint64_t last_allocated_id; - version_t format_version; - void upgrade_format(); void export_keyring(KeyRing& keyring); @@ -151,9 +149,10 @@ private: bool check_rotate(); public: AuthMonitor(Monitor *mn, Paxos *p, const string& service_name) - : PaxosService(mn, p, service_name), last_rotating_ver(0), - max_global_id(0), last_allocated_id(0), - format_version(0) + : PaxosService(mn, p, service_name), + last_rotating_ver(0), + max_global_id(0), + last_allocated_id(0) {} void pre_auth(MAuth *m); diff --git a/src/mon/PaxosService.cc b/src/mon/PaxosService.cc index d3912e87b63a..345fa36cb41b 100644 --- a/src/mon/PaxosService.cc +++ b/src/mon/PaxosService.cc @@ -114,6 +114,7 @@ void PaxosService::refresh(bool *need_bootstrap) // update cached versions cached_first_committed = mon->store->get(get_service_name(), first_committed_name); cached_last_committed = mon->store->get(get_service_name(), last_committed_name); + format_version = get_value("format_version"); dout(10) << __func__ << dendl; @@ -195,6 +196,10 @@ void PaxosService::propose_pending() encode_pending(&t); have_pending = false; + if (format_version > 0) { + t.put(get_service_name(), "format_version", format_version); + } + dout(30) << __func__ << " transaction dump:\n"; JSONFormatter f(true); t.dump(&f); @@ -298,6 +303,9 @@ void PaxosService::_active() // on this list; it is on Paxos's. finish_contexts(g_ceph_context, waiting_for_finished_proposal, 0); + if (is_active() && mon->is_leader()) + upgrade_format(); + // NOTE: it's possible that this will get called twice if we commit // an old paxos value. Implementations should be mindful of that. if (is_active()) diff --git a/src/mon/PaxosService.h b/src/mon/PaxosService.h index 14854e137ad2..289e25c8ecff 100644 --- a/src/mon/PaxosService.h +++ b/src/mon/PaxosService.h @@ -85,6 +85,14 @@ class PaxosService { version_t trim_version; protected: + + /** + * format of our state in leveldb, 0 for default + */ + version_t format_version; + + + /** * @defgroup PaxosService_h_callbacks Callback classes * @{ @@ -193,6 +201,7 @@ public: proposing(false), service_version(0), proposal_timer(0), have_pending(false), trim_version(0), + format_version(0), last_committed_name("last_committed"), first_committed_name("first_committed"), full_prefix_name("full"), full_latest_name("latest"), @@ -428,6 +437,13 @@ public: */ virtual void on_active() { } + /** + * this is called when activating on the leader + * + * it should conditionally upgrade the on-disk format by proposing a transaction + */ + virtual void upgrade_format() { } + /** * Called when the Paxos system enters a Leader election. *