From: Sage Weil Date: Thu, 30 May 2013 21:26:42 +0000 (-0700) Subject: os/LevelDBStore: merge adjacent ranges in compactionqueue X-Git-Tag: v0.64~35^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f628dd0e4a5ace079568773edfab29d9f764d4f0;p=ceph.git os/LevelDBStore: merge adjacent ranges in compactionqueue If we get behind and multiple adjacent ranges end up in the queue, merge them so that we fire off compaction on larger ranges. Signed-off-by: Sage Weil --- diff --git a/src/os/LevelDBStore.cc b/src/os/LevelDBStore.cc index 2f1ea53e9a59..7b61c81635a9 100644 --- a/src/os/LevelDBStore.cc +++ b/src/os/LevelDBStore.cc @@ -158,3 +158,36 @@ void LevelDBStore::compact_thread_entry() } compact_queue_lock.Unlock(); } + +void 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 >::iterator p = compact_queue.begin(); + while (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)); + 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)); + break; + } else { + ++p; + } + } + if (p == compact_queue.end()) { + // no merge, new entry. + compact_queue.push_back(make_pair(start, end)); + } + compact_queue_cond.Signal(); + if (!compact_thread.is_started()) { + compact_thread.create(); + } +} diff --git a/src/os/LevelDBStore.h b/src/os/LevelDBStore.h index e4e84107fdf0..556ba0388ee8 100644 --- a/src/os/LevelDBStore.h +++ b/src/os/LevelDBStore.h @@ -56,15 +56,7 @@ class LevelDBStore : public KeyValueDB { leveldb::Slice cend(end); db->CompactRange(&cstart, &cend); } - void compact_range_async(const string& start, const string& end) { - Mutex::Locker l(compact_queue_lock); - compact_queue.remove(make_pair(start, end)); // prevent unbounded dups - compact_queue.push_back(make_pair(start, end)); - compact_queue_cond.Signal(); - if (!compact_thread.is_started()) { - compact_thread.create(); - } - } + void compact_range_async(const string& start, const string& end); public: /// compact the underlying leveldb store