6a6f94
diff --git a/src/kv/rocksdb_cache/BinnedLRUCache.cc b/src/kv/rocksdb_cache/BinnedLRUCache.cc
6a6f94
index 0d657883e92de..47c56e2ddd769 100644
6a6f94
--- a/src/kv/rocksdb_cache/BinnedLRUCache.cc
6a6f94
+++ b/src/kv/rocksdb_cache/BinnedLRUCache.cc
6a6f94
@@ -151,13 +151,20 @@ void BinnedLRUCacheShard::EraseUnRefEntries() {
6a6f94
   }
6a6f94
 }
6a6f94
 
6a6f94
-void BinnedLRUCacheShard::ApplyToAllCacheEntries(void (*callback)(void*, size_t),
6a6f94
-                                           bool thread_safe) {
6a6f94
+void BinnedLRUCacheShard::ApplyToAllCacheEntries(
6a6f94
+  const std::function
6a6f94
+                           void* value,
6a6f94
+                           size_t charge,
6a6f94
+                           DeleterFn)>& callback,
6a6f94
+  bool thread_safe)
6a6f94
+{
6a6f94
   if (thread_safe) {
6a6f94
     mutex_.lock();
6a6f94
   }
6a6f94
   table_.ApplyToAllCacheEntries(
6a6f94
-      [callback](BinnedLRUHandle* h) { callback(h->value, h->charge); });
6a6f94
+    [callback](BinnedLRUHandle* h) {
6a6f94
+      callback(h->key(), h->value, h->charge, h->deleter);
6a6f94
+    });
6a6f94
   if (thread_safe) {
6a6f94
     mutex_.unlock();
6a6f94
   }
6a6f94
@@ -345,7 +352,7 @@ bool BinnedLRUCacheShard::Release(rocksdb::Cache::Handle* handle, bool force_era
6a6f94
 
6a6f94
 rocksdb::Status BinnedLRUCacheShard::Insert(const rocksdb::Slice& key, uint32_t hash, void* value,
6a6f94
                              size_t charge,
6a6f94
-                             void (*deleter)(const rocksdb::Slice& key, void* value),
6a6f94
+                             DeleterFn deleter,
6a6f94
                              rocksdb::Cache::Handle** handle, rocksdb::Cache::Priority priority) {
6a6f94
   auto e = new BinnedLRUHandle();
6a6f94
   rocksdb::Status s;
6a6f94
@@ -464,6 +471,12 @@ std::string BinnedLRUCacheShard::GetPrintableOptions() const {
6a6f94
   return std::string(buffer);
6a6f94
 }
6a6f94
 
6a6f94
+DeleterFn BinnedLRUCacheShard::GetDeleter(rocksdb::Cache::Handle* h) const
6a6f94
+{
6a6f94
+  auto* handle = reinterpret_cast<BinnedLRUHandle*>(h);
6a6f94
+  return handle->deleter;
6a6f94
+}
6a6f94
+
6a6f94
 BinnedLRUCache::BinnedLRUCache(CephContext *c, 
6a6f94
                                size_t capacity, 
6a6f94
                                int num_shard_bits,
6a6f94
@@ -519,6 +532,13 @@ void BinnedLRUCache::DisownData() {
6a6f94
 #endif  // !__SANITIZE_ADDRESS__
6a6f94
 }
6a6f94
 
6a6f94
+#if (ROCKSDB_MAJOR >= 6 && ROCKSDB_MINOR >= 22)
6a6f94
+DeleterFn BinnedLRUCache::GetDeleter(Handle* handle) const
6a6f94
+{
6a6f94
+  return reinterpret_cast<const BinnedLRUHandle*>(handle)->deleter;
6a6f94
+}
6a6f94
+#endif
6a6f94
+
6a6f94
 size_t BinnedLRUCache::TEST_GetLRUSize() {
6a6f94
   size_t lru_size_of_all_shards = 0;
6a6f94
   for (int i = 0; i < num_shards_; i++) {
6a6f94
diff --git a/src/kv/rocksdb_cache/BinnedLRUCache.h b/src/kv/rocksdb_cache/BinnedLRUCache.h
6a6f94
index 85608be0e5734..88bf4502e8927 100644
6a6f94
--- a/src/kv/rocksdb_cache/BinnedLRUCache.h
6a6f94
+++ b/src/kv/rocksdb_cache/BinnedLRUCache.h
6a6f94
@@ -56,7 +56,7 @@ std::shared_ptr<rocksdb::Cache> NewBinnedLRUCache(
6a6f94
 
6a6f94
 struct BinnedLRUHandle {
6a6f94
   void* value;
6a6f94
-  void (*deleter)(const rocksdb::Slice&, void* value);
6a6f94
+  DeleterFn deleter;
6a6f94
   BinnedLRUHandle* next_hash;
6a6f94
   BinnedLRUHandle* next;
6a6f94
   BinnedLRUHandle* prev;
6a6f94
@@ -189,7 +189,7 @@ class alignas(CACHE_LINE_SIZE) BinnedLRUCacheShard : public CacheShard {
6a6f94
   // Like Cache methods, but with an extra "hash" parameter.
6a6f94
   virtual rocksdb::Status Insert(const rocksdb::Slice& key, uint32_t hash, void* value,
6a6f94
                         size_t charge,
6a6f94
-                        void (*deleter)(const rocksdb::Slice& key, void* value),
6a6f94
+                        DeleterFn deleter,
6a6f94
                         rocksdb::Cache::Handle** handle,
6a6f94
                         rocksdb::Cache::Priority priority) override;
6a6f94
   virtual rocksdb::Cache::Handle* Lookup(const rocksdb::Slice& key, uint32_t hash) override;
6a6f94
@@ -205,13 +205,19 @@ class alignas(CACHE_LINE_SIZE) BinnedLRUCacheShard : public CacheShard {
6a6f94
   virtual size_t GetUsage() const override;
6a6f94
   virtual size_t GetPinnedUsage() const override;
6a6f94
 
6a6f94
-  virtual void ApplyToAllCacheEntries(void (*callback)(void*, size_t),
6a6f94
-                                      bool thread_safe) override;
6a6f94
+  virtual void ApplyToAllCacheEntries(
6a6f94
+    const std::function
6a6f94
+                             void* value,
6a6f94
+                             size_t charge,
6a6f94
+                             DeleterFn)>& callback,
6a6f94
+    bool thread_safe) override;
6a6f94
 
6a6f94
   virtual void EraseUnRefEntries() override;
6a6f94
 
6a6f94
   virtual std::string GetPrintableOptions() const override;
6a6f94
 
6a6f94
+  virtual DeleterFn GetDeleter(rocksdb::Cache::Handle* handle) const override;
6a6f94
+
6a6f94
   void TEST_GetLRUList(BinnedLRUHandle** lru, BinnedLRUHandle** lru_low_pri);
6a6f94
 
6a6f94
   //  Retrieves number of elements in LRU, for unit test purpose only
6a6f94
@@ -304,7 +310,9 @@ class BinnedLRUCache : public ShardedCache {
6a6f94
   virtual size_t GetCharge(Handle* handle) const override;
6a6f94
   virtual uint32_t GetHash(Handle* handle) const override;
6a6f94
   virtual void DisownData() override;
6a6f94
-
6a6f94
+#if (ROCKSDB_MAJOR >= 6 && ROCKSDB_MINOR >= 22)
6a6f94
+  virtual DeleterFn GetDeleter(Handle* handle) const override;
6a6f94
+#endif
6a6f94
   //  Retrieves number of elements in LRU, for unit test purpose only
6a6f94
   size_t TEST_GetLRUSize();
6a6f94
   // Sets the high pri pool ratio
6a6f94
diff --git a/src/kv/rocksdb_cache/ShardedCache.cc b/src/kv/rocksdb_cache/ShardedCache.cc
6a6f94
index 367140a94d8be..6cbd89ad6472c 100644
6a6f94
--- a/src/kv/rocksdb_cache/ShardedCache.cc
6a6f94
+++ b/src/kv/rocksdb_cache/ShardedCache.cc
6a6f94
@@ -44,7 +44,7 @@ void ShardedCache::SetStrictCapacityLimit(bool strict_capacity_limit) {
6a6f94
 }
6a6f94
 
6a6f94
 rocksdb::Status ShardedCache::Insert(const rocksdb::Slice& key, void* value, size_t charge,
6a6f94
-                            void (*deleter)(const rocksdb::Slice& key, void* value),
6a6f94
+                            DeleterFn deleter,
6a6f94
                             rocksdb::Cache::Handle** handle, Priority priority) {
6a6f94
   uint32_t hash = HashSlice(key);
6a6f94
   return GetShard(Shard(hash))
6a6f94
@@ -109,13 +109,36 @@ size_t ShardedCache::GetPinnedUsage() const {
6a6f94
   return usage;
6a6f94
 }
6a6f94
 
6a6f94
+#if (ROCKSDB_MAJOR >= 6 && ROCKSDB_MINOR >= 22)
6a6f94
+DeleterFn ShardedCache::GetDeleter(Handle* handle) const
6a6f94
+{
6a6f94
+  uint32_t hash = GetHash(handle);
6a6f94
+  return GetShard(Shard(hash))->GetDeleter(handle);
6a6f94
+}
6a6f94
+
6a6f94
+void ShardedCache::ApplyToAllEntries(
6a6f94
+    const std::function
6a6f94
+                             DeleterFn deleter)>& callback,
6a6f94
+    const ApplyToAllEntriesOptions& opts)
6a6f94
+{
6a6f94
+  int num_shards = 1 << num_shard_bits_;
6a6f94
+  for (int s = 0; s < num_shards; s++) {
6a6f94
+    GetShard(s)->ApplyToAllCacheEntries(callback, true /* thread_safe */);
6a6f94
+  }
6a6f94
+}
6a6f94
+#else
6a6f94
 void ShardedCache::ApplyToAllCacheEntries(void (*callback)(void*, size_t),
6a6f94
                                           bool thread_safe) {
6a6f94
   int num_shards = 1 << num_shard_bits_;
6a6f94
   for (int s = 0; s < num_shards; s++) {
6a6f94
-    GetShard(s)->ApplyToAllCacheEntries(callback, thread_safe);
6a6f94
+    GetShard(s)->ApplyToAllCacheEntries(
6a6f94
+      [callback](const rocksdb::Slice&, void* value, size_t charge, DeleterFn) {
6a6f94
+        callback(value, charge);
6a6f94
+      },
6a6f94
+      thread_safe);
6a6f94
   }
6a6f94
 }
6a6f94
+#endif
6a6f94
 
6a6f94
 void ShardedCache::EraseUnRefEntries() {
6a6f94
   int num_shards = 1 << num_shard_bits_;
6a6f94
@@ -131,7 +154,7 @@ std::string ShardedCache::GetPrintableOptions() const {
6a6f94
   char buffer[kBufferSize];
6a6f94
   {
6a6f94
     std::lock_guard<std::mutex> l(capacity_mutex_);
6a6f94
-    snprintf(buffer, kBufferSize, "    capacity : %" ROCKSDB_PRIszt "\n",
6a6f94
+    snprintf(buffer, kBufferSize, "    capacity : %zu\n",
6a6f94
              capacity_);
6a6f94
     ret.append(buffer);
6a6f94
     snprintf(buffer, kBufferSize, "    num_shard_bits : %d\n", num_shard_bits_);
6a6f94
diff --git a/src/kv/rocksdb_cache/ShardedCache.h b/src/kv/rocksdb_cache/ShardedCache.h
6a6f94
index 4d64893ab1c7b..f98421a09a33a 100644
6a6f94
--- a/src/kv/rocksdb_cache/ShardedCache.h
6a6f94
+++ b/src/kv/rocksdb_cache/ShardedCache.h
6a6f94
@@ -14,6 +14,7 @@
6a6f94
 #include <string>
6a6f94
 #include <mutex>
6a6f94
 
6a6f94
+#include "rocksdb/version.h"
6a6f94
 #include "rocksdb/cache.h"
6a6f94
 #include "include/ceph_hash.h"
6a6f94
 #include "common/PriorityCache.h"
6a6f94
@@ -22,10 +23,11 @@
6a6f94
 #ifndef CACHE_LINE_SIZE
6a6f94
 #define CACHE_LINE_SIZE 64 // XXX arch-specific define 
6a6f94
 #endif
6a6f94
-#define ROCKSDB_PRIszt "zu"
6a6f94
 
6a6f94
 namespace rocksdb_cache {
6a6f94
 
6a6f94
+using DeleterFn = void (*)(const rocksdb::Slice& key, void* value);
6a6f94
+
6a6f94
 // Single cache shard interface.
6a6f94
 class CacheShard {
6a6f94
  public:
6a6f94
@@ -34,7 +36,7 @@ class CacheShard {
6a6f94
 
6a6f94
   virtual rocksdb::Status Insert(const rocksdb::Slice& key, uint32_t hash, void* value,
6a6f94
                                  size_t charge,
6a6f94
-                                 void (*deleter)(const rocksdb::Slice& key, void* value),
6a6f94
+                                 DeleterFn deleter,
6a6f94
                                  rocksdb::Cache::Handle** handle, rocksdb::Cache::Priority priority) = 0;
6a6f94
   virtual rocksdb::Cache::Handle* Lookup(const rocksdb::Slice& key, uint32_t hash) = 0;
6a6f94
   virtual bool Ref(rocksdb::Cache::Handle* handle) = 0;
6a6f94
@@ -44,10 +46,15 @@ class CacheShard {
6a6f94
   virtual void SetStrictCapacityLimit(bool strict_capacity_limit) = 0;
6a6f94
   virtual size_t GetUsage() const = 0;
6a6f94
   virtual size_t GetPinnedUsage() const = 0;
6a6f94
-  virtual void ApplyToAllCacheEntries(void (*callback)(void*, size_t),
6a6f94
-                                      bool thread_safe) = 0;
6a6f94
+  virtual void ApplyToAllCacheEntries(
6a6f94
+    const std::function
6a6f94
+                             void* value,
6a6f94
+                             size_t charge,
6a6f94
+                             DeleterFn)>& callback,
6a6f94
+    bool thread_safe) = 0;
6a6f94
   virtual void EraseUnRefEntries() = 0;
6a6f94
   virtual std::string GetPrintableOptions() const { return ""; }
6a6f94
+  virtual DeleterFn GetDeleter(rocksdb::Cache::Handle* handle) const = 0;
6a6f94
 };
6a6f94
 
6a6f94
 // Generic cache interface which shards cache by hash of keys. 2^num_shard_bits
6a6f94
@@ -57,34 +64,43 @@ class ShardedCache : public rocksdb::Cache, public PriorityCache::PriCache {
6a6f94
  public:
6a6f94
   ShardedCache(size_t capacity, int num_shard_bits, bool strict_capacity_limit);
6a6f94
   virtual ~ShardedCache() = default;
6a6f94
+  // rocksdb::Cache
6a6f94
   virtual const char* Name() const override = 0;
6a6f94
-  virtual CacheShard* GetShard(int shard) = 0;
6a6f94
-  virtual const CacheShard* GetShard(int shard) const = 0;
6a6f94
-  virtual void* Value(Handle* handle) override = 0;
6a6f94
-  virtual size_t GetCharge(Handle* handle) const = 0;
6a6f94
-  virtual uint32_t GetHash(Handle* handle) const = 0;
6a6f94
-  virtual void DisownData() override = 0;
6a6f94
-
6a6f94
-  virtual void SetCapacity(size_t capacity) override;
6a6f94
-  virtual void SetStrictCapacityLimit(bool strict_capacity_limit) override;
6a6f94
-
6a6f94
   virtual rocksdb::Status Insert(const rocksdb::Slice& key, void* value, size_t charge,
6a6f94
-                                 void (*deleter)(const rocksdb::Slice& key, void* value),
6a6f94
+                                 DeleterFn,
6a6f94
                                  rocksdb::Cache::Handle** handle, Priority priority) override;
6a6f94
   virtual rocksdb::Cache::Handle* Lookup(const rocksdb::Slice& key, rocksdb::Statistics* stats) override;
6a6f94
   virtual bool Ref(rocksdb::Cache::Handle* handle) override;
6a6f94
   virtual bool Release(rocksdb::Cache::Handle* handle, bool force_erase = false) override;
6a6f94
+  virtual void* Value(Handle* handle) override = 0;
6a6f94
   virtual void Erase(const rocksdb::Slice& key) override;
6a6f94
   virtual uint64_t NewId() override;
6a6f94
-  virtual size_t GetCapacity() const override;
6a6f94
+  virtual void SetCapacity(size_t capacity) override;
6a6f94
+  virtual void SetStrictCapacityLimit(bool strict_capacity_limit) override;
6a6f94
   virtual bool HasStrictCapacityLimit() const override;
6a6f94
+  virtual size_t GetCapacity() const override;
6a6f94
   virtual size_t GetUsage() const override;
6a6f94
   virtual size_t GetUsage(rocksdb::Cache::Handle* handle) const override;
6a6f94
   virtual size_t GetPinnedUsage() const override;
6a6f94
+  virtual size_t GetCharge(Handle* handle) const = 0;
6a6f94
+#if (ROCKSDB_MAJOR >= 6 && ROCKSDB_MINOR >= 22)
6a6f94
+  virtual DeleterFn GetDeleter(Handle* handle) const override;
6a6f94
+#endif
6a6f94
+  virtual void DisownData() override = 0;
6a6f94
+#if (ROCKSDB_MAJOR >= 6 && ROCKSDB_MINOR >= 22)
6a6f94
+  virtual void ApplyToAllEntries(
6a6f94
+      const std::function
6a6f94
+                               DeleterFn deleter)>& callback,
6a6f94
+      const ApplyToAllEntriesOptions& opts) override;
6a6f94
+#else
6a6f94
   virtual void ApplyToAllCacheEntries(void (*callback)(void*, size_t),
6a6f94
                                       bool thread_safe) override;
6a6f94
+#endif
6a6f94
   virtual void EraseUnRefEntries() override;
6a6f94
   virtual std::string GetPrintableOptions() const override;
6a6f94
+  virtual CacheShard* GetShard(int shard) = 0;
6a6f94
+  virtual const CacheShard* GetShard(int shard) const = 0;
6a6f94
+  virtual uint32_t GetHash(Handle* handle) const = 0;
6a6f94
 
6a6f94
   int GetNumShardBits() const { return num_shard_bits_; }
6a6f94
 
6a6f94
@@ -120,7 +136,7 @@ class ShardedCache : public rocksdb::Cache, public PriorityCache::PriCache {
6a6f94
 //    return Hash(s.data(), s.size(), 0);
6a6f94
   }
6a6f94
 
6a6f94
-  uint32_t Shard(uint32_t hash) {
6a6f94
+  uint32_t Shard(uint32_t hash) const {
6a6f94
     // Note, hash >> 32 yields hash in gcc, not the zero we expect!
6a6f94
     return (num_shard_bits_ > 0) ? (hash >> (32 - num_shard_bits_)) : 0;
6a6f94
   }