From ab48c165a974ee1afc58a547393f2355579ba468 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Thu, 22 Dec 2016 14:44:01 -0800 Subject: [PATCH] Print cache options to info log Summary: Improve cache options logging to info log. Also print the value of cache_index_and_filter_blocks_with_high_priority. Closes https://github.com/facebook/rocksdb/pull/1709 Differential Revision: D4358776 Pulled By: yiwu-arbug fbshipit-source-id: 8f030a0 --- include/rocksdb/cache.h | 3 ++ table/block_based_table_factory.cc | 38 ++++++++++++++++++-------- util/lru_cache.cc | 16 +++++++++++ util/lru_cache.h | 4 +++ util/sharded_cache.cc | 27 ++++++++++++++++++ util/sharded_cache.h | 3 ++ utilities/simulator_cache/sim_cache.cc | 10 +++++++ 7 files changed, 89 insertions(+), 12 deletions(-) diff --git a/include/rocksdb/cache.h b/include/rocksdb/cache.h index ab5b9469f..e42d4a350 100644 --- a/include/rocksdb/cache.h +++ b/include/rocksdb/cache.h @@ -24,6 +24,7 @@ #include #include +#include #include "rocksdb/slice.h" #include "rocksdb/statistics.h" #include "rocksdb/status.h" @@ -167,6 +168,8 @@ class Cache { // Prerequisit: no entry is referenced. virtual void EraseUnRefEntries() = 0; + virtual std::string GetPrintableOptions() const { return ""; } + private: // No copying allowed Cache(const Cache&); diff --git a/table/block_based_table_factory.cc b/table/block_based_table_factory.cc index f4e6902cc..e0d49ad90 100644 --- a/table/block_based_table_factory.cc +++ b/table/block_based_table_factory.cc @@ -115,6 +115,10 @@ std::string BlockBasedTableFactory::GetPrintableTableOptions() const { snprintf(buffer, kBufferSize, " cache_index_and_filter_blocks: %d\n", table_options_.cache_index_and_filter_blocks); ret.append(buffer); + snprintf(buffer, kBufferSize, + " cache_index_and_filter_blocks_with_high_priority: %d\n", + table_options_.cache_index_and_filter_blocks_with_high_priority); + ret.append(buffer); snprintf(buffer, kBufferSize, " pin_l0_filter_and_index_blocks_in_cache: %d\n", table_options_.pin_l0_filter_and_index_blocks_in_cache); @@ -135,9 +139,28 @@ std::string BlockBasedTableFactory::GetPrintableTableOptions() const { static_cast(table_options_.block_cache.get())); ret.append(buffer); if (table_options_.block_cache) { - snprintf(buffer, kBufferSize, " block_cache_size: %" ROCKSDB_PRIszt "\n", - table_options_.block_cache->GetCapacity()); - ret.append(buffer); + const char* block_cache_name = table_options_.block_cache->Name(); + if (block_cache_name != nullptr) { + snprintf(buffer, kBufferSize, " block_cache_name: %s\n", + block_cache_name); + ret.append(buffer); + } + ret.append(" block_cache_options:\n"); + ret.append(table_options_.block_cache->GetPrintableOptions()); + } + snprintf(buffer, kBufferSize, " block_cache_compressed: %p\n", + static_cast(table_options_.block_cache_compressed.get())); + ret.append(buffer); + if (table_options_.block_cache_compressed) { + const char* block_cache_compressed_name = + table_options_.block_cache_compressed->Name(); + if (block_cache_compressed_name != nullptr) { + snprintf(buffer, kBufferSize, " block_cache_name: %s\n", + block_cache_compressed_name); + ret.append(buffer); + } + ret.append(" block_cache_compressed_options:\n"); + ret.append(table_options_.block_cache_compressed->GetPrintableOptions()); } snprintf(buffer, kBufferSize, " persistent_cache: %p\n", static_cast(table_options_.persistent_cache.get())); @@ -147,15 +170,6 @@ std::string BlockBasedTableFactory::GetPrintableTableOptions() const { ret.append(buffer); ret.append(table_options_.persistent_cache->GetPrintableOptions()); } - snprintf(buffer, kBufferSize, " block_cache_compressed: %p\n", - static_cast(table_options_.block_cache_compressed.get())); - ret.append(buffer); - if (table_options_.block_cache_compressed) { - snprintf(buffer, kBufferSize, - " block_cache_compressed_size: %" ROCKSDB_PRIszt "\n", - table_options_.block_cache_compressed->GetCapacity()); - ret.append(buffer); - } snprintf(buffer, kBufferSize, " block_size: %" ROCKSDB_PRIszt "\n", table_options_.block_size); ret.append(buffer); diff --git a/util/lru_cache.cc b/util/lru_cache.cc index cac9a0459..3d3de5336 100644 --- a/util/lru_cache.cc +++ b/util/lru_cache.cc @@ -7,11 +7,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + #include "util/lru_cache.h" #include #include #include +#include #include "util/mutexlock.h" @@ -408,6 +413,17 @@ size_t LRUCacheShard::GetPinnedUsage() const { return usage_ - lru_usage_; } +std::string LRUCacheShard::GetPrintableOptions() const { + const int kBufferSize = 200; + char buffer[kBufferSize]; + { + MutexLock l(&mutex_); + snprintf(buffer, kBufferSize, " high_pri_pool_ratio: %.3lf\n", + high_pri_pool_ratio_); + } + return std::string(buffer); +} + LRUCache::LRUCache(size_t capacity, int num_shard_bits, bool strict_capacity_limit, double high_pri_pool_ratio) : ShardedCache(capacity, num_shard_bits, strict_capacity_limit) { diff --git a/util/lru_cache.h b/util/lru_cache.h index 807af9cbb..368f4bf97 100644 --- a/util/lru_cache.h +++ b/util/lru_cache.h @@ -8,6 +8,8 @@ // found in the LICENSE file. See the AUTHORS file for names of contributors. #pragma once +#include + #include "util/sharded_cache.h" #include "port/port.h" @@ -190,6 +192,8 @@ class LRUCacheShard : public CacheShard { virtual void EraseUnRefEntries() override; + virtual std::string GetPrintableOptions() const override; + void TEST_GetLRUList(LRUHandle** lru, LRUHandle** lru_low_pri); private: diff --git a/util/sharded_cache.cc b/util/sharded_cache.cc index 3a7fd0202..b529299a7 100644 --- a/util/sharded_cache.cc +++ b/util/sharded_cache.cc @@ -7,7 +7,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + #include "util/sharded_cache.h" + +#include + #include "util/mutexlock.h" namespace rocksdb { @@ -114,4 +121,24 @@ void ShardedCache::EraseUnRefEntries() { } } +std::string ShardedCache::GetPrintableOptions() const { + std::string ret; + ret.reserve(20000); + const int kBufferSize = 200; + char buffer[kBufferSize]; + { + MutexLock l(&capacity_mutex_); + snprintf(buffer, kBufferSize, " capacity : %" ROCKSDB_PRIszt "\n", + capacity_); + ret.append(buffer); + snprintf(buffer, kBufferSize, " num_shard_bits : %d\n", num_shard_bits_); + ret.append(buffer); + snprintf(buffer, kBufferSize, " strict_capacity_limit : %d\n", + strict_capacity_limit_); + ret.append(buffer); + } + ret.append(GetShard(0)->GetPrintableOptions()); + return ret; +} + } // namespace rocksdb diff --git a/util/sharded_cache.h b/util/sharded_cache.h index 10e345090..bdb4e77c6 100644 --- a/util/sharded_cache.h +++ b/util/sharded_cache.h @@ -10,6 +10,7 @@ #pragma once #include +#include #include "port/port.h" #include "rocksdb/cache.h" @@ -37,6 +38,7 @@ class CacheShard { virtual void ApplyToAllCacheEntries(void (*callback)(void*, size_t), bool thread_safe) = 0; virtual void EraseUnRefEntries() = 0; + virtual std::string GetPrintableOptions() const { return ""; } }; // Generic cache interface which shards cache by hash of keys. 2^num_shard_bits @@ -72,6 +74,7 @@ class ShardedCache : public Cache { virtual void ApplyToAllCacheEntries(void (*callback)(void*, size_t), bool thread_safe) override; virtual void EraseUnRefEntries() override; + virtual std::string GetPrintableOptions() const override; private: static inline uint32_t HashSlice(const Slice& s) { diff --git a/utilities/simulator_cache/sim_cache.cc b/utilities/simulator_cache/sim_cache.cc index 3145c186f..dce2fd0cf 100644 --- a/utilities/simulator_cache/sim_cache.cc +++ b/utilities/simulator_cache/sim_cache.cc @@ -144,6 +144,16 @@ class SimCacheImpl : public SimCache { return res; } + virtual std::string GetPrintableOptions() const override { + std::string ret; + ret.reserve(20000); + ret.append(" cache_options:\n"); + ret.append(cache_->GetPrintableOptions()); + ret.append(" sim_cache_options:\n"); + ret.append(key_only_cache_->GetPrintableOptions()); + return ret; + } + private: std::shared_ptr cache_; std::shared_ptr key_only_cache_;