diff --git a/db/db_bench.cc b/db/db_bench.cc index 0d364c6f6..bf69c0d82 100644 --- a/db/db_bench.cc +++ b/db/db_bench.cc @@ -161,6 +161,9 @@ static int FLAGS_level0_slowdown_writes_trigger = 8; // setting is 9 gets for every 1 put. static int FLAGS_readwritepercent = 90; +// Option to disable compation triggered by read. +static int FLAGS_disable_seek_compaction = false; + // Algorithm to use to compress the database static enum leveldb::CompressionType FLAGS_compression_type = leveldb::kSnappyCompression; @@ -850,6 +853,7 @@ class Benchmark { options.level0_slowdown_writes_trigger = FLAGS_level0_slowdown_writes_trigger; options.compression = FLAGS_compression_type; + options.disable_seek_compaction = FLAGS_disable_seek_compaction; Status s = DB::Open(options, FLAGS_db, &db_); if (!s.ok()) { fprintf(stderr, "open error: %s\n", s.ToString().c_str()); @@ -1245,6 +1249,9 @@ int main(int argc, char** argv) { else { fprintf(stdout, "Cannot parse %s\n", argv[i]); } + } else if (sscanf(argv[i], "--disable_seek_compaction=%d%c", &n, &junk) == 1 + && (n == 0 || n == 1)) { + FLAGS_disable_seek_compaction = n; } else { fprintf(stderr, "Invalid flag '%s'\n", argv[i]); exit(1); diff --git a/db/version_set.cc b/db/version_set.cc index 86f933c3f..1fcf831c8 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1380,7 +1380,7 @@ Compaction* VersionSet::PickCompaction() { // Wrap-around to the beginning of the key space c->inputs_[0].push_back(current_->files_[level][0]); } - } else if (seek_compaction) { + } else if (seek_compaction && !options_->disable_seek_compaction) { level = current_->file_to_compact_level_; c = new Compaction(level, MaxFileSizeForLevel(level), MaxGrandParentOverlapBytes(level), NumberLevels()); diff --git a/include/leveldb/options.h b/include/leveldb/options.h index 8644c7ba8..f49f833ae 100644 --- a/include/leveldb/options.h +++ b/include/leveldb/options.h @@ -220,6 +220,12 @@ struct Options { // name's prefix. std::string db_log_dir; + // Disable compaction triggered by seek. + // With bloomfilter and fast storage, a miss on one level + // is very cheap if the file handle is cached in table cache + // (which is true if max_open_files is large). + bool disable_seek_compaction; + // Create an Options object with default values for all fields. Options(); diff --git a/util/options.cc b/util/options.cc index 8fb8000d0..bd9027be9 100644 --- a/util/options.cc +++ b/util/options.cc @@ -39,7 +39,8 @@ Options::Options() disableDataSync(false), use_fsync(false), db_stats_log_interval(1800), - db_log_dir("") { + db_log_dir(""), + disable_seek_compaction(false) { } void @@ -87,7 +88,8 @@ Options::Dump( max_grandparent_overlap_factor); Log(log," Options.db_log_dir: %s", db_log_dir.c_str()); - + Log(log," Options.disable_seek_compaction: %d", + disable_seek_compaction); } // Options::Dump