MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / sendCancelToQuery

Method sendCancelToQuery

src/Interpreters/ProcessList.cpp:710–743  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

708
709
710CancellationCode ProcessList::sendCancelToQuery(const String & current_query_id, const String & current_user)
711{
712 QueryStatusPtr elem;
713
714 /// Cancelling the query should be done without the lock.
715 ///
716 /// Since it may be not that trivial, for example in case of distributed
717 /// queries it tries to cancel the query gracefully on shards and this can
718 /// take a while, so acquiring a lock during this time will lead to wait
719 /// all new queries for this cancellation.
720 ///
721 /// Another problem is that it can lead to a deadlock, because of
722 /// OvercommitTracker.
723 ///
724 /// So here we first set is_cancelling, and later reset it.
725 /// The ProcessListEntry cannot be destroy if is_cancelling is true.
726 {
727 LockAndBlocker lock(mutex);
728 elem = tryGetProcessListElement(current_query_id, current_user);
729 if (!elem)
730 return CancellationCode::NotFound;
731 elem->is_cancelling = true;
732 }
733
734 SCOPE_EXIT({
735 DENY_ALLOCATIONS_IN_SCOPE;
736
737 Lock lock(mutex);
738 elem->is_cancelling = false;
739 cancelled_cv.notify_all();
740 });
741
742 return elem->cancelQuery(CancelReason::CANCELLED_BY_USER);
743}
744
745
746CancellationCode ProcessList::sendCancelToQuery(QueryStatusPtr elem)

Callers 4

cancelMethod · 0.80
generateMethod · 0.80
executeMethod · 0.80

Calls 1

cancelQueryMethod · 0.45

Tested by

no test coverage detected