mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #61494 from ClickHouse/minor-rename
Minor rename in FileCache
This commit is contained in:
commit
f53f3cd833
@ -32,7 +32,7 @@ void EvictionCandidates::add(LockedKey & locked_key, const FileSegmentMetadataPt
|
||||
++candidates_size;
|
||||
}
|
||||
|
||||
void EvictionCandidates::evict(FileCacheQueryLimit::QueryContext * query_context, const CacheGuard::Lock & lock)
|
||||
void EvictionCandidates::evict(FileCacheQueryLimit::QueryContext * query_context, const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
if (candidates.empty())
|
||||
return;
|
||||
|
@ -11,7 +11,7 @@ public:
|
||||
|
||||
void add(LockedKey & locked_key, const FileSegmentMetadataPtr & candidate);
|
||||
|
||||
void evict(FileCacheQueryLimit::QueryContext * query_context, const CacheGuard::Lock &);
|
||||
void evict(FileCacheQueryLimit::QueryContext * query_context, const CachePriorityGuard::Lock &);
|
||||
|
||||
size_t size() const { return candidates_size; }
|
||||
|
||||
|
@ -183,13 +183,13 @@ void FileCache::initialize()
|
||||
is_initialized = true;
|
||||
}
|
||||
|
||||
CacheGuard::Lock FileCache::lockCache() const
|
||||
CachePriorityGuard::Lock FileCache::lockCache() const
|
||||
{
|
||||
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::FilesystemCacheLockCacheMicroseconds);
|
||||
return cache_guard.lock();
|
||||
}
|
||||
|
||||
CacheGuard::Lock FileCache::tryLockCache(std::optional<std::chrono::milliseconds> acquire_timeout) const
|
||||
CachePriorityGuard::Lock FileCache::tryLockCache(std::optional<std::chrono::milliseconds> acquire_timeout) const
|
||||
{
|
||||
return acquire_timeout.has_value() ? cache_guard.tryLockFor(acquire_timeout.value()) : cache_guard.tryLock();
|
||||
}
|
||||
@ -706,7 +706,7 @@ KeyMetadata::iterator FileCache::addFileSegment(
|
||||
size_t size,
|
||||
FileSegment::State state,
|
||||
const CreateFileSegmentSettings & create_settings,
|
||||
const CacheGuard::Lock * lock)
|
||||
const CachePriorityGuard::Lock * lock)
|
||||
{
|
||||
/// Create a file_segment_metadata and put it in `files` map by [key][offset].
|
||||
|
||||
|
@ -173,8 +173,8 @@ public:
|
||||
|
||||
void deactivateBackgroundOperations();
|
||||
|
||||
CacheGuard::Lock lockCache() const;
|
||||
CacheGuard::Lock tryLockCache(std::optional<std::chrono::milliseconds> acquire_timeout = std::nullopt) const;
|
||||
CachePriorityGuard::Lock lockCache() const;
|
||||
CachePriorityGuard::Lock tryLockCache(std::optional<std::chrono::milliseconds> acquire_timeout = std::nullopt) const;
|
||||
|
||||
std::vector<FileSegment::Info> sync();
|
||||
|
||||
@ -208,7 +208,7 @@ private:
|
||||
CacheMetadata metadata;
|
||||
|
||||
FileCachePriorityPtr main_priority;
|
||||
mutable CacheGuard cache_guard;
|
||||
mutable CachePriorityGuard cache_guard;
|
||||
|
||||
struct HitsCountStash
|
||||
{
|
||||
@ -280,7 +280,7 @@ private:
|
||||
size_t size,
|
||||
FileSegment::State state,
|
||||
const CreateFileSegmentSettings & create_settings,
|
||||
const CacheGuard::Lock *);
|
||||
const CachePriorityGuard::Lock *);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,17 +10,17 @@ namespace DB
|
||||
* 2. KeyGuard::Lock (hold till the end of the method)
|
||||
*
|
||||
* FileCache::tryReserve
|
||||
* 1. CacheGuard::Lock
|
||||
* 1. CachePriorityGuard::Lock
|
||||
* 2. KeyGuard::Lock (taken without metadata lock)
|
||||
* 3. any number of KeyGuard::Lock's for files which are going to be evicted (taken via metadata lock)
|
||||
*
|
||||
* FileCache::removeIfExists
|
||||
* 1. CacheGuard::Lock
|
||||
* 1. CachePriorityGuard::Lock
|
||||
* 2. KeyGuard::Lock (taken via metadata lock)
|
||||
* 3. FileSegmentGuard::Lock
|
||||
*
|
||||
* FileCache::removeAllReleasable
|
||||
* 1. CacheGuard::Lock
|
||||
* 1. CachePriorityGuard::Lock
|
||||
* 2. any number of KeyGuard::Lock's locks (takken via metadata lock), but at a moment of time only one key lock can be hold
|
||||
* 3. FileSegmentGuard::Lock
|
||||
*
|
||||
@ -34,23 +34,23 @@ namespace DB
|
||||
* 2. FileSegmentGuard::Lock
|
||||
*
|
||||
* FileSegment::complete
|
||||
* 1. CacheGuard::Lock
|
||||
* 1. CachePriorityGuard::Lock
|
||||
* 2. KeyGuard::Lock (taken without metadata lock)
|
||||
* 3. FileSegmentGuard::Lock
|
||||
*
|
||||
* Rules:
|
||||
* 1. Priority of locking: CacheGuard::Lock > CacheMetadataGuard::Lock > KeyGuard::Lock > FileSegmentGuard::Lock
|
||||
* 2. If we take more than one key lock at a moment of time, we need to take CacheGuard::Lock (example: tryReserve())
|
||||
* 1. Priority of locking: CachePriorityGuard::Lock > CacheMetadataGuard::Lock > KeyGuard::Lock > FileSegmentGuard::Lock
|
||||
* 2. If we take more than one key lock at a moment of time, we need to take CachePriorityGuard::Lock (example: tryReserve())
|
||||
*
|
||||
*
|
||||
* _CacheGuard_
|
||||
* _CachePriorityGuard_
|
||||
* 1. FileCache::tryReserve
|
||||
* 2. FileCache::removeIfExists(key)
|
||||
* 3. FileCache::removeAllReleasable
|
||||
* 4. FileSegment::complete
|
||||
*
|
||||
* _KeyGuard_ _CacheMetadataGuard_
|
||||
* 1. all from CacheGuard 1. getOrSet/get/set
|
||||
* 1. all from CachePriorityGuard 1. getOrSet/get/set
|
||||
* 2. getOrSet/get/Set
|
||||
*
|
||||
* *This table does not include locks taken for introspection and system tables.
|
||||
@ -59,11 +59,11 @@ namespace DB
|
||||
/**
|
||||
* Cache priority queue guard.
|
||||
*/
|
||||
struct CacheGuard : private boost::noncopyable
|
||||
struct CachePriorityGuard : private boost::noncopyable
|
||||
{
|
||||
using Mutex = std::timed_mutex;
|
||||
/// struct is used (not keyword `using`) to make CacheGuard::Lock non-interchangable with other guards locks
|
||||
/// so, we wouldn't be able to pass CacheGuard::Lock to a function which accepts KeyGuard::Lock, for example
|
||||
/// struct is used (not keyword `using`) to make CachePriorityGuard::Lock non-interchangable with other guards locks
|
||||
/// so, we wouldn't be able to pass CachePriorityGuard::Lock to a function which accepts KeyGuard::Lock, for example
|
||||
struct Lock : public std::unique_lock<Mutex>
|
||||
{
|
||||
using Base = std::unique_lock<Mutex>;
|
||||
|
@ -43,11 +43,11 @@ public:
|
||||
|
||||
virtual EntryPtr getEntry() const = 0;
|
||||
|
||||
virtual size_t increasePriority(const CacheGuard::Lock &) = 0;
|
||||
virtual size_t increasePriority(const CachePriorityGuard::Lock &) = 0;
|
||||
|
||||
virtual void updateSize(int64_t size) = 0;
|
||||
|
||||
virtual void remove(const CacheGuard::Lock &) = 0;
|
||||
virtual void remove(const CachePriorityGuard::Lock &) = 0;
|
||||
|
||||
virtual void invalidate() = 0;
|
||||
|
||||
@ -57,13 +57,13 @@ public:
|
||||
|
||||
virtual ~IFileCachePriority() = default;
|
||||
|
||||
size_t getElementsLimit(const CacheGuard::Lock &) const { return max_elements; }
|
||||
size_t getElementsLimit(const CachePriorityGuard::Lock &) const { return max_elements; }
|
||||
|
||||
size_t getSizeLimit(const CacheGuard::Lock &) const { return max_size; }
|
||||
size_t getSizeLimit(const CachePriorityGuard::Lock &) const { return max_size; }
|
||||
|
||||
virtual size_t getSize(const CacheGuard::Lock &) const = 0;
|
||||
virtual size_t getSize(const CachePriorityGuard::Lock &) const = 0;
|
||||
|
||||
virtual size_t getElementsCount(const CacheGuard::Lock &) const = 0;
|
||||
virtual size_t getElementsCount(const CachePriorityGuard::Lock &) const = 0;
|
||||
|
||||
/// Throws exception if there is not enough size to fit it.
|
||||
virtual IteratorPtr add( /// NOLINT
|
||||
@ -71,7 +71,7 @@ public:
|
||||
size_t offset,
|
||||
size_t size,
|
||||
const UserInfo & user,
|
||||
const CacheGuard::Lock &,
|
||||
const CachePriorityGuard::Lock &,
|
||||
bool best_effort = false) = 0;
|
||||
|
||||
/// `reservee` is the entry for which are reserving now.
|
||||
@ -79,11 +79,11 @@ public:
|
||||
/// for the corresponding file segment.
|
||||
virtual bool canFit( /// NOLINT
|
||||
size_t size,
|
||||
const CacheGuard::Lock &,
|
||||
const CachePriorityGuard::Lock &,
|
||||
IteratorPtr reservee = nullptr,
|
||||
bool best_effort = false) const = 0;
|
||||
|
||||
virtual void shuffle(const CacheGuard::Lock &) = 0;
|
||||
virtual void shuffle(const CachePriorityGuard::Lock &) = 0;
|
||||
|
||||
struct IPriorityDump
|
||||
{
|
||||
@ -91,9 +91,9 @@ public:
|
||||
};
|
||||
using PriorityDumpPtr = std::shared_ptr<IPriorityDump>;
|
||||
|
||||
virtual PriorityDumpPtr dump(const CacheGuard::Lock &) = 0;
|
||||
virtual PriorityDumpPtr dump(const CachePriorityGuard::Lock &) = 0;
|
||||
|
||||
using FinalizeEvictionFunc = std::function<void(const CacheGuard::Lock & lk)>;
|
||||
using FinalizeEvictionFunc = std::function<void(const CachePriorityGuard::Lock & lk)>;
|
||||
virtual bool collectCandidatesForEviction(
|
||||
size_t size,
|
||||
FileCacheReserveStat & stat,
|
||||
@ -101,9 +101,9 @@ public:
|
||||
IFileCachePriority::IteratorPtr reservee,
|
||||
FinalizeEvictionFunc & finalize_eviction_func,
|
||||
const UserID & user_id,
|
||||
const CacheGuard::Lock &) = 0;
|
||||
const CachePriorityGuard::Lock &) = 0;
|
||||
|
||||
virtual bool modifySizeLimits(size_t max_size_, size_t max_elements_, double size_ratio_, const CacheGuard::Lock &) = 0;
|
||||
virtual bool modifySizeLimits(size_t max_size_, size_t max_elements_, double size_ratio_, const CachePriorityGuard::Lock &) = 0;
|
||||
|
||||
protected:
|
||||
IFileCachePriority(size_t max_size_, size_t max_elements_);
|
||||
|
@ -43,13 +43,13 @@ IFileCachePriority::IteratorPtr LRUFileCachePriority::add( /// NOLINT
|
||||
size_t offset,
|
||||
size_t size,
|
||||
const UserInfo &,
|
||||
const CacheGuard::Lock & lock,
|
||||
const CachePriorityGuard::Lock & lock,
|
||||
bool)
|
||||
{
|
||||
return std::make_shared<LRUIterator>(add(std::make_shared<Entry>(key_metadata->key, offset, size, key_metadata), lock));
|
||||
}
|
||||
|
||||
LRUFileCachePriority::LRUIterator LRUFileCachePriority::add(EntryPtr entry, const CacheGuard::Lock & lock)
|
||||
LRUFileCachePriority::LRUIterator LRUFileCachePriority::add(EntryPtr entry, const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
if (entry->size == 0)
|
||||
{
|
||||
@ -93,7 +93,7 @@ LRUFileCachePriority::LRUIterator LRUFileCachePriority::add(EntryPtr entry, cons
|
||||
return LRUIterator(this, iterator);
|
||||
}
|
||||
|
||||
LRUFileCachePriority::LRUQueue::iterator LRUFileCachePriority::remove(LRUQueue::iterator it, const CacheGuard::Lock &)
|
||||
LRUFileCachePriority::LRUQueue::iterator LRUFileCachePriority::remove(LRUQueue::iterator it, const CachePriorityGuard::Lock &)
|
||||
{
|
||||
/// If size is 0, entry is invalidated, current_elements_num was already updated.
|
||||
const auto & entry = **it;
|
||||
@ -150,7 +150,7 @@ bool LRUFileCachePriority::LRUIterator::operator ==(const LRUIterator & other) c
|
||||
return cache_priority == other.cache_priority && iterator == other.iterator;
|
||||
}
|
||||
|
||||
void LRUFileCachePriority::iterate(IterateFunc && func, const CacheGuard::Lock & lock)
|
||||
void LRUFileCachePriority::iterate(IterateFunc && func, const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
for (auto it = queue.begin(); it != queue.end();)
|
||||
{
|
||||
@ -201,7 +201,7 @@ void LRUFileCachePriority::iterate(IterateFunc && func, const CacheGuard::Lock &
|
||||
|
||||
bool LRUFileCachePriority::canFit( /// NOLINT
|
||||
size_t size,
|
||||
const CacheGuard::Lock & lock,
|
||||
const CachePriorityGuard::Lock & lock,
|
||||
IteratorPtr,
|
||||
bool) const
|
||||
{
|
||||
@ -212,7 +212,7 @@ bool LRUFileCachePriority::canFit(
|
||||
size_t size,
|
||||
size_t released_size_assumption,
|
||||
size_t released_elements_assumption,
|
||||
const CacheGuard::Lock &) const
|
||||
const CachePriorityGuard::Lock &) const
|
||||
{
|
||||
return (max_size == 0 || (state->current_size + size - released_size_assumption <= max_size))
|
||||
&& (max_elements == 0 || state->current_elements_num + 1 - released_elements_assumption <= max_elements);
|
||||
@ -225,7 +225,7 @@ bool LRUFileCachePriority::collectCandidatesForEviction(
|
||||
IFileCachePriority::IteratorPtr,
|
||||
FinalizeEvictionFunc &,
|
||||
const UserID &,
|
||||
const CacheGuard::Lock & lock)
|
||||
const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
if (canFit(size, lock))
|
||||
return true;
|
||||
@ -264,7 +264,7 @@ bool LRUFileCachePriority::collectCandidatesForEviction(
|
||||
return can_fit();
|
||||
}
|
||||
|
||||
LRUFileCachePriority::LRUIterator LRUFileCachePriority::move(LRUIterator & it, LRUFileCachePriority & other, const CacheGuard::Lock &)
|
||||
LRUFileCachePriority::LRUIterator LRUFileCachePriority::move(LRUIterator & it, LRUFileCachePriority & other, const CachePriorityGuard::Lock &)
|
||||
{
|
||||
const auto & entry = *it.getEntry();
|
||||
if (entry.size == 0)
|
||||
@ -297,7 +297,7 @@ LRUFileCachePriority::LRUIterator LRUFileCachePriority::move(LRUIterator & it, L
|
||||
return LRUIterator(this, it.iterator);
|
||||
}
|
||||
|
||||
IFileCachePriority::PriorityDumpPtr LRUFileCachePriority::dump(const CacheGuard::Lock & lock)
|
||||
IFileCachePriority::PriorityDumpPtr LRUFileCachePriority::dump(const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
std::vector<FileSegmentInfo> res;
|
||||
iterate([&](LockedKey &, const FileSegmentMetadataPtr & segment_metadata)
|
||||
@ -309,7 +309,7 @@ IFileCachePriority::PriorityDumpPtr LRUFileCachePriority::dump(const CacheGuard:
|
||||
}
|
||||
|
||||
bool LRUFileCachePriority::modifySizeLimits(
|
||||
size_t max_size_, size_t max_elements_, double /* size_ratio_ */, const CacheGuard::Lock & lock)
|
||||
size_t max_size_, size_t max_elements_, double /* size_ratio_ */, const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
if (max_size == max_size_ && max_elements == max_elements_)
|
||||
return false; /// Nothing to change.
|
||||
@ -353,7 +353,7 @@ bool LRUFileCachePriority::modifySizeLimits(
|
||||
return true;
|
||||
}
|
||||
|
||||
void LRUFileCachePriority::LRUIterator::remove(const CacheGuard::Lock & lock)
|
||||
void LRUFileCachePriority::LRUIterator::remove(const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
assertValid();
|
||||
cache_priority->remove(iterator, lock);
|
||||
@ -389,7 +389,7 @@ void LRUFileCachePriority::LRUIterator::updateSize(int64_t size)
|
||||
entry->size += size;
|
||||
}
|
||||
|
||||
size_t LRUFileCachePriority::LRUIterator::increasePriority(const CacheGuard::Lock &)
|
||||
size_t LRUFileCachePriority::LRUIterator::increasePriority(const CachePriorityGuard::Lock &)
|
||||
{
|
||||
assertValid();
|
||||
cache_priority->queue.splice(cache_priority->queue.end(), cache_priority->queue, iterator);
|
||||
@ -402,7 +402,7 @@ void LRUFileCachePriority::LRUIterator::assertValid() const
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Attempt to use invalid iterator");
|
||||
}
|
||||
|
||||
void LRUFileCachePriority::shuffle(const CacheGuard::Lock &)
|
||||
void LRUFileCachePriority::shuffle(const CachePriorityGuard::Lock &)
|
||||
{
|
||||
std::vector<LRUQueue::iterator> its;
|
||||
its.reserve(queue.size());
|
||||
|
@ -24,13 +24,13 @@ protected:
|
||||
public:
|
||||
LRUFileCachePriority(size_t max_size_, size_t max_elements_, StatePtr state_ = nullptr);
|
||||
|
||||
size_t getSize(const CacheGuard::Lock &) const override { return state->current_size; }
|
||||
size_t getSize(const CachePriorityGuard::Lock &) const override { return state->current_size; }
|
||||
|
||||
size_t getElementsCount(const CacheGuard::Lock &) const override { return state->current_elements_num; }
|
||||
size_t getElementsCount(const CachePriorityGuard::Lock &) const override { return state->current_elements_num; }
|
||||
|
||||
bool canFit( /// NOLINT
|
||||
size_t size,
|
||||
const CacheGuard::Lock &,
|
||||
const CachePriorityGuard::Lock &,
|
||||
IteratorPtr reservee = nullptr,
|
||||
bool best_effort = false) const override;
|
||||
|
||||
@ -39,7 +39,7 @@ public:
|
||||
size_t offset,
|
||||
size_t size,
|
||||
const UserInfo & user,
|
||||
const CacheGuard::Lock &,
|
||||
const CachePriorityGuard::Lock &,
|
||||
bool best_effort = false) override;
|
||||
|
||||
bool collectCandidatesForEviction(
|
||||
@ -49,9 +49,9 @@ public:
|
||||
IFileCachePriority::IteratorPtr reservee,
|
||||
FinalizeEvictionFunc & finalize_eviction_func,
|
||||
const UserID & user_id,
|
||||
const CacheGuard::Lock &) override;
|
||||
const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void shuffle(const CacheGuard::Lock &) override;
|
||||
void shuffle(const CachePriorityGuard::Lock &) override;
|
||||
|
||||
struct LRUPriorityDump : public IPriorityDump
|
||||
{
|
||||
@ -59,11 +59,11 @@ public:
|
||||
explicit LRUPriorityDump(const std::vector<FileSegmentInfo> & infos_) : infos(infos_) {}
|
||||
void merge(const LRUPriorityDump & other) { infos.insert(infos.end(), other.infos.begin(), other.infos.end()); }
|
||||
};
|
||||
PriorityDumpPtr dump(const CacheGuard::Lock &) override;
|
||||
PriorityDumpPtr dump(const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void pop(const CacheGuard::Lock & lock) { remove(queue.begin(), lock); }
|
||||
void pop(const CachePriorityGuard::Lock & lock) { remove(queue.begin(), lock); }
|
||||
|
||||
bool modifySizeLimits(size_t max_size_, size_t max_elements_, double size_ratio_, const CacheGuard::Lock &) override;
|
||||
bool modifySizeLimits(size_t max_size_, size_t max_elements_, double size_ratio_, const CachePriorityGuard::Lock &) override;
|
||||
|
||||
private:
|
||||
class LRUIterator;
|
||||
@ -77,9 +77,9 @@ private:
|
||||
void updateElementsCount(int64_t num);
|
||||
void updateSize(int64_t size);
|
||||
|
||||
bool canFit(size_t size, size_t released_size_assumption, size_t released_elements_assumption, const CacheGuard::Lock &) const;
|
||||
bool canFit(size_t size, size_t released_size_assumption, size_t released_elements_assumption, const CachePriorityGuard::Lock &) const;
|
||||
|
||||
LRUQueue::iterator remove(LRUQueue::iterator it, const CacheGuard::Lock &);
|
||||
LRUQueue::iterator remove(LRUQueue::iterator it, const CachePriorityGuard::Lock &);
|
||||
|
||||
enum class IterationResult
|
||||
{
|
||||
@ -88,10 +88,10 @@ private:
|
||||
REMOVE_AND_CONTINUE,
|
||||
};
|
||||
using IterateFunc = std::function<IterationResult(LockedKey &, const FileSegmentMetadataPtr &)>;
|
||||
void iterate(IterateFunc && func, const CacheGuard::Lock &);
|
||||
void iterate(IterateFunc && func, const CachePriorityGuard::Lock &);
|
||||
|
||||
LRUIterator move(LRUIterator & it, LRUFileCachePriority & other, const CacheGuard::Lock &);
|
||||
LRUIterator add(EntryPtr entry, const CacheGuard::Lock &);
|
||||
LRUIterator move(LRUIterator & it, LRUFileCachePriority & other, const CachePriorityGuard::Lock &);
|
||||
LRUIterator add(EntryPtr entry, const CachePriorityGuard::Lock &);
|
||||
};
|
||||
|
||||
class LRUFileCachePriority::LRUIterator : public IFileCachePriority::Iterator
|
||||
@ -108,9 +108,9 @@ public:
|
||||
|
||||
EntryPtr getEntry() const override { return *iterator; }
|
||||
|
||||
size_t increasePriority(const CacheGuard::Lock &) override;
|
||||
size_t increasePriority(const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void remove(const CacheGuard::Lock &) override;
|
||||
void remove(const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void invalidate() override;
|
||||
|
||||
|
@ -16,7 +16,7 @@ static bool isQueryInitialized()
|
||||
&& !CurrentThread::getQueryId().empty();
|
||||
}
|
||||
|
||||
FileCacheQueryLimit::QueryContextPtr FileCacheQueryLimit::tryGetQueryContext(const CacheGuard::Lock &)
|
||||
FileCacheQueryLimit::QueryContextPtr FileCacheQueryLimit::tryGetQueryContext(const CachePriorityGuard::Lock &)
|
||||
{
|
||||
if (!isQueryInitialized())
|
||||
return nullptr;
|
||||
@ -25,7 +25,7 @@ FileCacheQueryLimit::QueryContextPtr FileCacheQueryLimit::tryGetQueryContext(con
|
||||
return (query_iter == query_map.end()) ? nullptr : query_iter->second;
|
||||
}
|
||||
|
||||
void FileCacheQueryLimit::removeQueryContext(const std::string & query_id, const CacheGuard::Lock &)
|
||||
void FileCacheQueryLimit::removeQueryContext(const std::string & query_id, const CachePriorityGuard::Lock &)
|
||||
{
|
||||
auto query_iter = query_map.find(query_id);
|
||||
if (query_iter == query_map.end())
|
||||
@ -41,7 +41,7 @@ void FileCacheQueryLimit::removeQueryContext(const std::string & query_id, const
|
||||
FileCacheQueryLimit::QueryContextPtr FileCacheQueryLimit::getOrSetQueryContext(
|
||||
const std::string & query_id,
|
||||
const ReadSettings & settings,
|
||||
const CacheGuard::Lock &)
|
||||
const CachePriorityGuard::Lock &)
|
||||
{
|
||||
if (query_id.empty())
|
||||
return nullptr;
|
||||
@ -70,7 +70,7 @@ void FileCacheQueryLimit::QueryContext::add(
|
||||
size_t offset,
|
||||
size_t size,
|
||||
const FileCache::UserInfo & user,
|
||||
const CacheGuard::Lock & lock)
|
||||
const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
auto it = getPriority().add(key_metadata, offset, size, user, lock);
|
||||
auto [_, inserted] = records.emplace(FileCacheKeyAndOffset{key_metadata->key, offset}, it);
|
||||
@ -87,7 +87,7 @@ void FileCacheQueryLimit::QueryContext::add(
|
||||
void FileCacheQueryLimit::QueryContext::remove(
|
||||
const Key & key,
|
||||
size_t offset,
|
||||
const CacheGuard::Lock & lock)
|
||||
const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
auto record = records.find({key, offset});
|
||||
if (record == records.end())
|
||||
@ -100,7 +100,7 @@ void FileCacheQueryLimit::QueryContext::remove(
|
||||
IFileCachePriority::IteratorPtr FileCacheQueryLimit::QueryContext::tryGet(
|
||||
const Key & key,
|
||||
size_t offset,
|
||||
const CacheGuard::Lock &)
|
||||
const CachePriorityGuard::Lock &)
|
||||
{
|
||||
auto it = records.find({key, offset});
|
||||
if (it == records.end())
|
||||
|
@ -13,14 +13,14 @@ public:
|
||||
class QueryContext;
|
||||
using QueryContextPtr = std::shared_ptr<QueryContext>;
|
||||
|
||||
QueryContextPtr tryGetQueryContext(const CacheGuard::Lock & lock);
|
||||
QueryContextPtr tryGetQueryContext(const CachePriorityGuard::Lock & lock);
|
||||
|
||||
QueryContextPtr getOrSetQueryContext(
|
||||
const std::string & query_id,
|
||||
const ReadSettings & settings,
|
||||
const CacheGuard::Lock &);
|
||||
const CachePriorityGuard::Lock &);
|
||||
|
||||
void removeQueryContext(const std::string & query_id, const CacheGuard::Lock &);
|
||||
void removeQueryContext(const std::string & query_id, const CachePriorityGuard::Lock &);
|
||||
|
||||
class QueryContext
|
||||
{
|
||||
@ -38,19 +38,19 @@ public:
|
||||
Priority::IteratorPtr tryGet(
|
||||
const Key & key,
|
||||
size_t offset,
|
||||
const CacheGuard::Lock &);
|
||||
const CachePriorityGuard::Lock &);
|
||||
|
||||
void add(
|
||||
KeyMetadataPtr key_metadata,
|
||||
size_t offset,
|
||||
size_t size,
|
||||
const FileCacheUserInfo & user,
|
||||
const CacheGuard::Lock &);
|
||||
const CachePriorityGuard::Lock &);
|
||||
|
||||
void remove(
|
||||
const Key & key,
|
||||
size_t offset,
|
||||
const CacheGuard::Lock &);
|
||||
const CachePriorityGuard::Lock &);
|
||||
|
||||
private:
|
||||
using Records = std::unordered_map<FileCacheKeyAndOffset, Priority::IteratorPtr, FileCacheKeyAndOffsetHash>;
|
||||
|
@ -34,19 +34,19 @@ SLRUFileCachePriority::SLRUFileCachePriority(
|
||||
probationary_queue.max_size, protected_queue.max_elements);
|
||||
}
|
||||
|
||||
size_t SLRUFileCachePriority::getSize(const CacheGuard::Lock & lock) const
|
||||
size_t SLRUFileCachePriority::getSize(const CachePriorityGuard::Lock & lock) const
|
||||
{
|
||||
return protected_queue.getSize(lock) + probationary_queue.getSize(lock);
|
||||
}
|
||||
|
||||
size_t SLRUFileCachePriority::getElementsCount(const CacheGuard::Lock & lock) const
|
||||
size_t SLRUFileCachePriority::getElementsCount(const CachePriorityGuard::Lock & lock) const
|
||||
{
|
||||
return protected_queue.getElementsCount(lock) + probationary_queue.getElementsCount(lock);
|
||||
}
|
||||
|
||||
bool SLRUFileCachePriority::canFit( /// NOLINT
|
||||
size_t size,
|
||||
const CacheGuard::Lock & lock,
|
||||
const CachePriorityGuard::Lock & lock,
|
||||
IteratorPtr reservee,
|
||||
bool best_effort) const
|
||||
{
|
||||
@ -70,7 +70,7 @@ IFileCachePriority::IteratorPtr SLRUFileCachePriority::add( /// NOLINT
|
||||
size_t offset,
|
||||
size_t size,
|
||||
const UserInfo &,
|
||||
const CacheGuard::Lock & lock,
|
||||
const CachePriorityGuard::Lock & lock,
|
||||
bool is_startup)
|
||||
{
|
||||
if (is_startup)
|
||||
@ -103,7 +103,7 @@ bool SLRUFileCachePriority::collectCandidatesForEviction(
|
||||
IFileCachePriority::IteratorPtr reservee,
|
||||
FinalizeEvictionFunc & finalize_eviction_func,
|
||||
const UserID & user_id,
|
||||
const CacheGuard::Lock & lock)
|
||||
const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
/// If `it` is nullptr, then it is the first space reservation attempt
|
||||
/// for a corresponding file segment, so it will be directly put into probationary queue.
|
||||
@ -143,7 +143,7 @@ bool SLRUFileCachePriority::collectCandidatesForEviction(
|
||||
&& !probationary_queue.collectCandidatesForEviction(size_to_downgrade, stat, res, reservee, noop, user_id, lock))
|
||||
return false;
|
||||
|
||||
finalize_eviction_func = [=, this](const CacheGuard::Lock & lk) mutable
|
||||
finalize_eviction_func = [=, this](const CachePriorityGuard::Lock & lk) mutable
|
||||
{
|
||||
for (const auto & [key, key_candidates] : *downgrade_candidates)
|
||||
{
|
||||
@ -159,7 +159,7 @@ bool SLRUFileCachePriority::collectCandidatesForEviction(
|
||||
return true;
|
||||
}
|
||||
|
||||
void SLRUFileCachePriority::increasePriority(SLRUIterator & iterator, const CacheGuard::Lock & lock)
|
||||
void SLRUFileCachePriority::increasePriority(SLRUIterator & iterator, const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
/// If entry is already in protected queue,
|
||||
/// we only need to increase its priority within the protected queue.
|
||||
@ -242,7 +242,7 @@ void SLRUFileCachePriority::increasePriority(SLRUIterator & iterator, const Cach
|
||||
iterator.is_protected = true;
|
||||
}
|
||||
|
||||
IFileCachePriority::PriorityDumpPtr SLRUFileCachePriority::dump(const CacheGuard::Lock & lock)
|
||||
IFileCachePriority::PriorityDumpPtr SLRUFileCachePriority::dump(const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
auto res = dynamic_pointer_cast<LRUFileCachePriority::LRUPriorityDump>(probationary_queue.dump(lock));
|
||||
auto part_res = dynamic_pointer_cast<LRUFileCachePriority::LRUPriorityDump>(protected_queue.dump(lock));
|
||||
@ -250,14 +250,14 @@ IFileCachePriority::PriorityDumpPtr SLRUFileCachePriority::dump(const CacheGuard
|
||||
return res;
|
||||
}
|
||||
|
||||
void SLRUFileCachePriority::shuffle(const CacheGuard::Lock & lock)
|
||||
void SLRUFileCachePriority::shuffle(const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
protected_queue.shuffle(lock);
|
||||
probationary_queue.shuffle(lock);
|
||||
}
|
||||
|
||||
bool SLRUFileCachePriority::modifySizeLimits(
|
||||
size_t max_size_, size_t max_elements_, double size_ratio_, const CacheGuard::Lock & lock)
|
||||
size_t max_size_, size_t max_elements_, double size_ratio_, const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
if (max_size == max_size_ && max_elements == max_elements_ && size_ratio == size_ratio_)
|
||||
return false; /// Nothing to change.
|
||||
@ -287,7 +287,7 @@ SLRUFileCachePriority::EntryPtr SLRUFileCachePriority::SLRUIterator::getEntry()
|
||||
return entry;
|
||||
}
|
||||
|
||||
size_t SLRUFileCachePriority::SLRUIterator::increasePriority(const CacheGuard::Lock & lock)
|
||||
size_t SLRUFileCachePriority::SLRUIterator::increasePriority(const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
assertValid();
|
||||
cache_priority->increasePriority(*this, lock);
|
||||
@ -306,7 +306,7 @@ void SLRUFileCachePriority::SLRUIterator::invalidate()
|
||||
lru_iterator.invalidate();
|
||||
}
|
||||
|
||||
void SLRUFileCachePriority::SLRUIterator::remove(const CacheGuard::Lock & lock)
|
||||
void SLRUFileCachePriority::SLRUIterator::remove(const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
assertValid();
|
||||
lru_iterator.remove(lock);
|
||||
|
@ -21,13 +21,13 @@ public:
|
||||
LRUFileCachePriority::StatePtr probationary_state_ = nullptr,
|
||||
LRUFileCachePriority::StatePtr protected_state_ = nullptr);
|
||||
|
||||
size_t getSize(const CacheGuard::Lock & lock) const override;
|
||||
size_t getSize(const CachePriorityGuard::Lock & lock) const override;
|
||||
|
||||
size_t getElementsCount(const CacheGuard::Lock &) const override;
|
||||
size_t getElementsCount(const CachePriorityGuard::Lock &) const override;
|
||||
|
||||
bool canFit( /// NOLINT
|
||||
size_t size,
|
||||
const CacheGuard::Lock &,
|
||||
const CachePriorityGuard::Lock &,
|
||||
IteratorPtr reservee = nullptr,
|
||||
bool best_effort = false) const override;
|
||||
|
||||
@ -36,7 +36,7 @@ public:
|
||||
size_t offset,
|
||||
size_t size,
|
||||
const UserInfo & user,
|
||||
const CacheGuard::Lock &,
|
||||
const CachePriorityGuard::Lock &,
|
||||
bool is_startup = false) override;
|
||||
|
||||
bool collectCandidatesForEviction(
|
||||
@ -46,13 +46,13 @@ public:
|
||||
IFileCachePriority::IteratorPtr reservee,
|
||||
FinalizeEvictionFunc & finalize_eviction_func,
|
||||
const UserID & user_id,
|
||||
const CacheGuard::Lock &) override;
|
||||
const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void shuffle(const CacheGuard::Lock &) override;
|
||||
void shuffle(const CachePriorityGuard::Lock &) override;
|
||||
|
||||
PriorityDumpPtr dump(const CacheGuard::Lock &) override;
|
||||
PriorityDumpPtr dump(const CachePriorityGuard::Lock &) override;
|
||||
|
||||
bool modifySizeLimits(size_t max_size_, size_t max_elements_, double size_ratio_, const CacheGuard::Lock &) override;
|
||||
bool modifySizeLimits(size_t max_size_, size_t max_elements_, double size_ratio_, const CachePriorityGuard::Lock &) override;
|
||||
|
||||
private:
|
||||
double size_ratio;
|
||||
@ -60,7 +60,7 @@ private:
|
||||
LRUFileCachePriority probationary_queue;
|
||||
LoggerPtr log = getLogger("SLRUFileCachePriority");
|
||||
|
||||
void increasePriority(SLRUIterator & iterator, const CacheGuard::Lock & lock);
|
||||
void increasePriority(SLRUIterator & iterator, const CachePriorityGuard::Lock & lock);
|
||||
};
|
||||
|
||||
class SLRUFileCachePriority::SLRUIterator : public IFileCachePriority::Iterator
|
||||
@ -74,9 +74,9 @@ public:
|
||||
|
||||
EntryPtr getEntry() const override;
|
||||
|
||||
size_t increasePriority(const CacheGuard::Lock &) override;
|
||||
size_t increasePriority(const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void remove(const CacheGuard::Lock &) override;
|
||||
void remove(const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void invalidate() override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user