mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 19:42:00 +00:00
Fix assertion
This commit is contained in:
parent
6428868843
commit
eb9690016a
@ -10,12 +10,6 @@ public:
|
||||
using FinalizeEvictionFunc = std::function<void(const CachePriorityGuard::Lock & lk)>;
|
||||
|
||||
EvictionCandidates() = default;
|
||||
EvictionCandidates(EvictionCandidates && other) noexcept
|
||||
{
|
||||
candidates = std::move(other.candidates);
|
||||
candidates_size = std::move(other.candidates_size);
|
||||
queue_entries_to_invalidate = std::move(other.queue_entries_to_invalidate);
|
||||
}
|
||||
~EvictionCandidates();
|
||||
|
||||
void add(
|
||||
|
@ -1388,8 +1388,8 @@ void FileCache::applySettingsIfPossible(const FileCacheSettings & new_settings,
|
||||
if (new_settings.max_size != actual_settings.max_size
|
||||
|| new_settings.max_elements != actual_settings.max_elements)
|
||||
{
|
||||
std::optional<EvictionCandidates> eviction_candidates;
|
||||
bool modified_size_limits = false;
|
||||
EvictionCandidates eviction_candidates;
|
||||
bool limits_satisfied = false;
|
||||
{
|
||||
cache_is_being_resized.store(true, std::memory_order_relaxed);
|
||||
SCOPE_EXIT({
|
||||
@ -1399,15 +1399,12 @@ void FileCache::applySettingsIfPossible(const FileCacheSettings & new_settings,
|
||||
auto cache_lock = lockCache();
|
||||
|
||||
FileCacheReserveStat stat;
|
||||
eviction_candidates.emplace(main_priority->collectCandidatesForEviction(
|
||||
new_settings.max_size, new_settings.max_elements, 0/* max_candidates_to_evict */, stat, cache_lock));
|
||||
limits_satisfied = main_priority->collectCandidatesForEviction(
|
||||
new_settings.max_size, new_settings.max_elements, 0/* max_candidates_to_evict */, stat, eviction_candidates, cache_lock);
|
||||
|
||||
eviction_candidates->removeQueueEntries(cache_lock);
|
||||
eviction_candidates.removeQueueEntries(cache_lock);
|
||||
|
||||
modified_size_limits = main_priority->getSize(cache_lock) <= new_settings.max_size
|
||||
&& main_priority->getElementsCount(cache_lock) <= new_settings.max_elements;
|
||||
|
||||
if (modified_size_limits)
|
||||
if (limits_satisfied)
|
||||
{
|
||||
main_priority->modifySizeLimits(
|
||||
new_settings.max_size, new_settings.max_elements, new_settings.slru_size_ratio, cache_lock);
|
||||
@ -1423,16 +1420,16 @@ void FileCache::applySettingsIfPossible(const FileCacheSettings & new_settings,
|
||||
|
||||
try
|
||||
{
|
||||
eviction_candidates->evict();
|
||||
eviction_candidates.evict();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
auto cache_lock = lockCache();
|
||||
eviction_candidates->finalize(nullptr, cache_lock);
|
||||
eviction_candidates.finalize(nullptr, cache_lock);
|
||||
throw;
|
||||
}
|
||||
|
||||
if (modified_size_limits)
|
||||
if (limits_satisfied)
|
||||
{
|
||||
LOG_INFO(log, "Changed max_size from {} to {}, max_elements from {} to {}",
|
||||
actual_settings.max_size, new_settings.max_size,
|
||||
|
@ -147,11 +147,12 @@ public:
|
||||
const CachePriorityGuard::Lock &) = 0;
|
||||
|
||||
/// Collect eviction `candidates_num` candidates for eviction.
|
||||
virtual EvictionCandidates collectCandidatesForEviction(
|
||||
virtual bool collectCandidatesForEviction(
|
||||
size_t desired_size,
|
||||
size_t desired_elements_count,
|
||||
size_t max_candidates_to_evict,
|
||||
FileCacheReserveStat & stat,
|
||||
EvictionCandidates & candidates,
|
||||
const CachePriorityGuard::Lock &) = 0;
|
||||
|
||||
virtual bool modifySizeLimits(
|
||||
|
@ -322,14 +322,14 @@ bool LRUFileCachePriority::collectCandidatesForEviction(
|
||||
}
|
||||
}
|
||||
|
||||
EvictionCandidates LRUFileCachePriority::collectCandidatesForEviction(
|
||||
bool LRUFileCachePriority::collectCandidatesForEviction(
|
||||
size_t desired_size,
|
||||
size_t desired_elements_count,
|
||||
size_t max_candidates_to_evict,
|
||||
FileCacheReserveStat & stat,
|
||||
EvictionCandidates & res,
|
||||
const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
EvictionCandidates res;
|
||||
auto stop_condition = [&, this]()
|
||||
{
|
||||
return canFit(0, 0, stat.total_stat.releasable_size, stat.total_stat.releasable_count,
|
||||
@ -337,7 +337,7 @@ EvictionCandidates LRUFileCachePriority::collectCandidatesForEviction(
|
||||
|| (max_candidates_to_evict && res.size() >= max_candidates_to_evict);
|
||||
};
|
||||
iterateForEviction(res, stat, stop_condition, lock);
|
||||
return res;
|
||||
return stop_condition();
|
||||
}
|
||||
|
||||
void LRUFileCachePriority::iterateForEviction(
|
||||
|
@ -62,11 +62,12 @@ public:
|
||||
const UserID & user_id,
|
||||
const CachePriorityGuard::Lock &) override;
|
||||
|
||||
EvictionCandidates collectCandidatesForEviction(
|
||||
bool collectCandidatesForEviction(
|
||||
size_t desired_size,
|
||||
size_t desired_elements_count,
|
||||
size_t max_candidates_to_evict,
|
||||
FileCacheReserveStat & stat,
|
||||
EvictionCandidates & res,
|
||||
const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void shuffle(const CachePriorityGuard::Lock &) override;
|
||||
|
@ -251,42 +251,47 @@ bool SLRUFileCachePriority::collectCandidatesForEvictionInProtected(
|
||||
return true;
|
||||
}
|
||||
|
||||
EvictionCandidates SLRUFileCachePriority::collectCandidatesForEviction(
|
||||
bool SLRUFileCachePriority::collectCandidatesForEviction(
|
||||
size_t desired_size,
|
||||
size_t desired_elements_count,
|
||||
size_t max_candidates_to_evict,
|
||||
FileCacheReserveStat & stat,
|
||||
EvictionCandidates & res,
|
||||
const CachePriorityGuard::Lock & lock)
|
||||
{
|
||||
const auto desired_probationary_size = getRatio(desired_size, 1 - size_ratio);
|
||||
const auto desired_probationary_elements_num = getRatio(desired_elements_count, 1 - size_ratio);
|
||||
|
||||
auto res = probationary_queue.collectCandidatesForEviction(
|
||||
desired_probationary_size, desired_probationary_elements_num, max_candidates_to_evict, stat, lock);
|
||||
FileCacheReserveStat probationary_stat;
|
||||
const bool probationary_limit_satisfied = probationary_queue.collectCandidatesForEviction(
|
||||
desired_probationary_size, desired_probationary_elements_num,
|
||||
max_candidates_to_evict, probationary_stat, res, lock);
|
||||
|
||||
LOG_TEST(log, "Collected {} eviction candidates from probationary queue (size: {})",
|
||||
res.size(), stat.total_stat.releasable_size);
|
||||
stat += probationary_stat;
|
||||
|
||||
LOG_TEST(log, "Collected {} to evict from probationary queue. Total size: {}",
|
||||
res.size(), probationary_stat.total_stat.releasable_size);
|
||||
|
||||
chassert(!max_candidates_to_evict || res.size() <= max_candidates_to_evict);
|
||||
chassert(res.size() == stat.total_stat.releasable_count);
|
||||
|
||||
if (max_candidates_to_evict && res.size() == max_candidates_to_evict)
|
||||
return res;
|
||||
if (max_candidates_to_evict && res.size() >= max_candidates_to_evict)
|
||||
return probationary_limit_satisfied;
|
||||
|
||||
const auto desired_protected_size = getRatio(max_size, size_ratio);
|
||||
const auto desired_protected_elements_num = getRatio(max_elements, size_ratio);
|
||||
|
||||
FileCacheReserveStat protected_stat;
|
||||
auto res_add = protected_queue.collectCandidatesForEviction(
|
||||
const bool protected_limit_satisfied = protected_queue.collectCandidatesForEviction(
|
||||
desired_protected_size, desired_protected_elements_num,
|
||||
max_candidates_to_evict ? max_candidates_to_evict - res.size() : 0, protected_stat, lock);
|
||||
|
||||
LOG_TEST(log, "Collected {} eviction candidates from protected queue (size: {})",
|
||||
res_add.size(), protected_stat.total_stat.releasable_size);
|
||||
max_candidates_to_evict - res.size(), protected_stat, res, lock);
|
||||
|
||||
stat += protected_stat;
|
||||
res.insert(std::move(res_add), lock);
|
||||
return res;
|
||||
|
||||
LOG_TEST(log, "Collected {} to evict from protected queue. Total size: {}",
|
||||
res.size(), protected_stat.total_stat.releasable_size);
|
||||
|
||||
return probationary_limit_satisfied && protected_limit_satisfied;
|
||||
}
|
||||
|
||||
void SLRUFileCachePriority::downgrade(IteratorPtr iterator, const CachePriorityGuard::Lock & lock)
|
||||
|
@ -58,11 +58,12 @@ public:
|
||||
const UserID & user_id,
|
||||
const CachePriorityGuard::Lock &) override;
|
||||
|
||||
EvictionCandidates collectCandidatesForEviction(
|
||||
bool collectCandidatesForEviction(
|
||||
size_t desired_size,
|
||||
size_t desired_elements_count,
|
||||
size_t max_candidates_to_evict,
|
||||
FileCacheReserveStat & stat,
|
||||
EvictionCandidates & res,
|
||||
const CachePriorityGuard::Lock &) override;
|
||||
|
||||
void shuffle(const CachePriorityGuard::Lock &) override;
|
||||
|
Loading…
Reference in New Issue
Block a user