Merge pull request #5892 from yandex/thread-status-remove-bad-code

ThreadStatus: removed bad and questionable code
This commit is contained in:
alexey-milovidov 2019-07-05 21:27:08 +03:00 committed by GitHub
commit 6dea389f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 31 deletions

View File

@ -23,7 +23,7 @@ void CurrentThread::updatePerformanceCounters()
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().updatePerformanceCounters(); current_thread->updatePerformanceCounters();
} }
ThreadStatus & CurrentThread::get() ThreadStatus & CurrentThread::get()
@ -36,35 +36,35 @@ ThreadStatus & CurrentThread::get()
ProfileEvents::Counters & CurrentThread::getProfileEvents() 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() MemoryTracker * CurrentThread::getMemoryTracker()
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return nullptr; return nullptr;
return &get().memory_tracker; return &current_thread->memory_tracker;
} }
void CurrentThread::updateProgressIn(const Progress & value) void CurrentThread::updateProgressIn(const Progress & value)
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().progress_in.incrementPiecewiseAtomically(value); current_thread->progress_in.incrementPiecewiseAtomically(value);
} }
void CurrentThread::updateProgressOut(const Progress & value) void CurrentThread::updateProgressOut(const Progress & value)
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().progress_out.incrementPiecewiseAtomically(value); current_thread->progress_out.incrementPiecewiseAtomically(value);
} }
void CurrentThread::attachInternalTextLogsQueue(const std::shared_ptr<InternalTextLogsQueue> & logs_queue) void CurrentThread::attachInternalTextLogsQueue(const std::shared_ptr<InternalTextLogsQueue> & logs_queue)
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().attachInternalTextLogsQueue(logs_queue); current_thread->attachInternalTextLogsQueue(logs_queue);
} }
std::shared_ptr<InternalTextLogsQueue> CurrentThread::getInternalTextLogsQueue() std::shared_ptr<InternalTextLogsQueue> CurrentThread::getInternalTextLogsQueue()
@ -73,10 +73,10 @@ std::shared_ptr<InternalTextLogsQueue> CurrentThread::getInternalTextLogsQueue()
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return nullptr; return nullptr;
if (get().getCurrentState() == ThreadStatus::ThreadState::Died) if (current_thread->getCurrentState() == ThreadStatus::ThreadState::Died)
return nullptr; return nullptr;
return get().getInternalTextLogsQueue(); return current_thread->getInternalTextLogsQueue();
} }
ThreadGroupStatusPtr CurrentThread::getGroup() ThreadGroupStatusPtr CurrentThread::getGroup()
@ -84,7 +84,7 @@ ThreadGroupStatusPtr CurrentThread::getGroup()
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return nullptr; return nullptr;
return get().getThreadGroup(); return current_thread->getThreadGroup();
} }
} }

View File

@ -3,6 +3,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <common/StringRef.h>
#include <Common/ThreadStatus.h> #include <Common/ThreadStatus.h>
@ -69,7 +70,7 @@ public:
static void finalizePerformanceCounters(); static void finalizePerformanceCounters();
/// Returns a non-empty string if the thread is attached to a query /// 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 /// Non-master threads call this method in destructor automatically
static void detachQuery(); static void detachQuery();

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <common/StringRef.h>
#include <Common/ProfileEvents.h> #include <Common/ProfileEvents.h>
#include <Common/MemoryTracker.h> #include <Common/MemoryTracker.h>
@ -114,7 +115,7 @@ public:
return thread_state.load(std::memory_order_relaxed); 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 /// Starts new query and create new thread group for it, current thread becomes master thread of the query
void initializeQuery(); void initializeQuery();

View File

@ -30,7 +30,7 @@ void ThreadStatus::attachQueryContext(Context & query_context_)
} }
} }
const std::string & ThreadStatus::getQueryId() const StringRef ThreadStatus::getQueryId() const
{ {
return query_id; return query_id;
} }
@ -39,8 +39,7 @@ void CurrentThread::defaultThreadDeleter()
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
ThreadStatus & thread = CurrentThread::get(); current_thread->detachQuery(true, true);
thread.detachQuery(true, true);
} }
void ThreadStatus::initializeQuery() void ThreadStatus::initializeQuery()
@ -197,62 +196,59 @@ void CurrentThread::initializeQuery()
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().initializeQuery(); current_thread->initializeQuery();
get().deleter = CurrentThread::defaultThreadDeleter; current_thread->deleter = CurrentThread::defaultThreadDeleter;
} }
void CurrentThread::attachTo(const ThreadGroupStatusPtr & thread_group) void CurrentThread::attachTo(const ThreadGroupStatusPtr & thread_group)
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().attachQuery(thread_group, true); current_thread->attachQuery(thread_group, true);
get().deleter = CurrentThread::defaultThreadDeleter; current_thread->deleter = CurrentThread::defaultThreadDeleter;
} }
void CurrentThread::attachToIfDetached(const ThreadGroupStatusPtr & thread_group) void CurrentThread::attachToIfDetached(const ThreadGroupStatusPtr & thread_group)
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().attachQuery(thread_group, false); current_thread->attachQuery(thread_group, false);
get().deleter = CurrentThread::defaultThreadDeleter; current_thread->deleter = CurrentThread::defaultThreadDeleter;
} }
const std::string & CurrentThread::getQueryId() StringRef CurrentThread::getQueryId()
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
{ return {};
const static std::string empty; return current_thread->getQueryId();
return empty;
}
return get().getQueryId();
} }
void CurrentThread::attachQueryContext(Context & query_context) void CurrentThread::attachQueryContext(Context & query_context)
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
return get().attachQueryContext(query_context); return current_thread->attachQueryContext(query_context);
} }
void CurrentThread::finalizePerformanceCounters() void CurrentThread::finalizePerformanceCounters()
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().finalizePerformanceCounters(); current_thread->finalizePerformanceCounters();
} }
void CurrentThread::detachQuery() void CurrentThread::detachQuery()
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().detachQuery(false); current_thread->detachQuery(false);
} }
void CurrentThread::detachQueryIfNotDetached() void CurrentThread::detachQueryIfNotDetached()
{ {
if (unlikely(!current_thread)) if (unlikely(!current_thread))
return; return;
get().detachQuery(true); current_thread->detachQuery(true);
} }

View File

@ -25,7 +25,11 @@ ExtendedLogMessage ExtendedLogMessage::getFrom(const Poco::Message & base)
msg_ext.time_microseconds = static_cast<UInt32>(tv.tv_usec); msg_ext.time_microseconds = static_cast<UInt32>(tv.tv_usec);
if (current_thread) 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(); msg_ext.thread_number = getThreadNumber();