diff --git a/include/leveldb/options.h b/include/leveldb/options.h index 28aaba485..4e6d5e0d6 100644 --- a/include/leveldb/options.h +++ b/include/leveldb/options.h @@ -347,7 +347,7 @@ struct Options { // Set appropriate parameters for bulk loading. // The reason that this is a function that returns "this" instead of a - // constructure is to enable chaining of multiple similar calls in the future. + // constructor is to enable chaining of multiple similar calls in the future. // // All data will be in level 0 without any automatic compaction. // It's recommended to manually call CompactRange(NULL, NULL) before reading diff --git a/util/options.cc b/util/options.cc index 9597b7c85..a9d7719dd 100644 --- a/util/options.cc +++ b/util/options.cc @@ -161,17 +161,40 @@ Options::Dump(Logger* log) const manifest_preallocation_size); } // Options::Dump +// +// The goal of this method is to create a configuration that +// allows an application to write all files into L0 and +// then do a single compaction to output all files into L1. Options* Options::PrepareForBulkLoad() { + // never slowdown ingest. level0_file_num_compaction_trigger = (1<<30); level0_slowdown_writes_trigger = (1<<30); level0_stop_writes_trigger = (1<<30); + + // no auto compactions please. The application should issue a + // manual compaction after all data is loaded into L0. disable_auto_compactions = true; disable_seek_compaction = true; disableDataSync = true; + + // A manual compaction run should pick all files in L0 in + // a single compaction run. source_compaction_factor = (1<<30); + // It is better to have only 2 levels, otherwise a manual + // compaction would compact at every possible level, thereby + // increasing the total time needed for compactions. + num_levels = 2; + + // Prevent a memtable flush to automatically promote files + // to L1. This is helpful so that all files that are + // input to the manual compaction are all at L0. + max_background_compactions = 2; + + // The compaction would create large files in L1. + target_file_size_base = 256 * 1024 * 1024; return this; }