#include <string>
#include <mutex>
+#include <boost/circular_buffer.hpp>
#include "ShardedCache.h"
#include "common/autovector.h"
double high_pri_pool_ratio = 0.0);
struct BinnedLRUHandle {
+ std::shared_ptr<uint64_t> age_bin;
void* value;
- void (*deleter)(const rocksdb::Slice&, void* value);
+ DeleterFn deleter;
BinnedLRUHandle* next_hash;
BinnedLRUHandle* next;
BinnedLRUHandle* prev;
// Like Cache methods, but with an extra "hash" parameter.
virtual rocksdb::Status Insert(const rocksdb::Slice& key, uint32_t hash, void* value,
size_t charge,
- void (*deleter)(const rocksdb::Slice& key, void* value),
+ DeleterFn deleter,
rocksdb::Cache::Handle** handle,
rocksdb::Cache::Priority priority) override;
virtual rocksdb::Cache::Handle* Lookup(const rocksdb::Slice& key, uint32_t hash) override;
virtual size_t GetUsage() const override;
virtual size_t GetPinnedUsage() const override;
- virtual void ApplyToAllCacheEntries(void (*callback)(void*, size_t),
- bool thread_safe) override;
+ virtual void ApplyToAllCacheEntries(
+ const std::function<void(const rocksdb::Slice& key,
+ void* value,
+ size_t charge,
+ DeleterFn)>& callback,
+ bool thread_safe) override;
virtual void EraseUnRefEntries() override;
virtual std::string GetPrintableOptions() const override;
+ virtual DeleterFn GetDeleter(rocksdb::Cache::Handle* handle) const override;
+
void TEST_GetLRUList(BinnedLRUHandle** lru, BinnedLRUHandle** lru_low_pri);
// Retrieves number of elements in LRU, for unit test purpose only
// Retrieves high pri pool usage
size_t GetHighPriPoolUsage() const;
+ // Rotate the bins
+ void shift_bins();
+
+ // Get the bin count
+ uint32_t get_bin_count() const;
+
+ // Set the bin count
+ void set_bin_count(uint32_t count);
+
+ // Get the byte counts for a range of age bins
+ uint64_t sum_bins(uint32_t start, uint32_t end) const;
+
private:
CephContext *cct;
void LRU_Remove(BinnedLRUHandle* e);
// We don't count mutex_ as the cache's internal state so semantically we
// don't mind mutex_ invoking the non-const actions.
mutable std::mutex mutex_;
+
+ // Circular buffer of byte counters for age binning
+ boost::circular_buffer<std::shared_ptr<uint64_t>> age_bins;
};
class BinnedLRUCache : public ShardedCache {
virtual size_t GetCharge(Handle* handle) const override;
virtual uint32_t GetHash(Handle* handle) const override;
virtual void DisownData() override;
-
+#if (ROCKSDB_MAJOR >= 7 || (ROCKSDB_MAJOR == 6 && ROCKSDB_MINOR >= 22))
+ virtual DeleterFn GetDeleter(Handle* handle) const override;
+#endif
// Retrieves number of elements in LRU, for unit test purpose only
size_t TEST_GetLRUSize();
// Sets the high pri pool ratio
virtual int64_t get_committed_size() const {
return GetCapacity();
}
+ virtual void shift_bins();
+ uint64_t sum_bins(uint32_t start, uint32_t end) const;
+ uint32_t get_bin_count() const;
+ void set_bin_count(uint32_t count);
+
virtual std::string get_cache_name() const {
return "RocksDB Binned LRU Cache";
}