From 5c201698f46226366073b777500226ee0a7e81b3 Mon Sep 17 00:00:00 2001 From: kssenii Date: Tue, 7 Feb 2023 16:50:55 +0100 Subject: [PATCH] Fix changes in commit c4be8682221556887e436cadeb59c10dbafa0f14 --- src/Interpreters/Cache/FileCacheKey.h | 2 ++ src/Interpreters/Cache/LockedKey.h | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Interpreters/Cache/FileCacheKey.h b/src/Interpreters/Cache/FileCacheKey.h index 48ccef2b319..e4037b6f9af 100644 --- a/src/Interpreters/Cache/FileCacheKey.h +++ b/src/Interpreters/Cache/FileCacheKey.h @@ -11,6 +11,8 @@ struct FileCacheKey std::string toString() const; + FileCacheKey() = default; + explicit FileCacheKey(const std::string & path); explicit FileCacheKey(const UInt128 & key_); diff --git a/src/Interpreters/Cache/LockedKey.h b/src/Interpreters/Cache/LockedKey.h index fc813a9d9f3..f99f07e8881 100644 --- a/src/Interpreters/Cache/LockedKey.h +++ b/src/Interpreters/Cache/LockedKey.h @@ -2,6 +2,7 @@ #include #include #include +#include namespace DB { @@ -76,22 +77,20 @@ private: struct KeysQueue { - std::unordered_set keys; - std::mutex mutex; + ConcurrentBoundedQueue keys{100000}; /// TODO: add a setting for the size void add(const FileCacheKey & key) { - std::lock_guard lock(mutex); - keys.insert(key); + [[maybe_unused]] const auto pushed = keys.tryPush(key); + chassert(pushed); } void clear(std::function && func) { - std::lock_guard lock(mutex); - for (auto it = keys.begin(); it != keys.end();) + FileCacheKey key; + while (keys.tryPop(key)) { - func(*it); - it = keys.erase(it); + func(key); } } };