add proper thread termination

This commit is contained in:
Yarik Briukhovetskyi 2024-10-04 20:46:28 +02:00 committed by GitHub
parent 568e25889b
commit 4ec7b10c73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 6 deletions

View File

@ -2318,6 +2318,8 @@ try
if (current_connections)
current_connections = waitServersToFinish(servers, servers_lock, server_settings.shutdown_wait_unfinished);
CancellationChecker::getInstance().terminateThread();
if (current_connections)
LOG_WARNING(log, "Closed connections. But {} remain."
" Tip: To increase wait time add to config: <shutdown_wait_unfinished>60</shutdown_wait_unfinished>", current_connections);

View File

@ -30,17 +30,20 @@ CancellationChecker::CancellationChecker() : stop_thread(false)
{
}
CancellationChecker::~CancellationChecker()
{
stop_thread = true;
}
CancellationChecker& CancellationChecker::getInstance()
{
static CancellationChecker instance;
return instance;
}
void CancellationChecker::terminateThread()
{
LOG_TRACE(getLogger("CancellationChecker"), "Stopping CancellationChecker");
stop_thread = true;
cond_var.notify_all();
}
void CancellationChecker::cancelTask(std::shared_ptr<QueryStatus> query, CancelReason reason)
{
query->cancelQuery(/*kill=*/false, /*reason=*/reason);

View File

@ -34,7 +34,6 @@ class CancellationChecker
{
private:
CancellationChecker();
~CancellationChecker();
// Priority queue to manage tasks based on endTime
std::multiset<QueryToTrack, CompareEndTime> querySet;
@ -55,6 +54,8 @@ public:
CancellationChecker(const CancellationChecker&) = delete;
CancellationChecker& operator=(const CancellationChecker&) = delete;
void terminateThread();
// Method to add a new task to the multiset
void appendTask(const std::shared_ptr<QueryStatus> & query, const Int64 & timeout);