This commit is contained in:
kssenii 2022-02-15 10:11:33 +01:00
parent bdbbe85f95
commit 690dcea8be
3 changed files with 13 additions and 16 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;