mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Fix uncaught exception from destructor
This commit is contained in:
parent
c20c7453a8
commit
28a3aece60
@ -51,8 +51,21 @@ size_t FileSegment::getDownloadOffset() const
|
||||
|
||||
String FileSegment::getCallerId()
|
||||
{
|
||||
if (!CurrentThread::isInitialized() || CurrentThread::getQueryId().size == 0)
|
||||
return getCallerIdImpl(false);
|
||||
}
|
||||
|
||||
String FileSegment::getCallerIdImpl(bool allow_non_strict_checking)
|
||||
{
|
||||
if (IFileCache::shouldBypassCache())
|
||||
{
|
||||
/// getCallerId() can be called from completeImpl(), which can be called from complete().
|
||||
/// complete() is called from destructor of CachedReadBufferFromRemoteFS when there is no query id anymore.
|
||||
/// Allow non strict checking only for internal usage.
|
||||
if (allow_non_strict_checking)
|
||||
return "None";
|
||||
|
||||
throw Exception(ErrorCodes::REMOTE_FS_OBJECT_CACHE_ERROR, "Cannot use cache without query id");
|
||||
}
|
||||
|
||||
return CurrentThread::getQueryId().toString() + ":" + toString(getThreadId());
|
||||
}
|
||||
@ -321,7 +334,7 @@ void FileSegment::complete()
|
||||
cv.notify_all();
|
||||
}
|
||||
|
||||
void FileSegment::completeImpl()
|
||||
void FileSegment::completeImpl(bool allow_non_strict_checking)
|
||||
{
|
||||
/// cache lock is always taken before segment lock.
|
||||
std::lock_guard cache_lock(cache->mutex);
|
||||
@ -361,7 +374,7 @@ void FileSegment::completeImpl()
|
||||
}
|
||||
}
|
||||
|
||||
if (downloader_id == getCallerId())
|
||||
if (!downloader_id.empty() && downloader_id == getCallerIdImpl(allow_non_strict_checking))
|
||||
{
|
||||
LOG_TEST(log, "Clearing downloader id: {}, current state: {}", downloader_id, stateToString(download_state));
|
||||
downloader_id.clear();
|
||||
|
@ -125,8 +125,9 @@ private:
|
||||
size_t availableSize() const { return reserved_size - downloaded_size; }
|
||||
bool lastFileSegmentHolder() const;
|
||||
void complete();
|
||||
void completeImpl();
|
||||
void completeImpl(bool allow_non_strict_checking = false);
|
||||
void setDownloaded(std::lock_guard<std::mutex> & segment_lock);
|
||||
static String getCallerIdImpl(bool allow_non_strict_checking = false);
|
||||
|
||||
const Range segment_range;
|
||||
|
||||
@ -164,7 +165,18 @@ struct FileSegmentsHolder : private boost::noncopyable
|
||||
/// remain only uncompleted file segments.
|
||||
|
||||
for (auto & segment : file_segments)
|
||||
{
|
||||
segment->complete();
|
||||
|
||||
// try
|
||||
// {
|
||||
// segment->complete();
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// tryLogCurrentException(__PRETTY_FUNCTION__);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
FileSegments file_segments{};
|
||||
|
@ -491,22 +491,22 @@ bool CachedReadBufferFromRemoteFS::nextImpl()
|
||||
if (current_file_segment_it == file_segments_holder->file_segments.end())
|
||||
return false;
|
||||
|
||||
// SCOPE_EXIT({
|
||||
// if (current_file_segment_it == file_segments_holder->file_segments.end())
|
||||
// return;
|
||||
SCOPE_EXIT({
|
||||
if (current_file_segment_it == file_segments_holder->file_segments.end())
|
||||
return;
|
||||
|
||||
// auto & file_segment = *current_file_segment_it;
|
||||
auto & file_segment = *current_file_segment_it;
|
||||
|
||||
// bool download_current_segment = read_type == ReadType::REMOTE_FS_READ_AND_PUT_IN_CACHE;
|
||||
// if (download_current_segment)
|
||||
// {
|
||||
// bool file_segment_already_completed = !file_segment->isDownloader();
|
||||
// if (!file_segment_already_completed)
|
||||
// file_segment->completeBatchAndResetDownloader();
|
||||
// }
|
||||
bool download_current_segment = read_type == ReadType::REMOTE_FS_READ_AND_PUT_IN_CACHE;
|
||||
if (download_current_segment)
|
||||
{
|
||||
bool file_segment_already_completed = !file_segment->isDownloader();
|
||||
if (!file_segment_already_completed)
|
||||
file_segment->completeBatchAndResetDownloader();
|
||||
}
|
||||
|
||||
// assert(!file_segment->isDownloader());
|
||||
// });
|
||||
assert(!file_segment->isDownloader());
|
||||
});
|
||||
|
||||
bytes_to_predownload = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user