From e40092f6e3457b5e0baf33962e4c15f6136a26ee Mon Sep 17 00:00:00 2001 From: Yang Honggang Date: Sat, 21 Apr 2018 15:39:21 +0000 Subject: [PATCH] kv/RocksDBStore: fix rocksdb error when block cache is disabled Fixes: http://tracker.ceph.com/issues/23816 Signed-off-by: Yang Honggang --- src/kv/RocksDBStore.cc | 29 ++++++++++-------- src/test/objectstore/store_test.cc | 48 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 293ac91c349..7f72e23ed03 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -432,15 +432,17 @@ int RocksDBStore::load_rocksdb_options(bool create_if_missing, rocksdb::Options& std::bind(std::equal_to(), _1, "two_level"))) bbt_opts.index_type = rocksdb::BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch; - bbt_opts.cache_index_and_filter_blocks = - g_conf->get_val("rocksdb_cache_index_and_filter_blocks"); - bbt_opts.cache_index_and_filter_blocks_with_high_priority = - g_conf->get_val("rocksdb_cache_index_and_filter_blocks_with_high_priority"); + if (!bbt_opts.no_block_cache) { + bbt_opts.cache_index_and_filter_blocks = + g_conf->get_val("rocksdb_cache_index_and_filter_blocks"); + bbt_opts.cache_index_and_filter_blocks_with_high_priority = + g_conf->get_val("rocksdb_cache_index_and_filter_blocks_with_high_priority"); + bbt_opts.pin_l0_filter_and_index_blocks_in_cache = + g_conf->get_val("rocksdb_pin_l0_filter_and_index_blocks_in_cache"); + } bbt_opts.partition_filters = g_conf->get_val("rocksdb_partition_filters"); if (g_conf->get_val("rocksdb_metadata_block_size") > 0) bbt_opts.metadata_block_size = g_conf->get_val("rocksdb_metadata_block_size"); - bbt_opts.pin_l0_filter_and_index_blocks_in_cache = - g_conf->get_val("rocksdb_pin_l0_filter_and_index_blocks_in_cache"); opt.table_factory.reset(rocksdb::NewBlockBasedTableFactory(bbt_opts)); dout(10) << __func__ << " block size " << g_conf->rocksdb_block_size @@ -711,12 +713,15 @@ void RocksDBStore::get_statistics(Formatter *f) } if (g_conf->rocksdb_collect_memory_stats) { f->open_object_section("rocksdb_memtable_statistics"); - std::string str(stringify(bbt_opts.block_cache->GetUsage())); - f->dump_string("block_cache_usage", str.data()); - str.clear(); - str.append(stringify(bbt_opts.block_cache->GetPinnedUsage())); - f->dump_string("block_cache_pinned_blocks_usage", str); - str.clear(); + std::string str; + if (!bbt_opts.no_block_cache) { + str.append(stringify(bbt_opts.block_cache->GetUsage())); + f->dump_string("block_cache_usage", str.data()); + str.clear(); + str.append(stringify(bbt_opts.block_cache->GetPinnedUsage())); + f->dump_string("block_cache_pinned_blocks_usage", str); + str.clear(); + } db->GetProperty("rocksdb.cur-size-all-mem-tables", &str); f->dump_string("rocksdb_memtable_usage", str); str.clear(); diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 33a1da43790..031214a8726 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -6984,6 +6984,54 @@ TEST_P(StoreTest, BluestoreRepairTest) { cerr << "Completing" << std::endl; bstore->mount(); } +TEST_P(StoreTest, BluestoreStatistics) { + if (string(GetParam()) != "bluestore") + return; + + SetVal(g_conf, "rocksdb_perf", "true"); + SetVal(g_conf, "rocksdb_collect_compaction_stats", "true"); + SetVal(g_conf, "rocksdb_collect_extended_stats","true"); + SetVal(g_conf, "rocksdb_collect_memory_stats","true"); + + // disable cache + SetVal(g_conf, "bluestore_cache_size_ssd", "0"); + SetVal(g_conf, "bluestore_cache_size_hdd", "0"); + SetVal(g_conf, "bluestore_cache_size", "0"); + g_ceph_context->_conf->apply_changes(NULL); + + int r = store->umount(); + ASSERT_EQ(r, 0); + r = store->mount(); + ASSERT_EQ(r, 0); + + BlueStore* bstore = NULL; + EXPECT_NO_THROW(bstore = dynamic_cast (store.get())); + + coll_t cid; + ghobject_t hoid(hobject_t("test_db_statistics", "", CEPH_NOSNAP, 0, 0, "")); + auto ch = bstore->create_new_collection(cid); + bufferlist bl; + bl.append("0123456789abcdefghi"); + { + ObjectStore::Transaction t; + t.create_collection(cid, 0); + t.touch(cid, hoid); + t.write(cid, hoid, 0, bl.length(), bl); + cerr << "Write object" << std::endl; + r = queue_transaction(bstore, ch, std::move(t)); + ASSERT_EQ(r, 0); + } + { + bufferlist readback; + r = store->read(ch, hoid, 0, bl.length(), readback); + ASSERT_EQ(r, bl.length()); + ASSERT_TRUE(bl_eq(bl, readback)); + } + Formatter *f = Formatter::create("store_test", "json-pretty", "json-pretty"); + EXPECT_NO_THROW(store->get_db_statistics(f)); + f->flush(cout); + cout << std::endl; +} #endif // WITH_BLUESTORE int main(int argc, char **argv) { -- 2.39.5