Fixes after merge

This commit is contained in:
kssenii 2024-03-28 17:00:54 +01:00
parent 52a08a7aa0
commit fd925770b2
4 changed files with 43 additions and 42 deletions

View File

@ -7,15 +7,17 @@ namespace DB
class EvictionCandidates
{
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);
on_finalize = std::move(other.on_finalize);
queue_entries_to_invalidate = std::move(other.queue_entries_to_invalidate);
finalize_eviction_func = std::move(other.finalize_eviction_func);
hold_space = std::move(other.hold_space);
}
using FinalizeEvictionFunc = std::function<void(const CachePriorityGuard::Lock & lk)>;
~EvictionCandidates();

View File

@ -997,7 +997,7 @@ void FileCache::freeSpaceRatioKeepingThreadFunc()
main_priority->getSize(lock), size_limit,
main_priority->getElementsCount(lock), elements_limit,
desired_size, desired_elements_num,
eviction_candidates.size(), stat.stat.non_releasable_count);
eviction_candidates.size(), stat.total_stat.non_releasable_count);
lock.unlock();
eviction_candidates.evict();
@ -1345,7 +1345,8 @@ void FileCache::deactivateBackgroundOperations()
{
shutdown.store(true);
metadata.shutdown();
keep_up_free_space_ratio_task->deactivate();
if (keep_up_free_space_ratio_task)
keep_up_free_space_ratio_task->deactivate();
}
std::vector<FileSegment::Info> FileCache::getFileSegmentInfos(const UserID & user_id)

View File

@ -275,10 +275,43 @@ bool LRUFileCachePriority::collectCandidatesForEviction(
auto can_fit = [&]
{
return canFit(size, 1, stat.stat.releasable_size, stat.stat.releasable_count, nullptr, nullptr, lock);
return canFit(size, elements, stat.total_stat.releasable_size, stat.total_stat.releasable_count, lock);
};
iterateForEviction(res, stat, can_fit, lock);
return can_fit();
if (can_fit())
{
/// As eviction is done without a cache priority lock,
/// then if some space was partially available and some needed
/// to be freed via eviction, we need to make sure that this
/// partially available space is still available
/// after we finish with eviction for non-available space.
/// So we create a space holder for the currently available part
/// of the required space for the duration of eviction of the other
/// currently non-available part of the space.
const size_t hold_size = size > stat.total_stat.releasable_size
? size - stat.total_stat.releasable_size
: 0;
const size_t hold_elements = elements > stat.total_stat.releasable_count
? elements - stat.total_stat.releasable_count
: 0;
if (hold_size || hold_elements)
res.setSpaceHolder(hold_size, hold_elements, *this, lock);
// LOG_TEST(log, "Collected {} candidates for eviction (total size: {}). "
// "Took hold of size {} and elements {}",
// res.size(), stat.total_stat.releasable_size, hold_size, hold_elements);
return true;
}
else
{
return false;
}
}
EvictionCandidates LRUFileCachePriority::collectCandidatesForEviction(
@ -334,41 +367,6 @@ void LRUFileCachePriority::iterateForEviction(
}, lock);
}
if (can_fit())
{
/// As eviction is done without a cache priority lock,
/// then if some space was partially available and some needed
/// to be freed via eviction, we need to make sure that this
/// partially available space is still available
/// after we finish with eviction for non-available space.
/// So we create a space holder for the currently available part
/// of the required space for the duration of eviction of the other
/// currently non-available part of the space.
const size_t hold_size = size > stat.total_stat.releasable_size
? size - stat.total_stat.releasable_size
: 0;
const size_t hold_elements = elements > stat.total_stat.releasable_count
? elements - stat.total_stat.releasable_count
: 0;
if (hold_size || hold_elements)
res.setSpaceHolder(hold_size, hold_elements, *this, lock);
// LOG_TEST(log, "Collected {} candidates for eviction (total size: {}). "
// "Took hold of size {} and elements {}",
// res.size(), stat.total_stat.releasable_size, hold_size, hold_elements);
return true;
}
else
{
return false;
}
}
LRUFileCachePriority::LRUIterator LRUFileCachePriority::move(
LRUIterator & it,
LRUFileCachePriority & other,

View File

@ -266,7 +266,7 @@ EvictionCandidates SLRUFileCachePriority::collectCandidatesForEviction(
desired_probationary_size, desired_probationary_elements_num, max_candidates_to_evict, stat, lock);
chassert(res.size() <= max_candidates_to_evict);
chassert(res.size() == stat.stat.releasable_count);
chassert(res.size() == stat.total_stat.releasable_count);
if (res.size() == max_candidates_to_evict)
return res;