From d14665e550d9b2dfc47684b73427042b0744127f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 29 May 2013 08:40:32 -0700 Subject: [PATCH] mon: compact trimmed range, not entire prefix This will reduce the work that leveldb is asked to do by only triggering compaction of the keys that were just trimmed. We ma want to further reduce the work by compacting less frequently, but this is at least a step in that direction. Signed-off-by: Sage Weil (cherry picked from commit 6da4b20ca53fc8161485c8a99a6b333e23ace30e) --- src/mon/Paxos.cc | 12 ++++++------ src/mon/PaxosService.cc | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/mon/Paxos.cc b/src/mon/Paxos.cc index bfb9ed4f5dd3a..7ff5edbd0a921 100644 --- a/src/mon/Paxos.cc +++ b/src/mon/Paxos.cc @@ -21,6 +21,7 @@ #include "common/config.h" #include "include/assert.h" +#include "include/stringify.h" #include "common/Formatter.h" #define dout_subsys ceph_subsys_paxos @@ -959,14 +960,13 @@ void Paxos::trim_to(MonitorDBStore::Transaction *t, dout(10) << __func__ << " from " << from << " to " << to << dendl; assert(from < to); - while (from < to) { - dout(10) << "trim " << from << dendl; - t->erase(get_name(), from); - from++; + for (version_t v = from; v < to; ++v) { + dout(10) << "trim " << v << dendl; + t->erase(get_name(), v); } if (g_conf->mon_compact_on_trim) { - dout(10) << " compacting prefix" << dendl; - t->compact_prefix(get_name()); + dout(10) << " compacting trimmed range" << dendl; + t->compact_range(get_name(), stringify(from), stringify(to)); } } diff --git a/src/mon/PaxosService.cc b/src/mon/PaxosService.cc index 8f421ab3d8187..3402cf7e76f28 100644 --- a/src/mon/PaxosService.cc +++ b/src/mon/PaxosService.cc @@ -314,11 +314,12 @@ void PaxosService::trim(MonitorDBStore::Transaction *t, { dout(10) << __func__ << " from " << from << " to " << to << dendl; assert(from != to); - for (; from < to; from++) { - dout(20) << __func__ << " " << from << dendl; - t->erase(get_service_name(), from); - string full_key = mon->store->combine_strings("full", from); + for (version_t v = from; v < to; ++v) { + dout(20) << __func__ << " " << v << dendl; + t->erase(get_service_name(), v); + + string full_key = mon->store->combine_strings("full", v); if (mon->store->exists(get_service_name(), full_key)) { dout(20) << __func__ << " " << full_key << dendl; t->erase(get_service_name(), full_key); @@ -326,7 +327,7 @@ void PaxosService::trim(MonitorDBStore::Transaction *t, } if (g_conf->mon_compact_on_trim) { dout(20) << " compacting prefix " << get_service_name() << dendl; - t->compact_prefix(get_service_name()); + t->compact_range(get_service_name(), stringify(from), stringify(to)); } } -- 2.39.5