/*
* 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
* 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
public:
C_Trimmed(Paxos *p) : paxos(p) { }
void finish(int r) {
- paxos->going_to_trim = false;
+ paxos->trimming = false;
}
};
/**
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 {
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
*
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) {