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
static int FLAGS_min_level_to_compress = -1;
static int FLAGS_table_cache_numshardbits = 4;
// posix or hdfs environment
static leveldb::Env* FLAGS_env = leveldb::Env::Default();
@ -897,6 +899,9 @@ class Benchmark {
Options options;
options.create_if_missing = !FLAGS_use_existing_db;
options.block_cache = cache_;
if (cache_ == NULL) {
options.no_block_cache = true;
}
options.write_buffer_size = FLAGS_write_buffer_size;
options.block_size = FLAGS_block_size;
options.filter_policy = filter_policy_;
@ -932,6 +937,7 @@ class Benchmark {
options.delete_obsolete_files_period_micros =
FLAGS_delete_obsolete_files_period_micros;
options.rate_limit = FLAGS_rate_limit;
options.table_cache_numshardbits = FLAGS_table_cache_numshardbits;
Status s = DB::Open(options, FLAGS_db, &db_);
if (!s.ok()) {
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);
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) {
FLAGS_bloom_bits = n;
} 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;
}
}
if (result.block_cache == NULL) {
if (result.block_cache == NULL && !result.no_block_cache) {
result.block_cache = NewLRUCache(8 << 20);
}
if (src.compression_per_level != NULL) {
@ -1735,6 +1735,10 @@ Status DB::Open(const Options& options, const std::string& dbname,
DB** dbptr) {
*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);
impl->mutex_.Lock();
VersionEdit edit(impl->NumberLevels());

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

@ -271,6 +271,14 @@ struct Options {
// exceeds rate_limit. This is ignored when <= 1.0.
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.
Options();

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

Loading…
Cancel
Save