ClickHouse/dbms/src/Common/CurrentThread.cpp

96 lines
2.3 KiB
C++
Raw Normal View History

#include <memory>
2018-05-29 18:14:31 +00:00
#include "CurrentThread.h"
#include <common/logger_useful.h>
#include <Common/ThreadStatus.h>
#include <Common/TaskStatsInfoGetter.h>
2018-05-29 18:14:31 +00:00
#include <Interpreters/ProcessList.h>
#include <Interpreters/Context.h>
2020-02-02 02:35:47 +00:00
#include <common/getThreadId.h>
#include <Poco/Logger.h>
2018-05-29 18:14:31 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
void CurrentThread::updatePerformanceCounters()
{
if (unlikely(!current_thread))
return;
current_thread->updatePerformanceCounters();
}
2018-05-29 18:14:31 +00:00
2019-08-12 15:16:23 +00:00
bool CurrentThread::isInitialized()
{
2019-08-12 16:33:21 +00:00
return current_thread;
2019-08-12 15:16:23 +00:00
}
2019-01-13 18:51:57 +00:00
ThreadStatus & CurrentThread::get()
2018-05-29 18:14:31 +00:00
{
2019-01-13 18:51:57 +00:00
if (unlikely(!current_thread))
2020-02-02 02:35:47 +00:00
throw Exception("Thread #" + std::to_string(getThreadId()) + " status was not initialized", ErrorCodes::LOGICAL_ERROR);
2018-05-29 18:14:31 +00:00
2019-01-13 18:51:57 +00:00
return *current_thread;
}
2018-05-29 18:14:31 +00:00
ProfileEvents::Counters & CurrentThread::getProfileEvents()
{
return current_thread ? current_thread->performance_counters : ProfileEvents::global_counters;
2018-05-29 18:14:31 +00:00
}
MemoryTracker * CurrentThread::getMemoryTracker()
2018-05-29 18:14:31 +00:00
{
if (unlikely(!current_thread))
return nullptr;
return &current_thread->memory_tracker;
2018-05-29 18:14:31 +00:00
}
void CurrentThread::updateProgressIn(const Progress & value)
{
if (unlikely(!current_thread))
return;
current_thread->progress_in.incrementPiecewiseAtomically(value);
}
void CurrentThread::updateProgressOut(const Progress & value)
{
if (unlikely(!current_thread))
return;
current_thread->progress_out.incrementPiecewiseAtomically(value);
}
2019-07-09 10:39:05 +00:00
void CurrentThread::attachInternalTextLogsQueue(const std::shared_ptr<InternalTextLogsQueue> & logs_queue,
LogsLevel client_logs_level)
{
if (unlikely(!current_thread))
return;
2019-07-09 10:39:05 +00:00
current_thread->attachInternalTextLogsQueue(logs_queue, client_logs_level);
}
std::shared_ptr<InternalTextLogsQueue> CurrentThread::getInternalTextLogsQueue()
{
/// NOTE: this method could be called at early server startup stage
if (unlikely(!current_thread))
return nullptr;
if (current_thread->getCurrentState() == ThreadStatus::ThreadState::Died)
return nullptr;
return current_thread->getInternalTextLogsQueue();
2018-05-29 18:14:31 +00:00
}
ThreadGroupStatusPtr CurrentThread::getGroup()
{
if (unlikely(!current_thread))
2019-01-25 18:44:30 +00:00
return nullptr;
return current_thread->getThreadGroup();
}
2018-05-29 18:14:31 +00:00
}