Add two more options: disable block cache and make table cache shard number configuable

Summary:

as subject

Test Plan:

run db_bench and db_test

Reviewers: dhruba

Reviewed By: dhruba

Differential Revision: https://reviews.facebook.net/D6111
main
heyongqiang 12 years ago
parent 3e7e269292
commit 3096fa7534
  1. 13
      db/db_bench.cc
  2. 6
      db/db_impl.cc
  3. 2
      db/table_cache.cc
  4. 8
      include/leveldb/options.h
  5. 11
      util/options.cc

@ -183,6 +183,8 @@ static enum leveldb::CompressionType FLAGS_compression_type =
// other levels are compressed // other levels are compressed
static int FLAGS_min_level_to_compress = -1; static int FLAGS_min_level_to_compress = -1;
static int FLAGS_table_cache_numshardbits = 4;
// posix or hdfs environment // posix or hdfs environment
static leveldb::Env* FLAGS_env = leveldb::Env::Default(); static leveldb::Env* FLAGS_env = leveldb::Env::Default();
@ -897,6 +899,9 @@ class Benchmark {
Options options; Options options;
options.create_if_missing = !FLAGS_use_existing_db; options.create_if_missing = !FLAGS_use_existing_db;
options.block_cache = cache_; options.block_cache = cache_;
if (cache_ == NULL) {
options.no_block_cache = true;
}
options.write_buffer_size = FLAGS_write_buffer_size; options.write_buffer_size = FLAGS_write_buffer_size;
options.block_size = FLAGS_block_size; options.block_size = FLAGS_block_size;
options.filter_policy = filter_policy_; options.filter_policy = filter_policy_;
@ -932,6 +937,7 @@ class Benchmark {
options.delete_obsolete_files_period_micros = options.delete_obsolete_files_period_micros =
FLAGS_delete_obsolete_files_period_micros; FLAGS_delete_obsolete_files_period_micros;
options.rate_limit = FLAGS_rate_limit; options.rate_limit = FLAGS_rate_limit;
options.table_cache_numshardbits = FLAGS_table_cache_numshardbits;
Status s = DB::Open(options, FLAGS_db, &db_); Status s = DB::Open(options, FLAGS_db, &db_);
if (!s.ok()) { if (!s.ok()) {
fprintf(stderr, "open error: %s\n", s.ToString().c_str()); fprintf(stderr, "open error: %s\n", s.ToString().c_str());
@ -1256,6 +1262,13 @@ int main(int argc, char** argv) {
fprintf(stderr, "The cache cannot be sharded into 2**%d pieces\n", n); fprintf(stderr, "The cache cannot be sharded into 2**%d pieces\n", n);
exit(1); exit(1);
} }
} else if (sscanf(argv[i], "--table_cache_numshardbits=%d%c",
&n, &junk) == 1) {
if (n <= 0 || n > 20) {
fprintf(stderr, "The cache cannot be sharded into 2**%d pieces\n", n);
exit(1);
}
FLAGS_table_cache_numshardbits = n;
} else if (sscanf(argv[i], "--bloom_bits=%d%c", &n, &junk) == 1) { } else if (sscanf(argv[i], "--bloom_bits=%d%c", &n, &junk) == 1) {
FLAGS_bloom_bits = n; FLAGS_bloom_bits = n;
} else if (sscanf(argv[i], "--open_files=%d%c", &n, &junk) == 1) { } else if (sscanf(argv[i], "--open_files=%d%c", &n, &junk) == 1) {

@ -153,7 +153,7 @@ Options SanitizeOptions(const std::string& dbname,
result.info_log = NULL; result.info_log = NULL;
} }
} }
if (result.block_cache == NULL) { if (result.block_cache == NULL && !result.no_block_cache) {
result.block_cache = NewLRUCache(8 << 20); result.block_cache = NewLRUCache(8 << 20);
} }
if (src.compression_per_level != NULL) { if (src.compression_per_level != NULL) {
@ -1735,6 +1735,10 @@ Status DB::Open(const Options& options, const std::string& dbname,
DB** dbptr) { DB** dbptr) {
*dbptr = NULL; *dbptr = NULL;
if (options.block_cache != NULL && options.no_block_cache) {
return Status::InvalidArgument(
"no_block_cache is true while block_cache is not NULL");
}
DBImpl* impl = new DBImpl(options, dbname); DBImpl* impl = new DBImpl(options, dbname);
impl->mutex_.Lock(); impl->mutex_.Lock();
VersionEdit edit(impl->NumberLevels()); VersionEdit edit(impl->NumberLevels());

@ -39,7 +39,7 @@ TableCache::TableCache(const std::string& dbname,
: env_(options->env), : env_(options->env),
dbname_(dbname), dbname_(dbname),
options_(options), options_(options),
cache_(NewLRUCache(entries)) { cache_(NewLRUCache(entries, options->table_cache_numshardbits)) {
dbstatistics = (DBStatistics*)options->statistics; dbstatistics = (DBStatistics*)options->statistics;
} }

@ -271,6 +271,14 @@ struct Options {
// exceeds rate_limit. This is ignored when <= 1.0. // exceeds rate_limit. This is ignored when <= 1.0.
double rate_limit; double rate_limit;
// Disable block cache. If this is set to false,
// then no block cache should be used, and the block_cache should
// point to a NULL object.
bool no_block_cache;
// Number of shards used for table cache.
int table_cache_numshardbits;
// Create an Options object with default values for all fields. // Create an Options object with default values for all fields.
Options(); Options();

@ -43,6 +43,8 @@ Options::Options()
db_stats_log_interval(1800), db_stats_log_interval(1800),
db_log_dir(""), db_log_dir(""),
disable_seek_compaction(false), disable_seek_compaction(false),
no_block_cache(false),
table_cache_numshardbits(4),
max_log_file_size(0), max_log_file_size(0),
delete_obsolete_files_period_micros(0), delete_obsolete_files_period_micros(0),
rate_limit(0.0) { rate_limit(0.0) {
@ -61,7 +63,10 @@ Options::Dump(
Log(log," Options.write_buffer_size: %zd", write_buffer_size); Log(log," Options.write_buffer_size: %zd", write_buffer_size);
Log(log," Options.max_open_files: %d", max_open_files); Log(log," Options.max_open_files: %d", max_open_files);
Log(log," Options.block_cache: %p", block_cache); Log(log," Options.block_cache: %p", block_cache);
Log(log," Options.block_cache_size: %zd", block_cache->GetCapacity()); if (block_cache) {
Log(log," Options.block_cache_size: %zd",
block_cache->GetCapacity());
}
Log(log," Options.block_size: %zd", block_size); Log(log," Options.block_size: %zd", block_size);
Log(log,"Options.block_restart_interval: %d", block_restart_interval); Log(log,"Options.block_restart_interval: %d", block_restart_interval);
if (compression_per_level != NULL) { if (compression_per_level != NULL) {
@ -104,6 +109,10 @@ Options::Dump(
db_log_dir.c_str()); db_log_dir.c_str());
Log(log," Options.disable_seek_compaction: %d", Log(log," Options.disable_seek_compaction: %d",
disable_seek_compaction); disable_seek_compaction);
Log(log," Options.no_block_cache: %d",
no_block_cache);
Log(log," Options.table_cache_numshardbits: %d",
table_cache_numshardbits);
Log(log," Options.delete_obsolete_files_period_micros: %ld", Log(log," Options.delete_obsolete_files_period_micros: %ld",
delete_obsolete_files_period_micros); delete_obsolete_files_period_micros);
Log(log," Options.rate_limit: %.2f", Log(log," Options.rate_limit: %.2f",

Loading…
Cancel
Save