Support to disable background compactions on a database.

Summary:
This option is needed for fast bulk uploads. The goal is to load
all the data into files in L0 without any interference from
background compactions.

Test Plan: make clean check

Reviewers: sheki

Reviewed By: sheki

CC: leveldb

Differential Revision: https://reviews.facebook.net/D6849
This commit is contained in:
Dhruba Borthakur 2012-11-20 15:45:41 -08:00
parent 3754f2f4ff
commit fbb73a4ac3
4 changed files with 17 additions and 3 deletions

View File

@ -218,6 +218,9 @@ static int FLAGS_max_grandparent_overlap_factor;
// Run read only benchmarks.
static bool FLAGS_read_only = false;
// Do not auto trigger compactions
static bool FLAGS_disable_auto_compactions = false;
extern bool useOsBuffer;
extern bool useFsReadAhead;
extern bool useMmapRead;
@ -974,6 +977,7 @@ class Benchmark {
options.table_cache_numshardbits = FLAGS_table_cache_numshardbits;
options.max_grandparent_overlap_factor =
FLAGS_max_grandparent_overlap_factor;
options.disable_auto_compactions = FLAGS_disable_auto_compactions;
Status s;
if(FLAGS_read_only) {
s = DB::OpenForReadOnly(options, FLAGS_db, &db_);
@ -1424,6 +1428,9 @@ int main(int argc, char** argv) {
} else if (sscanf(argv[i], "--max_grandparent_overlap_factor=%d%c",
&n, &junk) == 1) {
FLAGS_max_grandparent_overlap_factor = n;
} else if (sscanf(argv[i], "--disable_auto_compactions=%d%c",
&n, &junk) == 1 && (n == 0 || n ==1)) {
FLAGS_disable_auto_compactions = n;
} else {
fprintf(stderr, "Invalid flag '%s'\n", argv[i]);
exit(1);

View File

@ -1012,7 +1012,7 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress,
}
}
Compaction* c;
Compaction* c = NULL;
bool is_manual = (manual_compaction_ != NULL) &&
(manual_compaction_->in_progress == false);
InternalKey manual_end;
@ -1031,7 +1031,7 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress,
(m->begin ? m->begin->DebugString().c_str() : "(begin)"),
(m->end ? m->end->DebugString().c_str() : "(end)"),
(m->done ? "(end)" : manual_end.DebugString().c_str()));
} else {
} else if (!options_.disable_auto_compactions) {
c = versions_->PickCompaction();
}

View File

@ -330,6 +330,10 @@ struct Options {
bool (*CompactionFilter)(void* compaction_filter_args,
int level, const Slice& key,
const Slice& existing_value, Slice** new_value);
// Disable automatic compactions. Manual compactions can still
// be issued on this database.
bool disable_auto_compactions;
};
// Options that control read operations

View File

@ -51,7 +51,8 @@ Options::Options()
no_block_cache(false),
table_cache_numshardbits(4),
compaction_filter_args(NULL),
CompactionFilter(NULL) {
CompactionFilter(NULL),
disable_auto_compactions(false) {
}
void
@ -134,6 +135,8 @@ Options::Dump(
compaction_filter_args);
Log(log," Options.CompactionFilter: %p",
CompactionFilter);
Log(log," Options.disable_auto_compactions: %d",
disable_auto_compactions);
} // Options::Dump
} // namespace leveldb