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

View File

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

View File

@ -330,6 +330,10 @@ struct Options {
bool (*CompactionFilter)(void* compaction_filter_args, bool (*CompactionFilter)(void* compaction_filter_args,
int level, const Slice& key, int level, const Slice& key,
const Slice& existing_value, Slice** new_value); 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 // Options that control read operations

View File

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