From: Sage Weil Date: Tue, 25 Jun 2013 23:12:39 +0000 (-0700) Subject: mon/Paxos: simplify trim() X-Git-Tag: v0.67-rc1~175^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=516445bebc1ddd390d789390c17408f69928b7d2;p=ceph.git mon/Paxos: simplify trim() Collapse all the trim methods into a single simple method. Signed-off-by: Sage Weil --- diff --git a/src/mon/Paxos.cc b/src/mon/Paxos.cc index ce9f2952e2a..58c35d0305c 100644 --- a/src/mon/Paxos.cc +++ b/src/mon/Paxos.cc @@ -958,54 +958,44 @@ void Paxos::lease_renew_timeout() /* * trim old states */ -void Paxos::trim_to(MonitorDBStore::Transaction *t, - version_t from, version_t to) { - dout(10) << __func__ << " from " << from << " to " << to << dendl; - assert(from < to); +void Paxos::trim() +{ + assert(should_trim()); + version_t end = MIN(get_version() - g_conf->paxos_max_join_drift, + get_first_committed() + g_conf->paxos_trim_max); + + if (first_committed >= end) + return; + + dout(10) << "trim to " << end << " (was " << first_committed << ")" << dendl; - for (version_t v = from; v < to; ++v) { + MonitorDBStore::Transaction t; + + for (version_t v = first_committed; v < end; ++v) { dout(10) << "trim " << v << dendl; - t->erase(get_name(), v); + t.erase(get_name(), v); } + t.put(get_name(), "first_committed", end); if (g_conf->mon_compact_on_trim) { dout(10) << " compacting trimmed range" << dendl; - t->compact_range(get_name(), stringify(from - 1), stringify(to)); + t.compact_range(get_name(), stringify(first_committed - 1), stringify(end)); } -} - -void Paxos::trim_to(MonitorDBStore::Transaction *t, version_t first) -{ - dout(10) << "trim_to " << first << " (was " << first_committed << ")" - << dendl; - - if (first_committed >= first) - return; - trim_to(t, first_committed, first); - t->put(get_name(), "first_committed", first); -} -void Paxos::trim_to(version_t first) -{ - MonitorDBStore::Transaction t; - - trim_to(&t, first); - - if (!t.empty()) { - dout(30) << __func__ << " transaction dump:\n"; - JSONFormatter f(true); - t.dump(&f); - f.flush(*_dout); - *_dout << dendl; + dout(30) << __func__ << " transaction dump:\n"; + JSONFormatter f(true); + t.dump(&f); + f.flush(*_dout); + *_dout << dendl; - bufferlist bl; - t.encode(bl); + bufferlist bl; + t.encode(bl); - going_to_trim = true; - queue_proposal(bl, new C_Trimmed(this)); - } + trimming = true; + queue_proposal(bl, new C_Trimmed(this)); } -void Paxos::trim_enable() { +void Paxos::trim_enable() +{ trim_disabled_version = 0; // We may not be the leader when we reach this function. We sure must // have been the leader at some point, but we may have been demoted and diff --git a/src/mon/Paxos.h b/src/mon/Paxos.h index 810953c8101..9be4713a282 100644 --- a/src/mon/Paxos.h +++ b/src/mon/Paxos.h @@ -529,7 +529,7 @@ private: * Should be true if we have proposed to trim, or are in the middle of * trimming; false otherwise. */ - bool going_to_trim; + bool trimming; /** * If we have disabled trimming our state, this variable should have a * value greater than zero, corresponding to the version we had at the time @@ -616,7 +616,7 @@ private: public: C_Trimmed(Paxos *p) : paxos(p) { } void finish(int r) { - paxos->going_to_trim = false; + paxos->trimming = false; } }; /** @@ -1013,7 +1013,7 @@ public: lease_timeout_event(0), accept_timeout_event(0), clock_drift_warned(0), - going_to_trim(false), + trimming(false), trim_disabled_version(0) { } const string get_name() const { @@ -1131,37 +1131,11 @@ public: waiting_for_active.push_back(c); } - /** - * Erase old states from stable storage. - * - * @param first The version we are trimming to - */ - void trim_to(version_t first); - /** - * Erase old states from stable storage. - * - * @param t A transaction - * @param first The version we are trimming to - */ - void trim_to(MonitorDBStore::Transaction *t, version_t first); - /** - * Auxiliary function to erase states in the interval [from, to[ from stable - * storage. - * - * @param t A transaction - * @param from Bottom limit of the interval of versions to erase - * @param to Upper limit, not including, of the interval of versions to erase - */ - void trim_to(MonitorDBStore::Transaction *t, version_t from, version_t to); /** * Trim the Paxos state as much as we can. */ - void trim() { - assert(should_trim()); - version_t trim_to_version = MIN(get_version() - g_conf->paxos_max_join_drift, - get_first_committed() + g_conf->paxos_trim_max); - trim_to(trim_to_version); - } + void trim(); + /** * Disable trimming * @@ -1195,7 +1169,7 @@ public: int maximum_versions = (g_conf->paxos_max_join_drift + g_conf->paxos_trim_min); - if (going_to_trim || (available_versions <= maximum_versions)) + if (trimming || (available_versions <= maximum_versions)) return false; if (trim_disabled_version > 0) {