summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-05-30 14:36:41 -0700
committerSage Weil <sage@inktank.com>2013-06-02 14:09:51 -0700
commit0109fa8ae70671c2d8ca19bcc95662d5f41cac66 (patch)
treeb8034eb33465bdc91c7a6f82fbf8a72fc6a4b0f5
parent83b1edac07dd74b91ba2cdfe8b63236d7930c9b1 (diff)
downloadceph-0109fa8ae70671c2d8ca19bcc95662d5f41cac66.tar.gz
mon: make compaction bounds overlap
When we trim items N to M, compact over range (N-1) to M so that the items in the queue will share bounds and get merged. There is no harm in compacting over a larger range here when the lower bound is a key that doesn't exist anyway. Signed-off-by: Sage Weil <sage@inktank.com> (cherry picked from commit a47ca583980523ee0108774b466718b303bd3f46)
-rw-r--r--src/mon/Paxos.cc2
-rw-r--r--src/mon/PaxosService.cc2
-rw-r--r--src/os/LevelDBStore.cc11
3 files changed, 9 insertions, 6 deletions
diff --git a/src/mon/Paxos.cc b/src/mon/Paxos.cc
index 7ff5edbd0a9..a1a04ae6c1e 100644
--- a/src/mon/Paxos.cc
+++ b/src/mon/Paxos.cc
@@ -966,7 +966,7 @@ void Paxos::trim_to(MonitorDBStore::Transaction *t,
}
if (g_conf->mon_compact_on_trim) {
dout(10) << " compacting trimmed range" << dendl;
- t->compact_range(get_name(), stringify(from), stringify(to));
+ t->compact_range(get_name(), stringify(from - 1), stringify(to));
}
}
diff --git a/src/mon/PaxosService.cc b/src/mon/PaxosService.cc
index 3402cf7e76f..5b69235e938 100644
--- a/src/mon/PaxosService.cc
+++ b/src/mon/PaxosService.cc
@@ -327,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_range(get_service_name(), stringify(from), stringify(to));
+ t->compact_range(get_service_name(), stringify(from - 1), stringify(to));
}
}
diff --git a/src/os/LevelDBStore.cc b/src/os/LevelDBStore.cc
index 435a8aa2f65..31807141c78 100644
--- a/src/os/LevelDBStore.cc
+++ b/src/os/LevelDBStore.cc
@@ -158,24 +158,27 @@ void LevelDBStore::compact_thread_entry()
compact_queue_lock.Unlock();
}
-void compact_range_async(const string& start, const string& end)
+void LevelDBStore::compact_range_async(const string& start, const string& end)
{
Mutex::Locker l(compact_queue_lock);
// try to merge adjacent ranges. this is O(n), but the queue should
- // be short.
- list< pair<string,string> >::iterator p = compact_queue.begin();
- while (p != compact_queue.end(); ++p) {
+ // be short. note that we do not cover all overlap cases and merge
+ // opportunities here, but we capture the ones we currently need.
+ list< pair<string,string> >::iterator p;
+ for (p = compact_queue.begin(); p != compact_queue.end(); ++p) {
if (p->first == start && p->second == end) {
// dup; no-op
return;
} else if (p->first <= end && p->first > start) {
// merge with existing range to the right
compact_queue.push_back(make_pair(start, p->second));
+ compact_queue.erase(p);
break;
} else if (p->second >= start && p->second < end) {
// merge with existing range to the left
compact_queue.push_back(make_pair(p->first, end));
+ compact_queue.erase(p);
break;
} else {
++p;