Fix the issue in the comment above.

This commit is contained in:
Yarik Briukhovetskyi 2024-11-19 20:14:23 +01:00 committed by GitHub
parent f956c2c4a9
commit 7599020b87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 18 deletions

View File

@ -42,7 +42,7 @@ void CancellationChecker::terminateThread()
cond_var.notify_all();
}
void CancellationChecker::cancelTask(QueryToTrack task, [[maybe_unused]]CancelReason reason)
void CancellationChecker::cancelTask(QueryToTrack task)
{
if (task.query)
{
@ -123,7 +123,7 @@ void CancellationChecker::workerFunction()
if ((end_time_ms <= now_ms && duration_milliseconds.count() != 0))
{
LOG_TRACE(getLogger("CancellationChecker"), "Cancelling the task because of the timeout: {} ms, query: {}", duration, next_task.query->getInfo().query);
cancelTask(next_task, CancelReason::TIMEOUT);
cancelTask(next_task);
querySet.erase(next_task);
continue;

View File

@ -46,7 +46,7 @@ private:
std::condition_variable cond_var;
// Function to execute when a task's endTime is reached
void cancelTask(QueryToTrack task, CancelReason reason);
void cancelTask(QueryToTrack task);
bool removeQueryFromSet(std::shared_ptr<QueryStatus> query);
public:

View File

@ -498,28 +498,26 @@ CancellationCode QueryStatus::cancelQuery(CancelReason reason, std::exception_pt
return CancellationCode::CancelSent;
}
void QueryStatus::throwProperExceptionIfNeeded(const UInt64 & max_execution_time, const UInt64 & elapsed_ns) const
void QueryStatus::throwProperExceptionIfNeeded(const UInt64 & max_execution_time, const UInt64 & elapsed_ns)
{
{
std::lock_guard<std::mutex> lock(cancel_mutex);
if (is_killed)
{
throwProperException(max_execution_time, elapsed_ns);
String additional_error_part;
if (!elapsed_ns)
additional_error_part = fmt::format("elapsed {} ms, ", static_cast<double>(elapsed_ns) / 1000000000ULL);
if (cancel_reason == CancelReason::TIMEOUT)
{
cancel_reason = CancelReason::UNDEFINED; // We can assign only CancelReason::TIMEOUT to cancel_reason, so we need to assign it back to UNDEFINED
throw Exception(ErrorCodes::TIMEOUT_EXCEEDED, "Timeout exceeded: {}maximum: {} ms", additional_error_part, max_execution_time / 1000.0);
}
throwQueryWasCancelled();
}
}
}
void QueryStatus::throwProperException(const UInt64 & max_execution_time, const UInt64 & elapsed_ns) const
{
String additional_error_part;
if (!elapsed_ns)
additional_error_part = fmt::format("elapsed {} ms,", static_cast<double>(elapsed_ns) / 1000000000ULL);
if (cancel_reason == CancelReason::TIMEOUT)
throw Exception(ErrorCodes::TIMEOUT_EXCEEDED, "Timeout exceeded: {} maximum: {} ms", additional_error_part, max_execution_time / 1000.0);
throwQueryWasCancelled();
}
void QueryStatus::addPipelineExecutor(PipelineExecutor * e)
{
/// In case of asynchronous distributed queries it is possible to call

View File

@ -240,8 +240,7 @@ public:
QueryStatusInfo getInfo(bool get_thread_list = false, bool get_profile_events = false, bool get_settings = false) const;
void throwProperExceptionIfNeeded(const UInt64 & max_execution_time, const UInt64 & elapsed_ns = 0) const;
[[noreturn]] void throwProperException(const UInt64 & max_execution_time, const UInt64 & elapsed_ns = 0) const;
void throwProperExceptionIfNeeded(const UInt64 & max_execution_time, const UInt64 & elapsed_ns = 0);
/// Cancels the current query.
/// Optional argument `exception` allows to set an exception which checkTimeLimit() will throw instead of "QUERY_WAS_CANCELLED".