mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Test with SLRU and debug logs
This commit is contained in:
parent
c044fee7a0
commit
8be62770aa
@ -5,6 +5,7 @@
|
||||
#include <Common/SLRUCachePolicy.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@ -30,7 +31,7 @@ public:
|
||||
using Mapped = TMapped;
|
||||
using MappedPtr = std::shared_ptr<Mapped>;
|
||||
|
||||
CacheBase(size_t max_size, size_t max_elements_size = 0) : CacheBase("LRU", max_size, max_elements_size) {}
|
||||
CacheBase(size_t max_size, size_t max_elements_size = 0) : CacheBase("SLRU", max_size, max_elements_size) {}
|
||||
|
||||
/// TODO: Rewrite "Args... args" to custom struct with fields for all cache policies.
|
||||
template <class... Args>
|
||||
@ -65,6 +66,11 @@ public:
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
auto weight = cache_policy->weight(lock);
|
||||
auto max_weight = cache_policy->maxSize();
|
||||
LOG_DEBUG(&Poco::Logger::get("CacheBase"), "Info before get. Weight: {}. Max weight: {}", weight, max_weight);
|
||||
assert(weight <= max_weight);
|
||||
|
||||
auto res = cache_policy->get(key, lock);
|
||||
if (res)
|
||||
++hits;
|
||||
@ -78,6 +84,11 @@ public:
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
auto weight = cache_policy->weight(lock);
|
||||
auto max_weight = cache_policy->maxSize();
|
||||
LOG_DEBUG(&Poco::Logger::get("CacheBase"), "Info before set. Weight: {}. Max weight: {}", weight, max_weight);
|
||||
assert(weight <= max_weight);
|
||||
|
||||
cache_policy->set(key, mapped, lock);
|
||||
}
|
||||
|
||||
@ -96,6 +107,11 @@ public:
|
||||
{
|
||||
std::lock_guard cache_lock(mutex);
|
||||
|
||||
auto weight = cache_policy->weight(cache_lock);
|
||||
auto max_weight = cache_policy->maxSize();
|
||||
LOG_DEBUG(&Poco::Logger::get("CacheBase"), "Info before getOrSet. Weight: {}. Max weight: {}", weight, max_weight);
|
||||
assert(weight <= max_weight);
|
||||
|
||||
auto val = cache_policy->get(key, cache_lock);
|
||||
if (val)
|
||||
{
|
||||
@ -154,6 +170,12 @@ public:
|
||||
void reset()
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
auto weight = cache_policy->weight(lock);
|
||||
auto max_weight = cache_policy->maxSize();
|
||||
LOG_DEBUG(&Poco::Logger::get("CacheBase"), "Info before reset. Weight: {}. Max weight: {}", weight, max_weight);
|
||||
assert(weight <= max_weight);
|
||||
|
||||
insert_tokens.clear();
|
||||
hits = 0;
|
||||
misses = 0;
|
||||
@ -163,6 +185,12 @@ public:
|
||||
void remove(const Key & key)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
auto weight = cache_policy->weight(lock);
|
||||
auto max_weight = cache_policy->maxSize();
|
||||
LOG_DEBUG(&Poco::Logger::get("CacheBase"), "Info before remove. Weight: {}. Max weight: {}", weight, max_weight);
|
||||
assert(weight <= max_weight);
|
||||
|
||||
cache_policy->remove(key, lock);
|
||||
}
|
||||
|
||||
@ -193,7 +221,7 @@ private:
|
||||
|
||||
std::unique_ptr<CachePolicy> cache_policy;
|
||||
|
||||
inline static const String default_cache_policy_name = "LRU";
|
||||
inline static const String default_cache_policy_name = "SLRU";
|
||||
|
||||
std::atomic<size_t> hits{0};
|
||||
std::atomic<size_t> misses{0};
|
||||
|
Loading…
Reference in New Issue
Block a user