This commit is contained in:
kssenii 2022-04-27 20:01:59 +02:00
parent 9410e2813f
commit da1392877a
4 changed files with 9 additions and 5 deletions

View File

@ -573,7 +573,7 @@ void LRUFileCache::remove(bool force_remove_unreleasable)
if (file_segment)
{
std::lock_guard<std::mutex> segment_lock(file_segment->mutex);
file_segment->detach(segment_lock);
file_segment->detach(cache_lock, segment_lock);
remove(file_segment->key(), file_segment->offset(), cache_lock, segment_lock);
}
}

View File

@ -498,7 +498,11 @@ void FileSegment::complete(State state)
void FileSegment::complete(std::lock_guard<std::mutex> & cache_lock)
{
std::lock_guard segment_lock(mutex);
completeUnlocked(cache_lock, segment_lock);
}
void FileSegment::completeUnlocked(std::lock_guard<std::mutex> & cache_lock, std::lock_guard<std::mutex> & segment_lock)
{
if (download_state == State::SKIP_CACHE || detached)
return;
@ -671,7 +675,7 @@ FileSegmentPtr FileSegment::getSnapshot(const FileSegmentPtr & file_segment, std
return snapshot;
}
void FileSegment::detach(std::lock_guard<std::mutex> & segment_lock)
void FileSegment::detach(std::lock_guard<std::mutex> & cache_lock, std::lock_guard<std::mutex> & segment_lock)
{
if (detached)
return;
@ -684,7 +688,7 @@ void FileSegment::detach(std::lock_guard<std::mutex> & segment_lock)
if (!has_finalized_state)
{
complete(segment_lock);
completeUnlocked(cache_lock, segment_lock);
}
}

View File

@ -144,7 +144,7 @@ public:
static FileSegmentPtr getSnapshot(const FileSegmentPtr & file_segment, std::lock_guard<std::mutex> & cache_lock);
void detach(std::lock_guard<std::mutex> & segment_lock);
void detach(std::lock_guard<std::mutex> & cache_lock, std::lock_guard<std::mutex> & segment_lock);
private:
size_t availableSize() const { return reserved_size - downloaded_size; }
@ -169,6 +169,7 @@ private:
/// is the last alive holder of the segment. Therefore, complete() and destruction
/// of the file segment pointer must be done under the same cache mutex.
void complete(std::lock_guard<std::mutex> & cache_lock);
void completeUnlocked(std::lock_guard<std::mutex> & cache_lock, std::lock_guard<std::mutex> & segment_lock);
void completeImpl(
std::lock_guard<std::mutex> & cache_lock,

View File

@ -46,7 +46,6 @@ CachedReadBufferFromRemoteFS::CachedReadBufferFromRemoteFS(
void CachedReadBufferFromRemoteFS::initialize(size_t offset, size_t size)
{
if (settings.read_from_filesystem_cache_if_exists_otherwise_bypass_cache)
{
file_segments_holder.emplace(cache->get(cache_key, offset, size));