PushingToViewsBlockOutputStream: Detatch ThreadStatus'

This commit is contained in:
Raúl Marín 2021-06-29 12:11:59 +02:00
parent 75d18bc79b
commit e4b65da6e4
3 changed files with 22 additions and 3 deletions

View File

@ -144,14 +144,14 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
if (!running_memory_tracker)
running_memory_tracker = &total_memory_tracker;
auto thread_status = std::make_shared<ThreadStatus>();
auto thread_status = std::make_unique<ThreadStatus>();
thread_status->attachQueryContext(getContext());
thread_status->memory_tracker.setParent(running_memory_tracker);
QueryViewsLogElement::ViewRuntimeStats runtime_stats{
target_name,
type,
thread_status,
std::move(thread_status),
0,
std::chrono::system_clock::now(),
QueryViewsLogElement::ViewStatus::EXCEPTION_BEFORE_START};
@ -178,6 +178,23 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream(
}
}
PushingToViewsBlockOutputStream::~PushingToViewsBlockOutputStream()
{
for (auto & view : views)
{
if (view.runtime_stats.thread_status)
{
try
{
view.runtime_stats.thread_status->detachQuery(true, true);
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
}
}
Block PushingToViewsBlockOutputStream::getHeader() const
{

View File

@ -43,6 +43,8 @@ public:
const ASTPtr & query_ptr_,
bool no_destination = false);
~PushingToViewsBlockOutputStream() override;
Block getHeader() const override;
void write(const Block & block) override;

View File

@ -36,7 +36,7 @@ struct QueryViewsLogElement
{
String target_name;
ViewType type = ViewType::DEFAULT;
std::shared_ptr<ThreadStatus> thread_status = nullptr;
std::unique_ptr<ThreadStatus> thread_status = nullptr;
UInt64 elapsed_ms = 0;
std::chrono::time_point<std::chrono::system_clock> event_time;
ViewStatus event_status = ViewStatus::QUERY_START;