From 8fb5f404688ad32b37de38e6efa65ae38d800627 Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Tue, 23 Oct 2012 22:36:22 -0700 Subject: [PATCH] firstIndex fix for multi-threaded compaction code. Summary: Prior to multi-threaded compaction, wrap-around would be done by using current_->files_[level[0]. With this change we should be using the first file for which f->being_compacted is not true. https://github.com/facebook/leveldb/commit/1ca0584345af85d2dccc434f451218119626d36e#commitcomment-2041516 Test Plan: make check Differential Revision: https://reviews.facebook.net/D6165 --- db/version_set.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index 2def46540..3f565d5e8 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1587,7 +1587,7 @@ Compaction* VersionSet::PickCompactionBySize(int level) { MaxGrandParentOverlapBytes(level), NumberLevels()); // remember the first file that is not being compacted - int firstIndex = 0; + int firstIndex = -1; // Pick the first file that comes after compact_pointer_[level] for (size_t i = 0; i < current_->files_[level].size(); i++) { @@ -1597,7 +1597,9 @@ Compaction* VersionSet::PickCompactionBySize(int level) { if (f->being_compacted) { continue; } - firstIndex = i; + if (firstIndex == -1) { + firstIndex = i; + } // Pick a file that has a key-range larger than the range // we picked in the previous call to PickCompaction. @@ -1612,7 +1614,7 @@ Compaction* VersionSet::PickCompactionBySize(int level) { break; } } - if (c->inputs_[0].empty()) { + if (c->inputs_[0].empty() && firstIndex != -1) { // Wrap-around to the beginning of the key space FileMetaData* f = current_->files_[level][firstIndex]; if (!f->being_compacted && !ParentFilesInCompaction(f, level)) {