ClickHouse/src/Common/CurrentThread.cpp

103 lines
2.5 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);
}
2020-06-20 11:17:15 +00:00
void CurrentThread::setFatalErrorCallback(std::function<void()> callback)
{
if (unlikely(!current_thread))
return;
current_thread->setFatalErrorCallback(callback);
}
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
}