mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
One more fix
This commit is contained in:
parent
faf783e66f
commit
a4afe0ad06
@ -76,12 +76,22 @@ void EvictionCandidates::removeQueueEntries(const CachePriorityGuard::Lock & loc
|
||||
|
||||
for (const auto & [key, key_candidates] : candidates)
|
||||
{
|
||||
auto locked_key = key_candidates.key_metadata->lock();
|
||||
for (const auto & candidate : key_candidates.candidates)
|
||||
{
|
||||
auto queue_iterator = candidate->getQueueIterator();
|
||||
queue_iterator->invalidate();
|
||||
|
||||
candidate->file_segment->resetQueueIterator();
|
||||
/// We need to set removed flag in file segment metadata,
|
||||
/// because in dynamic cache resize we first remove queue entries,
|
||||
/// then evict which also removes file segment metadata,
|
||||
/// but we need to make sure that this file segment is not requested from cache in the meantime.
|
||||
/// In ordinary eviction we use `evicting` flag for this purpose,
|
||||
/// but here we cannot, because `evicting` is a property of a queue entry,
|
||||
/// but at this point for dynamic cache resize we have already deleted all queue entries.
|
||||
candidate->setRemovedFlag(*locked_key, lock);
|
||||
|
||||
queue_iterator->remove(lock);
|
||||
}
|
||||
}
|
||||
@ -191,7 +201,7 @@ void EvictionCandidates::finalize(
|
||||
/// now we can release. It might also be needed for on_finalize func,
|
||||
/// so release the space it firtst.
|
||||
if (hold_space)
|
||||
hold_space.reset();
|
||||
hold_space->release();
|
||||
|
||||
while (!queue_entries_to_invalidate.empty())
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
|
||||
void finalize(
|
||||
FileCacheQueryLimit::QueryContext * query_context,
|
||||
const CachePriorityGuard::Lock & lock);
|
||||
const CachePriorityGuard::Lock &);
|
||||
|
||||
bool needFinalize() const;
|
||||
|
||||
|
@ -223,7 +223,7 @@ FileSegments FileCache::getImpl(const LockedKey & locked_key, const FileSegment:
|
||||
return false;
|
||||
|
||||
FileSegmentPtr file_segment;
|
||||
if (!file_segment_metadata.isEvicting(locked_key))
|
||||
if (!file_segment_metadata.isEvictingOrRemoved(locked_key))
|
||||
{
|
||||
file_segment = file_segment_metadata.file_segment;
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ void CacheMetadata::downloadThreadFunc(const bool & stop_flag)
|
||||
continue;
|
||||
|
||||
auto file_segment_metadata = locked_key->tryGetByOffset(offset);
|
||||
if (!file_segment_metadata || file_segment_metadata->isEvicting(*locked_key))
|
||||
if (!file_segment_metadata || file_segment_metadata->isEvictingOrRemoved(*locked_key))
|
||||
continue;
|
||||
|
||||
auto file_segment = file_segment_weak.lock();
|
||||
@ -881,7 +881,7 @@ bool LockedKey::removeAllFileSegments(bool if_releasable)
|
||||
removed_all = false;
|
||||
continue;
|
||||
}
|
||||
else if (it->second->isEvicting(*this))
|
||||
else if (it->second->isEvictingOrRemoved(*this))
|
||||
{
|
||||
/// File segment is currently a removal candidate,
|
||||
/// we do not know if it will be removed or not yet,
|
||||
@ -1104,7 +1104,7 @@ std::vector<FileSegment::Info> LockedKey::sync()
|
||||
std::vector<FileSegment::Info> broken;
|
||||
for (auto it = key_metadata->begin(); it != key_metadata->end();)
|
||||
{
|
||||
if (it->second->isEvicting(*this) || !it->second->releasable())
|
||||
if (it->second->isEvictingOrRemoved(*this) || !it->second->releasable())
|
||||
{
|
||||
++it;
|
||||
continue;
|
||||
|
@ -34,18 +34,18 @@ struct FileSegmentMetadata : private boost::noncopyable
|
||||
|
||||
size_t size() const;
|
||||
|
||||
bool isEvicting(const CachePriorityGuard::Lock & lock) const
|
||||
bool isEvictingOrRemoved(const CachePriorityGuard::Lock & lock) const
|
||||
{
|
||||
auto iterator = getQueueIterator();
|
||||
if (!iterator)
|
||||
if (!iterator || removed)
|
||||
return false;
|
||||
return iterator->getEntry()->isEvicting(lock);
|
||||
}
|
||||
|
||||
bool isEvicting(const LockedKey & lock) const
|
||||
bool isEvictingOrRemoved(const LockedKey & lock) const
|
||||
{
|
||||
auto iterator = getQueueIterator();
|
||||
if (!iterator)
|
||||
if (!iterator || removed)
|
||||
return false;
|
||||
return iterator->getEntry()->isEvicting(lock);
|
||||
}
|
||||
@ -58,6 +58,11 @@ struct FileSegmentMetadata : private boost::noncopyable
|
||||
iterator->getEntry()->setEvictingFlag(locked_key, lock);
|
||||
}
|
||||
|
||||
void setRemovedFlag(const LockedKey &, const CachePriorityGuard::Lock &)
|
||||
{
|
||||
removed = true;
|
||||
}
|
||||
|
||||
void resetEvictingFlag() const
|
||||
{
|
||||
auto iterator = getQueueIterator();
|
||||
@ -69,6 +74,8 @@ struct FileSegmentMetadata : private boost::noncopyable
|
||||
Priority::IteratorPtr getQueueIterator() const { return file_segment->getQueueIterator(); }
|
||||
|
||||
FileSegmentPtr file_segment;
|
||||
private:
|
||||
bool removed = false;
|
||||
};
|
||||
|
||||
using FileSegmentMetadataPtr = std::shared_ptr<FileSegmentMetadata>;
|
||||
|
Loading…
Reference in New Issue
Block a user