Fix changes in commit c4be868222

This commit is contained in:
kssenii 2023-02-07 16:50:55 +01:00
parent ae9922abe5
commit 5c201698f4
2 changed files with 9 additions and 8 deletions

View File

@ -11,6 +11,8 @@ struct FileCacheKey
std::string toString() const; std::string toString() const;
FileCacheKey() = default;
explicit FileCacheKey(const std::string & path); explicit FileCacheKey(const std::string & path);
explicit FileCacheKey(const UInt128 & key_); explicit FileCacheKey(const UInt128 & key_);

View File

@ -2,6 +2,7 @@
#include <Interpreters/Cache/FileCacheKey.h> #include <Interpreters/Cache/FileCacheKey.h>
#include <Interpreters/Cache/CacheMetadata.h> #include <Interpreters/Cache/CacheMetadata.h>
#include <Interpreters/Cache/Guards.h> #include <Interpreters/Cache/Guards.h>
#include <Common/ConcurrentBoundedQueue.h>
namespace DB namespace DB
{ {
@ -76,22 +77,20 @@ private:
struct KeysQueue struct KeysQueue
{ {
std::unordered_set<FileCacheKey> keys; ConcurrentBoundedQueue<FileCacheKey> keys{100000}; /// TODO: add a setting for the size
std::mutex mutex;
void add(const FileCacheKey & key) void add(const FileCacheKey & key)
{ {
std::lock_guard lock(mutex); [[maybe_unused]] const auto pushed = keys.tryPush(key);
keys.insert(key); chassert(pushed);
} }
void clear(std::function<void(const FileCacheKey &)> && func) void clear(std::function<void(const FileCacheKey &)> && func)
{ {
std::lock_guard lock(mutex); FileCacheKey key;
for (auto it = keys.begin(); it != keys.end();) while (keys.tryPop(key))
{ {
func(*it); func(key);
it = keys.erase(it);
} }
} }
}; };