mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-14 19:45:11 +00:00
Move ThreadGroupSwitcher to ThreadStatus.h (out from MergeTree code)
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
parent
5b2b20a0b0
commit
aacf2a0838
@ -41,7 +41,6 @@ class TaskStatsInfoGetter;
|
||||
class InternalTextLogsQueue;
|
||||
struct ViewRuntimeData;
|
||||
class QueryViewsLog;
|
||||
class ThreadGroupSwitcher;
|
||||
using InternalTextLogsQueuePtr = std::shared_ptr<InternalTextLogsQueue>;
|
||||
using InternalTextLogsQueueWeakPtr = std::weak_ptr<InternalTextLogsQueue>;
|
||||
|
||||
@ -120,6 +119,21 @@ private:
|
||||
std::unordered_set<UInt64> thread_ids;
|
||||
};
|
||||
|
||||
/**
|
||||
* Since merge is executed with multiple threads, this class
|
||||
* switches the parent MemoryTracker as part of the thread group to account all the memory used.
|
||||
*/
|
||||
class ThreadGroupSwitcher : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
explicit ThreadGroupSwitcher(ThreadGroupPtr thread_group);
|
||||
~ThreadGroupSwitcher();
|
||||
|
||||
private:
|
||||
ThreadGroupPtr prev_thread_group;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* We use **constinit** here to tell the compiler the current_thread variable is initialized.
|
||||
* If we didn't help the compiler, then it would most likely add a check before every use of the variable to initialize it if needed.
|
||||
|
@ -115,6 +115,24 @@ void ThreadGroup::attachInternalProfileEventsQueue(const InternalProfileEventsQu
|
||||
shared_data.profile_queue_ptr = profile_queue;
|
||||
}
|
||||
|
||||
ThreadGroupSwitcher::ThreadGroupSwitcher(ThreadGroupPtr thread_group)
|
||||
{
|
||||
chassert(thread_group);
|
||||
|
||||
/// might be nullptr
|
||||
prev_thread_group = CurrentThread::getGroup();
|
||||
|
||||
CurrentThread::detachFromGroupIfNotDetached();
|
||||
CurrentThread::attachToGroup(thread_group);
|
||||
}
|
||||
|
||||
ThreadGroupSwitcher::~ThreadGroupSwitcher()
|
||||
{
|
||||
CurrentThread::detachFromGroupIfNotDetached();
|
||||
if (prev_thread_group)
|
||||
CurrentThread::attachToGroup(prev_thread_group);
|
||||
}
|
||||
|
||||
void ThreadStatus::attachInternalProfileEventsQueue(const InternalProfileEventsQueuePtr & profile_queue)
|
||||
{
|
||||
if (!thread_group)
|
||||
|
@ -11,24 +11,6 @@ namespace DB
|
||||
{
|
||||
|
||||
|
||||
ThreadGroupSwitcher::ThreadGroupSwitcher(ThreadGroupPtr thread_group)
|
||||
{
|
||||
chassert(thread_group);
|
||||
|
||||
/// might be nullptr
|
||||
prev_thread_group = CurrentThread::getGroup();
|
||||
|
||||
CurrentThread::detachFromGroupIfNotDetached();
|
||||
CurrentThread::attachToGroup(thread_group);
|
||||
}
|
||||
|
||||
ThreadGroupSwitcher::~ThreadGroupSwitcher()
|
||||
{
|
||||
CurrentThread::detachFromGroupIfNotDetached();
|
||||
if (prev_thread_group)
|
||||
CurrentThread::attachToGroup(prev_thread_group);
|
||||
}
|
||||
|
||||
MergeListElement::MergeListElement(
|
||||
const StorageID & table_id_,
|
||||
FutureMergedMutatedPartPtr future_part,
|
||||
|
@ -62,20 +62,6 @@ using MergeListEntry = BackgroundProcessListEntry<MergeListElement, MergeInfo>;
|
||||
struct Settings;
|
||||
|
||||
|
||||
/**
|
||||
* Since merge is executed with multiple threads, this class
|
||||
* switches the parent MemoryTracker as part of the thread group to account all the memory used.
|
||||
*/
|
||||
class ThreadGroupSwitcher : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
explicit ThreadGroupSwitcher(ThreadGroupPtr thread_group);
|
||||
~ThreadGroupSwitcher();
|
||||
|
||||
private:
|
||||
ThreadGroupPtr prev_thread_group;
|
||||
};
|
||||
|
||||
struct MergeListElement : boost::noncopyable
|
||||
{
|
||||
const StorageID table_id;
|
||||
|
Loading…
Reference in New Issue
Block a user