Commit 20d39998 authored by Huachao Huang's avatar Huachao Huang Committed by zhangjinpeng1987

Fix and test when disable statistics (#172)

parent 5e3bfdc7
......@@ -1607,7 +1607,10 @@ size_t crocksdb_options_get_block_cache_usage(crocksdb_options_t *opt) {
if (opt && opt->rep.table_factory != nullptr) {
void* table_opt = opt->rep.table_factory->GetOptions();
if (table_opt && strcmp(opt->rep.table_factory->Name(), block_base_table_str) == 0) {
return static_cast<BlockBasedTableOptions*>(table_opt)->block_cache->GetUsage();
auto opts = static_cast<BlockBasedTableOptions*>(table_opt);
if (opts->block_cache) {
return opts->block_cache->GetUsage();
}
}
}
return 0;
......@@ -1966,7 +1969,10 @@ void crocksdb_options_enable_statistics(crocksdb_options_t* opt, unsigned char v
}
void crocksdb_options_reset_statistics(crocksdb_options_t* opt) {
opt->rep.statistics->Reset();
auto statistics = opt->rep.statistics.get();
if (statistics) {
statistics->Reset();
}
}
void crocksdb_options_set_num_levels(crocksdb_options_t* opt, int n) {
......
......@@ -369,6 +369,16 @@ fn test_get_block_cache_usage() {
assert!(db.get_options().get_block_cache_usage() > 0);
}
#[test]
fn test_disable_block_cache() {
let mut cf_opts = ColumnFamilyOptions::new();
assert_eq!(cf_opts.get_block_cache_usage(), 0);
let mut block_opts = BlockBasedOptions::new();
block_opts.set_no_block_cache(true);
cf_opts.set_block_based_table_factory(&block_opts);
assert_eq!(cf_opts.get_block_cache_usage(), 0);
}
#[test]
fn test_set_level_compaction_dynamic_level_bytes() {
let path = TempDir::new("_rust_rocksdb_level_compaction_dynamic_level_bytes").expect("");
......
......@@ -52,3 +52,35 @@ fn test_db_statistics() {
.unwrap();
assert_eq!(get_micros.max, 0.0);
}
#[test]
fn test_disable_db_statistics() {
let path = TempDir::new("_rust_rocksdb_statistics").expect("");
let mut opts = DBOptions::new();
opts.create_if_missing(true);
opts.enable_statistics(false);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let wopts = WriteOptions::new();
db.put_opt(b"k0", b"a", &wopts).unwrap();
db.put_opt(b"k1", b"b", &wopts).unwrap();
db.put_opt(b"k2", b"c", &wopts).unwrap();
db.flush(true /* sync */).unwrap(); // flush memtable to sst file.
assert_eq!(db.get(b"k0").unwrap().unwrap(), b"a");
assert_eq!(db.get(b"k1").unwrap().unwrap(), b"b");
assert_eq!(db.get(b"k2").unwrap().unwrap(), b"c");
assert_eq!(db.get_statistics_ticker_count(TickerType::BlockCacheHit), 0);
assert_eq!(
db.get_and_reset_statistics_ticker_count(TickerType::BlockCacheHit),
0
);
assert!(
db.get_statistics_histogram_string(HistogramType::GetMicros)
.is_none()
);
assert!(
db.get_statistics_histogram(HistogramType::GetMicros)
.is_none()
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment