]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Print cache options to info log
authorYi Wu <yiwu@fb.com>
Thu, 22 Dec 2016 22:44:01 +0000 (14:44 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 22 Dec 2016 22:54:19 +0000 (14:54 -0800)
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
table/block_based_table_factory.cc
util/lru_cache.cc
util/lru_cache.h
util/sharded_cache.cc
util/sharded_cache.h
utilities/simulator_cache/sim_cache.cc

index ab5b9469f0849be85cf3618b1c45c67b3a53bcfd..e42d4a3509faa4035998860e0ce17e73ba6b9960 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <stdint.h>
 #include <memory>
+#include <string>
 #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&);
index f4e6902cc6ace0dcd35c8e61d9839b27b21edbb3..e0d49ad900b14104ca629377f2021b274938870c 100644 (file)
@@ -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<void*>(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<void*>(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<void*>(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<void*>(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);
index cac9a045921d9135ed741ec4e33741dac0e8f381..3d3de533670441e3a14e6d939cb40983256bb93c 100644 (file)
@@ -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 <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string>
 
 #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) {
index 807af9cbb1fa011af6f3e6cae47914de963ab9af..368f4bf978b1b258d3ad7d5221609ce159dd255f 100644 (file)
@@ -8,6 +8,8 @@
 // found in the LICENSE file. See the AUTHORS file for names of contributors.
 #pragma once
 
+#include <string>
+
 #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:
index 3a7fd02027d7bc841c6f72f31ef982be66587167..b529299a7ce678b139f24aae8d529d19668c5a43 100644 (file)
@@ -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 <string>
+
 #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
index 10e3450903bb55b2d3a35a93f4b1f7f4c03f3acf..bdb4e77c6a966d4c481885286e075d8f98fad7ea 100644 (file)
@@ -10,6 +10,7 @@
 #pragma once
 
 #include <atomic>
+#include <string>
 
 #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) {
index 3145c186fe600a169d57fb4847a2f0328278159c..dce2fd0cf99b45398a1e78d2d00c28d96733bcf8 100644 (file)
@@ -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> cache_;
   std::shared_ptr<Cache> key_only_cache_;