2018-09-05 21:01:43 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2018-05-29 18:14:31 +00:00
|
|
|
#include "CurrentThread.h"
|
|
|
|
#include <common/logger_useful.h>
|
2018-05-31 15:54:08 +00:00
|
|
|
#include <Common/ThreadStatus.h>
|
2018-09-16 00:14:55 +00:00
|
|
|
#include <Common/TaskStatsInfoGetter.h>
|
2018-05-29 18:14:31 +00:00
|
|
|
#include <Interpreters/ProcessList.h>
|
2018-06-15 17:32:35 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2020-02-02 02:35:47 +00:00
|
|
|
#include <common/getThreadId.h>
|
2018-05-31 15:54:08 +00:00
|
|
|
#include <Poco/Logger.h>
|
2018-05-29 18:14:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2018-06-20 17:49:52 +00:00
|
|
|
void CurrentThread::updatePerformanceCounters()
|
|
|
|
{
|
2019-03-14 18:03:35 +00:00
|
|
|
if (unlikely(!current_thread))
|
|
|
|
return;
|
2019-07-05 14:15:05 +00:00
|
|
|
current_thread->updatePerformanceCounters();
|
2018-06-20 17:49:52 +00:00
|
|
|
}
|
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-09-05 21:01:43 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:14:31 +00:00
|
|
|
ProfileEvents::Counters & CurrentThread::getProfileEvents()
|
|
|
|
{
|
2019-07-05 14:15:05 +00:00
|
|
|
return current_thread ? current_thread->performance_counters : ProfileEvents::global_counters;
|
2018-05-29 18:14:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 18:03:35 +00:00
|
|
|
MemoryTracker * CurrentThread::getMemoryTracker()
|
2018-05-29 18:14:31 +00:00
|
|
|
{
|
2019-03-14 18:03:35 +00:00
|
|
|
if (unlikely(!current_thread))
|
|
|
|
return nullptr;
|
2019-07-05 14:15:05 +00:00
|
|
|
return ¤t_thread->memory_tracker;
|
2018-05-29 18:14:31 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 15:54:08 +00:00
|
|
|
void CurrentThread::updateProgressIn(const Progress & value)
|
|
|
|
{
|
2019-03-14 18:03:35 +00:00
|
|
|
if (unlikely(!current_thread))
|
|
|
|
return;
|
2019-07-05 14:15:05 +00:00
|
|
|
current_thread->progress_in.incrementPiecewiseAtomically(value);
|
2018-05-31 15:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CurrentThread::updateProgressOut(const Progress & value)
|
|
|
|
{
|
2019-03-14 18:03:35 +00:00
|
|
|
if (unlikely(!current_thread))
|
|
|
|
return;
|
2019-07-05 14:15:05 +00:00
|
|
|
current_thread->progress_out.incrementPiecewiseAtomically(value);
|
2018-05-31 15:54:08 +00:00
|
|
|
}
|
|
|
|
|
2019-07-09 10:39:05 +00:00
|
|
|
void CurrentThread::attachInternalTextLogsQueue(const std::shared_ptr<InternalTextLogsQueue> & logs_queue,
|
|
|
|
LogsLevel client_logs_level)
|
2018-06-06 20:57:07 +00:00
|
|
|
{
|
2019-03-14 18:03:35 +00:00
|
|
|
if (unlikely(!current_thread))
|
|
|
|
return;
|
2019-07-09 10:39:05 +00:00
|
|
|
current_thread->attachInternalTextLogsQueue(logs_queue, client_logs_level);
|
2018-06-06 20:57:07 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 17:32:35 +00:00
|
|
|
std::shared_ptr<InternalTextLogsQueue> CurrentThread::getInternalTextLogsQueue()
|
2018-06-06 20:57:07 +00:00
|
|
|
{
|
|
|
|
/// NOTE: this method could be called at early server startup stage
|
2019-03-14 18:03:35 +00:00
|
|
|
if (unlikely(!current_thread))
|
2018-06-06 20:57:07 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2019-07-05 14:15:05 +00:00
|
|
|
if (current_thread->getCurrentState() == ThreadStatus::ThreadState::Died)
|
2018-06-06 20:57:07 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2019-07-05 14:15:05 +00:00
|
|
|
return current_thread->getInternalTextLogsQueue();
|
2018-05-29 18:14:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 15:21:42 +00:00
|
|
|
ThreadGroupStatusPtr CurrentThread::getGroup()
|
|
|
|
{
|
2019-03-14 18:03:35 +00:00
|
|
|
if (unlikely(!current_thread))
|
2019-01-25 18:44:30 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2019-07-05 14:15:05 +00:00
|
|
|
return current_thread->getThreadGroup();
|
2018-06-20 15:21:42 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:14:31 +00:00
|
|
|
}
|