]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
kv/RocksDBStore: fix rocksdb error when block cache is disabled
authorYang Honggang <yanghonggang@umcloud.com>
Sat, 21 Apr 2018 15:39:21 +0000 (15:39 +0000)
committerYang Honggang <yanghonggang@umcloud.com>
Fri, 27 Apr 2018 17:46:36 +0000 (17:46 +0000)
Fixes: http://tracker.ceph.com/issues/23816
Signed-off-by: Yang Honggang <yanghonggang@umcloud.com>
src/kv/RocksDBStore.cc
src/test/objectstore/store_test.cc

index 293ac91c34924722d67532e3388ed5d71304e8d7..7f72e23ed0324318b44dc40cf935b0f42949a076 100644 (file)
@@ -432,15 +432,17 @@ int RocksDBStore::load_rocksdb_options(bool create_if_missing, rocksdb::Options&
                                    std::bind(std::equal_to<std::string>(), _1,
                                              "two_level")))
     bbt_opts.index_type = rocksdb::BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch;
-  bbt_opts.cache_index_and_filter_blocks = 
-      g_conf->get_val<bool>("rocksdb_cache_index_and_filter_blocks");
-  bbt_opts.cache_index_and_filter_blocks_with_high_priority = 
-      g_conf->get_val<bool>("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<bool>("rocksdb_cache_index_and_filter_blocks");
+    bbt_opts.cache_index_and_filter_blocks_with_high_priority =
+        g_conf->get_val<bool>("rocksdb_cache_index_and_filter_blocks_with_high_priority");
+    bbt_opts.pin_l0_filter_and_index_blocks_in_cache =
+      g_conf->get_val<bool>("rocksdb_pin_l0_filter_and_index_blocks_in_cache");
+  }
   bbt_opts.partition_filters = g_conf->get_val<bool>("rocksdb_partition_filters");
   if (g_conf->get_val<uint64_t>("rocksdb_metadata_block_size") > 0)
     bbt_opts.metadata_block_size = g_conf->get_val<uint64_t>("rocksdb_metadata_block_size");
-  bbt_opts.pin_l0_filter_and_index_blocks_in_cache = 
-      g_conf->get_val<bool>("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();
index 33a1da43790025ead689664975d57823506d93d4..031214a872647051ab5578104fd870d0fd94f505 100644 (file)
@@ -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<BlueStore*> (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) {