Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isssue 178 patch:Compaction causes previously deleted value to reappear #205

Open
cmumford opened this issue Sep 9, 2014 · 1 comment
Open
Labels

Comments

@cmumford
Copy link
Contributor

cmumford commented Sep 9, 2014

Original issue 199 created by zju.zhengmh on 2013-08-21T06:39:43.000Z:

In Leveldb 1.11, it fixed isssue 178 by not pick level-0 files when do CompactRange.
But we can pick level-0 oldest files for CompactRange, which we ca sort files if it is level0. It will be more reasonable, since it can avoid too much level-0 files.

diff --git a/db/version_set.cc b/db/version_set.cc
index 4fd1dde..21b76ee 100644
--- a/db/version_set.cc
+++ b/db/version_set.cc
@@ -289,6 +289,11 @@ static bool NewestFirst(FileMetaData* a, FileMetaData* b) {
   return a->number > b->number;
 }

+static bool OldestFirst(FileMetaData* a, FileMetaData* b) {
+  return a->number < b->number;
+}
+
+
 Status Version::Get(const ReadOptions& options,
                     const LookupKey& k,
                     std::string* value,
@@ -1333,17 +1338,19 @@ Compaction* VersionSet::CompactRange(
   // Avoid compacting too much in one shot in case the range is large.
   // But we cannot do this for level-0 since level-0 files can overlap
   // and we must not pick one file and drop another older file if the
-  // two files overlap.
-  if (level > 0) {
-    const uint64_t limit = MaxFileSizeForLevel(level);
-    uint64_t total = 0;
-    for (size_t i = 0; i < inputs.size(); i++) {
-      uint64_t s = inputs[i]->file_size;
-      total += s;
-      if (total >= limit) {
-        inputs.resize(i + 1);
-        break;
-      }
+  // two files overlap. For level-0, we can pick oldest files.
+  if (level == 0) {
+    std::sort(inputs.begin(), inputs.end(), OldestFirst);
+  }
+
+  const uint64_t limit = MaxFileSizeForLevel(level);
+  uint64_t total = 0;
+  for (size_t i = 0; i < inputs.size(); i++) {
+    uint64_t s = inputs[i]->file_size;
+    total += s;
+    if (total >= limit) {
+      inputs.resize(i + 1);
+      break;
     }
   }
@cmumford cmumford self-assigned this Sep 9, 2014
@cmumford cmumford removed their assignment Jan 16, 2016
@originalsouth
Copy link

Is this bug still present or is it fixed by #339 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants