]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/table/persistent_cache_helper.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / table / persistent_cache_helper.cc
index 21d3bf734caa1bc19bd6dad5bb9146aaefd12e41..eece8100e6c26151b3c9c592e11be0a33bff3a73 100644 (file)
@@ -4,28 +4,28 @@
 //  (found in the LICENSE.Apache file in the root directory).
 
 #include "table/persistent_cache_helper.h"
+
 #include "table/block_based/block_based_table_reader.h"
 #include "table/format.h"
 
 namespace ROCKSDB_NAMESPACE {
 
-void PersistentCacheHelper::InsertRawPage(
+const PersistentCacheOptions PersistentCacheOptions::kEmpty;
+
+void PersistentCacheHelper::InsertSerialized(
     const PersistentCacheOptions& cache_options, const BlockHandle& handle,
     const char* data, const size_t size) {
   assert(cache_options.persistent_cache);
   assert(cache_options.persistent_cache->IsCompressed());
 
-  // construct the page key
-  char cache_key[BlockBasedTable::kMaxCacheKeyPrefixSize + kMaxVarint64Length];
-  auto key = BlockBasedTable::GetCacheKey(cache_options.key_prefix.c_str(),
-                                          cache_options.key_prefix.size(),
-                                          handle, cache_key);
-  // insert content to cache
-  cache_options.persistent_cache->Insert(key, data, size)
+  CacheKey key =
+      BlockBasedTable::GetCacheKey(cache_options.base_cache_key, handle);
+
+  cache_options.persistent_cache->Insert(key.AsSlice(), data, size)
       .PermitUncheckedError();
 }
 
-void PersistentCacheHelper::InsertUncompressedPage(
+void PersistentCacheHelper::InsertUncompressed(
     const PersistentCacheOptions& cache_options, const BlockHandle& handle,
     const BlockContents& contents) {
   assert(cache_options.persistent_cache);
@@ -34,35 +34,30 @@ void PersistentCacheHelper::InsertUncompressedPage(
   // (1) content is cacheable
   // (2) content is not compressed
 
-  // construct the page key
-  char cache_key[BlockBasedTable::kMaxCacheKeyPrefixSize + kMaxVarint64Length];
-  auto key = BlockBasedTable::GetCacheKey(cache_options.key_prefix.c_str(),
-                                          cache_options.key_prefix.size(),
-                                          handle, cache_key);
-  // insert block contents to page cache
+  CacheKey key =
+      BlockBasedTable::GetCacheKey(cache_options.base_cache_key, handle);
+
   cache_options.persistent_cache
-      ->Insert(key, contents.data.data(), contents.data.size())
+      ->Insert(key.AsSlice(), contents.data.data(), contents.data.size())
       .PermitUncheckedError();
   ;
 }
 
-Status PersistentCacheHelper::LookupRawPage(
+Status PersistentCacheHelper::LookupSerialized(
     const PersistentCacheOptions& cache_options, const BlockHandle& handle,
-    std::unique_ptr<char[]>* raw_data, const size_t raw_data_size) {
+    std::unique_ptr<char[]>* out_data, const size_t expected_data_size) {
 #ifdef NDEBUG
-  (void)raw_data_size;
+  (void)expected_data_size;
 #endif
   assert(cache_options.persistent_cache);
   assert(cache_options.persistent_cache->IsCompressed());
 
-  // construct the page key
-  char cache_key[BlockBasedTable::kMaxCacheKeyPrefixSize + kMaxVarint64Length];
-  auto key = BlockBasedTable::GetCacheKey(cache_options.key_prefix.c_str(),
-                                          cache_options.key_prefix.size(),
-                                          handle, cache_key);
-  // Lookup page
+  CacheKey key =
+      BlockBasedTable::GetCacheKey(cache_options.base_cache_key, handle);
+
   size_t size;
-  Status s = cache_options.persistent_cache->Lookup(key, raw_data, &size);
+  Status s =
+      cache_options.persistent_cache->Lookup(key.AsSlice(), out_data, &size);
   if (!s.ok()) {
     // cache miss
     RecordTick(cache_options.statistics, PERSISTENT_CACHE_MISS);
@@ -70,13 +65,15 @@ Status PersistentCacheHelper::LookupRawPage(
   }
 
   // cache hit
-  assert(raw_data_size == handle.size() + kBlockTrailerSize);
-  assert(size == raw_data_size);
+  // Block-based table is assumed
+  assert(expected_data_size ==
+         handle.size() + BlockBasedTable::kBlockTrailerSize);
+  assert(size == expected_data_size);
   RecordTick(cache_options.statistics, PERSISTENT_CACHE_HIT);
   return Status::OK();
 }
 
-Status PersistentCacheHelper::LookupUncompressedPage(
+Status PersistentCacheHelper::LookupUncompressed(
     const PersistentCacheOptions& cache_options, const BlockHandle& handle,
     BlockContents* contents) {
   assert(cache_options.persistent_cache);
@@ -87,15 +84,13 @@ Status PersistentCacheHelper::LookupUncompressedPage(
     return Status::NotFound();
   }
 
-  // construct the page key
-  char cache_key[BlockBasedTable::kMaxCacheKeyPrefixSize + kMaxVarint64Length];
-  auto key = BlockBasedTable::GetCacheKey(cache_options.key_prefix.c_str(),
-                                          cache_options.key_prefix.size(),
-                                          handle, cache_key);
-  // Lookup page
+  CacheKey key =
+      BlockBasedTable::GetCacheKey(cache_options.base_cache_key, handle);
+
   std::unique_ptr<char[]> data;
   size_t size;
-  Status s = cache_options.persistent_cache->Lookup(key, &data, &size);
+  Status s =
+      cache_options.persistent_cache->Lookup(key.AsSlice(), &data, &size);
   if (!s.ok()) {
     // cache miss
     RecordTick(cache_options.statistics, PERSISTENT_CACHE_MISS);