mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 11:02:08 +00:00
Merge pull request #5892 from yandex/thread-status-remove-bad-code
ThreadStatus: removed bad and questionable code
This commit is contained in:
commit
6dea389f26
@ -23,7 +23,7 @@ void CurrentThread::updatePerformanceCounters()
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().updatePerformanceCounters();
|
||||
current_thread->updatePerformanceCounters();
|
||||
}
|
||||
|
||||
ThreadStatus & CurrentThread::get()
|
||||
@ -36,35 +36,35 @@ ThreadStatus & CurrentThread::get()
|
||||
|
||||
ProfileEvents::Counters & CurrentThread::getProfileEvents()
|
||||
{
|
||||
return current_thread ? get().performance_counters : ProfileEvents::global_counters;
|
||||
return current_thread ? current_thread->performance_counters : ProfileEvents::global_counters;
|
||||
}
|
||||
|
||||
MemoryTracker * CurrentThread::getMemoryTracker()
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return nullptr;
|
||||
return &get().memory_tracker;
|
||||
return ¤t_thread->memory_tracker;
|
||||
}
|
||||
|
||||
void CurrentThread::updateProgressIn(const Progress & value)
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().progress_in.incrementPiecewiseAtomically(value);
|
||||
current_thread->progress_in.incrementPiecewiseAtomically(value);
|
||||
}
|
||||
|
||||
void CurrentThread::updateProgressOut(const Progress & value)
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().progress_out.incrementPiecewiseAtomically(value);
|
||||
current_thread->progress_out.incrementPiecewiseAtomically(value);
|
||||
}
|
||||
|
||||
void CurrentThread::attachInternalTextLogsQueue(const std::shared_ptr<InternalTextLogsQueue> & logs_queue)
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().attachInternalTextLogsQueue(logs_queue);
|
||||
current_thread->attachInternalTextLogsQueue(logs_queue);
|
||||
}
|
||||
|
||||
std::shared_ptr<InternalTextLogsQueue> CurrentThread::getInternalTextLogsQueue()
|
||||
@ -73,10 +73,10 @@ std::shared_ptr<InternalTextLogsQueue> CurrentThread::getInternalTextLogsQueue()
|
||||
if (unlikely(!current_thread))
|
||||
return nullptr;
|
||||
|
||||
if (get().getCurrentState() == ThreadStatus::ThreadState::Died)
|
||||
if (current_thread->getCurrentState() == ThreadStatus::ThreadState::Died)
|
||||
return nullptr;
|
||||
|
||||
return get().getInternalTextLogsQueue();
|
||||
return current_thread->getInternalTextLogsQueue();
|
||||
}
|
||||
|
||||
ThreadGroupStatusPtr CurrentThread::getGroup()
|
||||
@ -84,7 +84,7 @@ ThreadGroupStatusPtr CurrentThread::getGroup()
|
||||
if (unlikely(!current_thread))
|
||||
return nullptr;
|
||||
|
||||
return get().getThreadGroup();
|
||||
return current_thread->getThreadGroup();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <common/StringRef.h>
|
||||
#include <Common/ThreadStatus.h>
|
||||
|
||||
|
||||
@ -69,7 +70,7 @@ public:
|
||||
static void finalizePerformanceCounters();
|
||||
|
||||
/// Returns a non-empty string if the thread is attached to a query
|
||||
static const std::string & getQueryId();
|
||||
static StringRef getQueryId();
|
||||
|
||||
/// Non-master threads call this method in destructor automatically
|
||||
static void detachQuery();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/StringRef.h>
|
||||
#include <Common/ProfileEvents.h>
|
||||
#include <Common/MemoryTracker.h>
|
||||
|
||||
@ -114,7 +115,7 @@ public:
|
||||
return thread_state.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
const std::string & getQueryId() const;
|
||||
StringRef getQueryId() const;
|
||||
|
||||
/// Starts new query and create new thread group for it, current thread becomes master thread of the query
|
||||
void initializeQuery();
|
||||
|
@ -30,7 +30,7 @@ void ThreadStatus::attachQueryContext(Context & query_context_)
|
||||
}
|
||||
}
|
||||
|
||||
const std::string & ThreadStatus::getQueryId() const
|
||||
StringRef ThreadStatus::getQueryId() const
|
||||
{
|
||||
return query_id;
|
||||
}
|
||||
@ -39,8 +39,7 @@ void CurrentThread::defaultThreadDeleter()
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
ThreadStatus & thread = CurrentThread::get();
|
||||
thread.detachQuery(true, true);
|
||||
current_thread->detachQuery(true, true);
|
||||
}
|
||||
|
||||
void ThreadStatus::initializeQuery()
|
||||
@ -197,62 +196,59 @@ void CurrentThread::initializeQuery()
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().initializeQuery();
|
||||
get().deleter = CurrentThread::defaultThreadDeleter;
|
||||
current_thread->initializeQuery();
|
||||
current_thread->deleter = CurrentThread::defaultThreadDeleter;
|
||||
}
|
||||
|
||||
void CurrentThread::attachTo(const ThreadGroupStatusPtr & thread_group)
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().attachQuery(thread_group, true);
|
||||
get().deleter = CurrentThread::defaultThreadDeleter;
|
||||
current_thread->attachQuery(thread_group, true);
|
||||
current_thread->deleter = CurrentThread::defaultThreadDeleter;
|
||||
}
|
||||
|
||||
void CurrentThread::attachToIfDetached(const ThreadGroupStatusPtr & thread_group)
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().attachQuery(thread_group, false);
|
||||
get().deleter = CurrentThread::defaultThreadDeleter;
|
||||
current_thread->attachQuery(thread_group, false);
|
||||
current_thread->deleter = CurrentThread::defaultThreadDeleter;
|
||||
}
|
||||
|
||||
const std::string & CurrentThread::getQueryId()
|
||||
StringRef CurrentThread::getQueryId()
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
{
|
||||
const static std::string empty;
|
||||
return empty;
|
||||
}
|
||||
return get().getQueryId();
|
||||
return {};
|
||||
return current_thread->getQueryId();
|
||||
}
|
||||
|
||||
void CurrentThread::attachQueryContext(Context & query_context)
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
return get().attachQueryContext(query_context);
|
||||
return current_thread->attachQueryContext(query_context);
|
||||
}
|
||||
|
||||
void CurrentThread::finalizePerformanceCounters()
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().finalizePerformanceCounters();
|
||||
current_thread->finalizePerformanceCounters();
|
||||
}
|
||||
|
||||
void CurrentThread::detachQuery()
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().detachQuery(false);
|
||||
current_thread->detachQuery(false);
|
||||
}
|
||||
|
||||
void CurrentThread::detachQueryIfNotDetached()
|
||||
{
|
||||
if (unlikely(!current_thread))
|
||||
return;
|
||||
get().detachQuery(true);
|
||||
current_thread->detachQuery(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,7 +25,11 @@ ExtendedLogMessage ExtendedLogMessage::getFrom(const Poco::Message & base)
|
||||
msg_ext.time_microseconds = static_cast<UInt32>(tv.tv_usec);
|
||||
|
||||
if (current_thread)
|
||||
msg_ext.query_id = CurrentThread::getQueryId();
|
||||
{
|
||||
auto query_id_ref = CurrentThread::getQueryId();
|
||||
if (query_id_ref.size)
|
||||
msg_ext.query_id.assign(query_id_ref.data, query_id_ref.size);
|
||||
}
|
||||
|
||||
msg_ext.thread_number = getThreadNumber();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user