Merge pull request #8831 from ClickHouse/revert-8820-issue-6964

Revert "Initialize query profiler for all threads in a group"
This commit is contained in:
alexey-milovidov 2020-01-25 23:34:33 +03:00 committed by GitHub
commit a21d3712eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 35 deletions

View File

@ -203,9 +203,6 @@ protected:
/// Set to non-nullptr only if we have enough capabilities. /// Set to non-nullptr only if we have enough capabilities.
std::unique_ptr<TaskStatsInfoGetter> taskstats_getter; std::unique_ptr<TaskStatsInfoGetter> taskstats_getter;
private:
void setupState(const ThreadGroupStatusPtr & thread_group_);
}; };
} }

View File

@ -50,11 +50,40 @@ void CurrentThread::defaultThreadDeleter()
current_thread->detachQuery(true, true); current_thread->detachQuery(true, true);
} }
void ThreadStatus::setupState(const ThreadGroupStatusPtr & thread_group_) void ThreadStatus::initializeQuery()
{ {
assertState({ThreadState::DetachedFromQuery}, __PRETTY_FUNCTION__); assertState({ThreadState::DetachedFromQuery}, __PRETTY_FUNCTION__);
/// Attach or init current thread to thread group and copy useful information from it thread_group = std::make_shared<ThreadGroupStatus>();
performance_counters.setParent(&thread_group->performance_counters);
memory_tracker.setParent(&thread_group->memory_tracker);
thread_group->memory_tracker.setDescription("(for query)");
thread_group->thread_numbers.emplace_back(thread_number);
thread_group->os_thread_ids.emplace_back(os_thread_id);
thread_group->master_thread_number = thread_number;
thread_group->master_thread_os_id = os_thread_id;
initPerformanceCounters();
thread_state = ThreadState::AttachedToQuery;
}
void ThreadStatus::attachQuery(const ThreadGroupStatusPtr & thread_group_, bool check_detached)
{
if (thread_state == ThreadState::AttachedToQuery)
{
if (check_detached)
throw Exception("Can't attach query to the thread, it is already attached", ErrorCodes::LOGICAL_ERROR);
return;
}
assertState({ThreadState::DetachedFromQuery}, __PRETTY_FUNCTION__);
if (!thread_group_)
throw Exception("Attempt to attach to nullptr thread group", ErrorCodes::LOGICAL_ERROR);
/// Attach current thread to thread group and copy useful information from it
thread_group = thread_group_; thread_group = thread_group_;
performance_counters.setParent(&thread_group->performance_counters); performance_counters.setParent(&thread_group->performance_counters);
@ -63,22 +92,22 @@ void ThreadStatus::setupState(const ThreadGroupStatusPtr & thread_group_)
{ {
std::lock_guard lock(thread_group->mutex); std::lock_guard lock(thread_group->mutex);
/// NOTE: thread may be attached multiple times if it is reused from a thread pool.
thread_group->thread_numbers.emplace_back(thread_number);
thread_group->os_thread_ids.emplace_back(os_thread_id);
logs_queue_ptr = thread_group->logs_queue_ptr; logs_queue_ptr = thread_group->logs_queue_ptr;
query_context = thread_group->query_context; query_context = thread_group->query_context;
if (!global_context) if (!global_context)
global_context = thread_group->global_context; global_context = thread_group->global_context;
/// NOTE: A thread may be attached multiple times if it is reused from a thread pool.
thread_group->thread_numbers.emplace_back(thread_number);
thread_group->os_thread_ids.emplace_back(os_thread_id);
} }
if (query_context) if (query_context)
{ {
query_id = query_context->getCurrentQueryId(); query_id = query_context->getCurrentQueryId();
#if defined(OS_LINUX) #if defined(__linux__)
/// Set "nice" value if required. /// Set "nice" value if required.
Int32 new_os_thread_priority = query_context->getSettingsRef().os_thread_priority; Int32 new_os_thread_priority = query_context->getSettingsRef().os_thread_priority;
if (new_os_thread_priority && hasLinuxCapability(CAP_SYS_NICE)) if (new_os_thread_priority && hasLinuxCapability(CAP_SYS_NICE))
@ -99,31 +128,6 @@ void ThreadStatus::setupState(const ThreadGroupStatusPtr & thread_group_)
thread_state = ThreadState::AttachedToQuery; thread_state = ThreadState::AttachedToQuery;
} }
void ThreadStatus::initializeQuery()
{
setupState(std::make_shared<ThreadGroupStatus>());
/// No need to lock on mutex here
thread_group->memory_tracker.setDescription("(for query)");
thread_group->master_thread_number = thread_number;
thread_group->master_thread_os_id = os_thread_id;
}
void ThreadStatus::attachQuery(const ThreadGroupStatusPtr & thread_group_, bool check_detached)
{
if (thread_state == ThreadState::AttachedToQuery)
{
if (check_detached)
throw Exception("Can't attach query to the thread, it is already attached", ErrorCodes::LOGICAL_ERROR);
return;
}
if (!thread_group_)
throw Exception("Attempt to attach to nullptr thread group", ErrorCodes::LOGICAL_ERROR);
setupState(thread_group_);
}
void ThreadStatus::finalizePerformanceCounters() void ThreadStatus::finalizePerformanceCounters()
{ {
if (performance_counters_finalized) if (performance_counters_finalized)