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