From b91f18033c428ae315954870ee2a4bfd764e6d92 Mon Sep 17 00:00:00 2001 From: KinderRiven <1339764596@qq.com> Date: Wed, 20 Apr 2022 19:43:07 +0800 Subject: [PATCH] fix bug for local cache --- src/Common/FileSegment.cpp | 9 ++++++++- src/Common/FileSegment.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Common/FileSegment.cpp b/src/Common/FileSegment.cpp index 9fe95c0d8cd..5281773a968 100644 --- a/src/Common/FileSegment.cpp +++ b/src/Common/FileSegment.cpp @@ -646,6 +646,13 @@ void FileSegment::assertNotDetached() const throw Exception(ErrorCodes::LOGICAL_ERROR, "Operation not allowed, file segment is detached"); } +void FileSegment::assertDetachedStatus() const +{ + assert( + (download_state == State::EMPTY) || (download_state == State::PARTIALLY_DOWNLOADED) + || (download_state == State::PARTIALLY_DOWNLOADED_NO_CONTINUATION) || (downloaded_stated == State::SKIP_CACHE)); +} + FileSegmentPtr FileSegment::getSnapshot(const FileSegmentPtr & file_segment, std::lock_guard & /* cache_lock */) { auto snapshot = std::make_shared( @@ -683,7 +690,7 @@ FileSegmentsHolder::~FileSegmentsHolder() { /// This file segment is not owned by cache, so it will be destructed /// at this point, therefore no completion required. - assert(file_segment->state() == FileSegment::State::EMPTY); + file_segment->assertDetachedStatus(); file_segment_it = file_segments.erase(current_file_segment_it); continue; } diff --git a/src/Common/FileSegment.h b/src/Common/FileSegment.h index e3011eeb0fa..2f883c0fb02 100644 --- a/src/Common/FileSegment.h +++ b/src/Common/FileSegment.h @@ -151,6 +151,7 @@ private: String getInfoForLogImpl(std::lock_guard & segment_lock) const; void assertCorrectnessImpl(std::lock_guard & segment_lock) const; void assertNotDetached() const; + void assertDetachedStatus() const; void setDownloaded(std::lock_guard & segment_lock); void setDownloadFailed(std::lock_guard & segment_lock);