ClickHouse/dbms/src/Common/CurrentThread.h

58 lines
1.5 KiB
C++
Raw Normal View History

2018-05-29 18:14:31 +00:00
#pragma once
#include <memory>
namespace ProfileEvents
{
class Counters;
2018-05-29 18:14:31 +00:00
}
class MemoryTracker;
namespace DB
{
class QueryStatus;
class ThreadStatus;
struct Progress;
2018-05-29 18:14:31 +00:00
using ThreadStatusPtr = std::shared_ptr<ThreadStatus>;
class CurrentThread
{
public:
static ThreadStatusPtr get();
/// Call when thread accepted connection (but haven't called executeQuery())
/// Currently it is used only for debugging
static void initializeQuery();
2018-05-29 18:14:31 +00:00
/// You must call one of these methods when create a child thread:
2018-05-29 18:14:31 +00:00
/// Bundles the current thread with a query
static void attachQuery(QueryStatus * parent_process);
/// Bundles the current thread with a query bundled to the sibling thread
static void attachQueryFromSiblingThread(const ThreadStatusPtr & sibling_thread);
/// Is useful for a ThreadPool tasks
static void attachQueryFromSiblingThreadIfDetached(const ThreadStatusPtr & sibling_thread);
/// Makes system calls to update ProfileEvents derived from rusage and taskstats
2018-05-29 18:14:31 +00:00
static void updatePerformanceCounters();
2018-05-29 18:14:31 +00:00
static ProfileEvents::Counters & getProfileEvents();
static MemoryTracker & getMemoryTracker();
static void updateProgressIn(const Progress & value);
static void updateProgressOut(const Progress & value);
2018-05-29 18:14:31 +00:00
/// Non-master threads call this method in destructor automatically
2018-05-29 18:14:31 +00:00
static void detachQuery();
private:
static void attachQueryFromSiblingThreadImpl(ThreadStatusPtr sibling_thread, bool check_detached = true);
2018-05-29 18:14:31 +00:00
};
}