From 599a02ca0da1a97c996638454e58a62456089384 Mon Sep 17 00:00:00 2001 From: kssenii Date: Thu, 13 Apr 2023 18:53:16 +0200 Subject: [PATCH] Fix --- programs/local/LocalServer.cpp | 1 + src/Disks/ObjectStorages/DiskObjectStorage.cpp | 1 + src/Interpreters/Cache/FileCache.cpp | 1 + src/Interpreters/Cache/FileSegment.cpp | 10 +--------- src/Interpreters/Cache/FileSegment.h | 1 + src/Interpreters/Cache/LRUFileCachePriority.cpp | 4 ++-- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index 5768e744f94..bbfd73af476 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Disks/ObjectStorages/DiskObjectStorage.cpp b/src/Disks/ObjectStorages/DiskObjectStorage.cpp index 6143f0620b8..0dc070ee917 100644 --- a/src/Disks/ObjectStorages/DiskObjectStorage.cpp +++ b/src/Disks/ObjectStorages/DiskObjectStorage.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include diff --git a/src/Interpreters/Cache/FileCache.cpp b/src/Interpreters/Cache/FileCache.cpp index 7bdb97e527d..d7497f068b6 100644 --- a/src/Interpreters/Cache/FileCache.cpp +++ b/src/Interpreters/Cache/FileCache.cpp @@ -664,6 +664,7 @@ bool FileCache::tryReserve(FileSegment & file_segment, size_t size) throw Exception(ErrorCodes::LOGICAL_ERROR, "Cache became inconsistent. There must be a bug"); file_segment.getKeyMetadata()->createBaseDirectory(); + file_segment.reserved_size += size; return true; } diff --git a/src/Interpreters/Cache/FileSegment.cpp b/src/Interpreters/Cache/FileSegment.cpp index 63c666d04c5..35d9c0e16cd 100644 --- a/src/Interpreters/Cache/FileSegment.cpp +++ b/src/Interpreters/Cache/FileSegment.cpp @@ -380,7 +380,7 @@ FileSegment::State FileSegment::wait(size_t offset) chassert(!getDownloaderUnlocked(lock).empty()); chassert(!isDownloaderUnlocked(lock)); - [[maybe_unused]] auto ok = cv.wait_for(lock, std::chrono::seconds(60), [&, this]() + [[maybe_unused]] const auto ok = cv.wait_for(lock, std::chrono::seconds(60), [&, this]() { return download_state != State::DOWNLOADING || offset < getCurrentWriteOffset(true); }); @@ -467,14 +467,6 @@ bool FileSegment::reserve(size_t size_to_reserve) segment_range.right = range().left + expected_downloaded_size + size_to_reserve; reserved = cache->tryReserve(*this, size_to_reserve); - if (reserved) - { - /// No lock is required because reserved size is always - /// mananaged (read/modified) by the downloader only - /// or in isLastOwnerOfFileSegment() case. - /// It is made atomic because of getInfoForLog. - reserved_size += size_to_reserve; - } chassert(assertCorrectness()); } diff --git a/src/Interpreters/Cache/FileSegment.h b/src/Interpreters/Cache/FileSegment.h index 6defe969ba4..6a40be3280c 100644 --- a/src/Interpreters/Cache/FileSegment.h +++ b/src/Interpreters/Cache/FileSegment.h @@ -64,6 +64,7 @@ struct CreateFileSegmentSettings class FileSegment : private boost::noncopyable, public std::enable_shared_from_this { friend struct LockedKey; +friend class FileCache; /// Because of reserved_size in tryReserve(). public: using Key = FileCacheKey; diff --git a/src/Interpreters/Cache/LRUFileCachePriority.cpp b/src/Interpreters/Cache/LRUFileCachePriority.cpp index 9a0e2d8fb05..9853a09a3d3 100644 --- a/src/Interpreters/Cache/LRUFileCachePriority.cpp +++ b/src/Interpreters/Cache/LRUFileCachePriority.cpp @@ -113,8 +113,8 @@ void LRUFileCachePriority::iterate(IterateFunc && func, const CacheGuard::Lock & { throw Exception( ErrorCodes::LOGICAL_ERROR, - "Mismatch of file segment size in file segment metadata and priority queue: {} != {}", - it->size, metadata->size()); + "Mismatch of file segment size in file segment metadata and priority queue: {} != {} ({})", + it->size, metadata->size(), metadata->file_segment->getInfoForLog()); } auto result = func(*locked_key, metadata);