From d14f86cfe89c3ca2886c674f13a7913e4d5f4807 Mon Sep 17 00:00:00 2001 From: kssenii Date: Thu, 16 Feb 2023 14:33:23 +0100 Subject: [PATCH] Get rid of download_mutex --- src/Interpreters/Cache/FileSegment.cpp | 6 ------ src/Interpreters/Cache/FileSegment.h | 10 +--------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/Interpreters/Cache/FileSegment.cpp b/src/Interpreters/Cache/FileSegment.cpp index c8fe38c2020..7003db02b91 100644 --- a/src/Interpreters/Cache/FileSegment.cpp +++ b/src/Interpreters/Cache/FileSegment.cpp @@ -132,10 +132,6 @@ size_t FileSegment::getDownloadedSize() const size_t FileSegment::getDownloadedSizeUnlocked(const FileSegmentGuard::Lock &) const { - if (download_state == State::DOWNLOADED) - return downloaded_size; - - std::unique_lock download_lock(download_mutex); return downloaded_size; } @@ -357,8 +353,6 @@ void FileSegment::write(const char * from, size_t size, size_t offset) { cache_writer->write(from, size); - std::unique_lock download_lock(download_mutex); - cache_writer->next(); downloaded_size += size; diff --git a/src/Interpreters/Cache/FileSegment.h b/src/Interpreters/Cache/FileSegment.h index fe1fae91d4f..042038741fc 100644 --- a/src/Interpreters/Cache/FileSegment.h +++ b/src/Interpreters/Cache/FileSegment.h @@ -317,7 +317,7 @@ private: LocalCacheWriterPtr cache_writer; /// downloaded_size should always be less or equal to reserved_size - size_t downloaded_size = 0; + std::atomic downloaded_size = 0; size_t reserved_size = 0; /// global locking order rule: @@ -328,14 +328,6 @@ private: LockedKeyCreatorPtr locked_key_creator; std::condition_variable cv; - /// Protects downloaded_size access with actual write into fs. - /// downloaded_size is not protected by download_mutex in methods which - /// can never be run in parallel to FileSegment::write() method - /// as downloaded_size is updated only in FileSegment::write() method. - /// Such methods are identified by isDownloader() check at their start, - /// e.g. they are executed strictly by the same thread, sequentially. - mutable std::mutex download_mutex; - Key file_key; const std::string file_path; FileCache * cache;