BackgroundSchedulePool should not have any query context

BackgroundSchedulePool is used for some peridic jobs, not from the query
context, i.e. flush of Buffer table.

And for such jobs there cannot be any query context, and more
importantly it will not work correctly since that query_context will
eventually expires.

And this is the reason of this failures [1].

  [1]: https://s3.amazonaws.com/clickhouse-test-reports/46668/015991bc5e20c787851050c2eaa13f0fef3aac00/stateless_tests_flaky_check__asan_.html

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2023-02-22 10:41:57 +01:00
parent 2d4eae386a
commit 2ca47a6eb6
4 changed files with 0 additions and 35 deletions

View File

@ -252,36 +252,10 @@ void BackgroundSchedulePool::cancelDelayedTask(const TaskInfoPtr & task, std::lo
}
scope_guard BackgroundSchedulePool::attachToThreadGroup()
{
scope_guard guard = [&]()
{
if (thread_group)
CurrentThread::detachQueryIfNotDetached();
};
std::lock_guard lock(delayed_tasks_mutex);
if (thread_group)
{
/// Put all threads to one thread pool
CurrentThread::attachTo(thread_group);
}
else
{
CurrentThread::initializeQuery();
thread_group = CurrentThread::getGroup();
}
return guard;
}
void BackgroundSchedulePool::threadFunction()
{
setThreadName(thread_name.c_str());
auto detach_thread_guard = attachToThreadGroup();
while (!shutdown)
{
TaskInfoPtr task;
@ -311,8 +285,6 @@ void BackgroundSchedulePool::delayExecutionThreadFunction()
{
setThreadName((thread_name + "/D").c_str());
auto detach_thread_guard = attachToThreadGroup();
while (!shutdown)
{
TaskInfoPtr task;

View File

@ -90,13 +90,8 @@ private:
/// Tasks ordered by scheduled time.
DelayedTasks delayed_tasks;
/// Thread group used for profiling purposes
ThreadGroupStatusPtr thread_group;
CurrentMetrics::Metric tasks_metric;
std::string thread_name;
[[nodiscard]] scope_guard attachToThreadGroup();
};

View File

@ -3,7 +3,6 @@
#include <condition_variable>
#include <memory>
#include <optional>
#include <Core/BackgroundSchedulePool.h>
#include <Functions/FunctionsLogical.h>
#include <Interpreters/Context.h>
#include <Interpreters/ExpressionActions.h>

View File

@ -4,7 +4,6 @@
#include <Interpreters/ExpressionActionsSettings.h>
#include <Storages/MergeTree/MergeTreeReadPool.h>
#include <Storages/MergeTree/MergeTreeIOSettings.h>
#include <Core/BackgroundSchedulePool.h>
#include <IO/AsyncReadCounters.h>
#include <queue>