Fix asserts so that "make check OPT=-g" works on performance branch

Summary:
Compilation used to fail with the error:
db/version_set.cc:1773: error: ‘number_of_files_to_sort_’ is not a member of ‘leveldb::VersionSet’

I created a new method called CheckConsistencyForDeletes() so that
all the high cost checking is done only when OPT=-g is specified.

I also fixed a bug in PickCompactionBySize that was triggered when
OPT=-g was switched on. The base_index in the compaction record
was not set correctly.

Test Plan: make check OPT=-g

Differential Revision: https://reviews.facebook.net/D6687
main
Dhruba Borthakur 12 years ago
parent 95dda37858
commit 43d9a8225a
  1. 49
      db/version_set.cc

@ -734,6 +734,38 @@ class VersionSet::Builder {
#endif
}
void CheckConsistencyForDeletes(VersionEdit* edit, int number, int level) {
#ifndef NDEBUG
// a file to be deleted better exist in the previous version
bool found = false;
for (int l = 0; !found && l < edit->number_levels_; l++) {
const std::vector<FileMetaData*>& base_files = base_->files_[l];
for (int i = 0; i < base_files.size(); i++) {
FileMetaData* f = base_files[i];
if (f->number == number) {
found = true;
break;
}
}
}
// if the file did not exist in the previous version, then it
// is possibly moved from lower level to higher level in current
// version
for (int l = level+1; !found && l < edit->number_levels_; l++) {
const FileSet* added = levels_[l].added_files;
for (FileSet::const_iterator added_iter = added->begin();
added_iter != added->end(); ++added_iter) {
FileMetaData* f = *added_iter;
if (f->number == number) {
found = true;
break;
}
}
}
assert(found);
#endif
}
// Apply all of the edits in *edit to the current state.
void Apply(VersionEdit* edit) {
CheckConsistency(base_);
@ -753,18 +785,7 @@ class VersionSet::Builder {
const int level = iter->first;
const uint64_t number = iter->second;
levels_[level].deleted_files.insert(number);
#ifndef NDEBUG
// none of the files to be deleted could have been added
// by a concurrent compaction process
const FileSet* added = levels_[level].added_files;
for (FileSet::const_iterator added_iter = added->begin();
added_iter != added->end();
++added_iter) {
FileMetaData* f = *added_iter;
assert(f->number != number);
}
#endif
CheckConsistencyForDeletes(edit, number, level);
}
// Add new files
@ -1771,7 +1792,7 @@ Compaction* VersionSet::PickCompactionBySize(int level) {
// check to verify files are arranged in descending size
assert((i == file_size.size() - 1) ||
(i >= VersionSet::number_of_files_to_sort_-1) ||
(i >= Version::number_of_files_to_sort_-1) ||
(f->file_size >= current_->files_[level][file_size[i+1]]->file_size));
// do not pick a file to compact if it is being compacted
@ -1796,7 +1817,7 @@ Compaction* VersionSet::PickCompactionBySize(int level) {
continue;
}
c->inputs_[0].push_back(f);
c->base_index_ = i;
c->base_index_ = index;
c->parent_index_ = parent_index;
break;
}

Loading…
Cancel
Save