From 690dcea8beeb02a8019a83bd5e98b15f0150cfcb Mon Sep 17 00:00:00 2001 From: kssenii Date: Tue, 15 Feb 2022 10:11:33 +0100 Subject: [PATCH] Style --- src/Common/FileCache.cpp | 8 +++----- src/Common/FileSegment.cpp | 19 +++++++++---------- src/Common/FileSegment.h | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Common/FileCache.cpp b/src/Common/FileCache.cpp index 23f9a169d80..9b18b8e005f 100644 --- a/src/Common/FileCache.cpp +++ b/src/Common/FileCache.cpp @@ -60,7 +60,7 @@ bool FileCache::shouldBypassCache() { return !CurrentThread::isInitialized() || !CurrentThread::get().getQueryContext() - || !CurrentThread::getQueryId().size; + || CurrentThread::getQueryId().size == 0; } LRUFileCache::LRUFileCache(const String & cache_base_path_, size_t max_size_, size_t max_element_size_) @@ -401,7 +401,6 @@ void LRUFileCache::remove( auto cache_file_path = path(key, offset); if (fs::exists(cache_file_path)) { - std::cerr << "\n\n\nRemoving cache file for file segment key: " << keyToStr(key) << " and offset: " << offset << "\n\n\n"; try { fs::remove(cache_file_path); @@ -444,7 +443,7 @@ void LRUFileCache::restore() if (!parsed) { LOG_WARNING(log, "Unexpected file: ", offset_it->path().string()); - continue; /// Or remove? Some unexpected file. + continue; /// Or just remove? Some unexpected file. } size = offset_it->file_size(); @@ -572,8 +571,7 @@ bool LRUFileCache::isLastFileSegmentHolder( if (!cell) throw Exception(ErrorCodes::LOGICAL_ERROR, "No cell found for key: {}, offset: {}", keyToStr(key), offset); - /// The caller of this method is last file segment holder if use count is 2 and the second - /// pointer is cache itself, + /// The caller of this method is last file segment holder if use count is 2 (the second pointer is cache itself) return cell->file_segment.use_count() == 2; } diff --git a/src/Common/FileSegment.cpp b/src/Common/FileSegment.cpp index dd82f87152e..0f3e8ed0515 100644 --- a/src/Common/FileSegment.cpp +++ b/src/Common/FileSegment.cpp @@ -123,7 +123,6 @@ void FileSegment::write(const char * from, size_t size) "Only downloader can do the downloading. (CallerId: {}, DownloaderId: {})", getCallerId(), downloader_id); - std::cerr << "\n\n\nWRITE: " << size << ", file info: " << getInfoForLog() << "\n\n\n"; if (!cache_writer) { auto download_path = cache->path(key(), offset()); @@ -137,7 +136,7 @@ void FileSegment::write(const char * from, size_t size) } catch (...) { - /// TODO: Mark this segment as NO_DOWNLOAD and remove from cache? + download_state = State::PARTIALLY_DOWNLOADED_NO_CONTINUATION; throw; } @@ -165,7 +164,7 @@ FileSegment::State FileSegment::wait() } #endif - cv.wait_for(segment_lock, std::chrono::seconds(60)); /// TODO: pass through settings + cv.wait_for(segment_lock, std::chrono::seconds(60)); /// TODO: make configurable by setting } return download_state; @@ -213,8 +212,6 @@ void FileSegment::completeBatchAndResetDownloader() std::lock_guard segment_lock(mutex); bool is_downloader = downloader_id == getCallerId(); - std::cerr << "caller id: " << getCallerId() << "\n"; - std::cerr << "downloader id: " << downloader_id << "\n"; if (!is_downloader) { cv.notify_all(); @@ -237,7 +234,7 @@ void FileSegment::completeBatchAndResetDownloader() cv.notify_all(); } -void FileSegment::complete(State state, bool error) +void FileSegment::complete(State state, bool complete_because_of_error) { { std::lock_guard segment_lock(mutex); @@ -249,10 +246,6 @@ void FileSegment::complete(State state, bool error) throw Exception(ErrorCodes::FILE_CACHE_ERROR, "File segment can be completed only by downloader or downloader's FileSegmentsHodler"); } - else if (error) - { - remote_file_reader.reset(); - } if (state != State::DOWNLOADED && state != State::PARTIALLY_DOWNLOADED @@ -263,6 +256,12 @@ void FileSegment::complete(State state, bool error) "Cannot complete file segment with state: {}", stateToString(state)); } + if (complete_because_of_error) + { + /// Let's use a new buffer on the next attempt in this case. + remote_file_reader.reset(); + } + download_state = state; completeImpl(segment_lock); } diff --git a/src/Common/FileSegment.h b/src/Common/FileSegment.h index 9505e61a8e3..d2807aead9c 100644 --- a/src/Common/FileSegment.h +++ b/src/Common/FileSegment.h @@ -113,7 +113,7 @@ public: void completeBatchAndResetDownloader(); - void complete(State state, bool error = false); + void complete(State state, bool complete_because_of_error = false); String getInfoForLog() const;