From e4b65da6e48c8fae6992d1e5afd40dd38fea2af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Tue, 29 Jun 2021 12:11:59 +0200 Subject: [PATCH] PushingToViewsBlockOutputStream: Detatch ThreadStatus' --- .../PushingToViewsBlockOutputStream.cpp | 21 +++++++++++++++++-- .../PushingToViewsBlockOutputStream.h | 2 ++ src/Interpreters/QueryViewsLog.h | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/DataStreams/PushingToViewsBlockOutputStream.cpp b/src/DataStreams/PushingToViewsBlockOutputStream.cpp index 26bf8213350..d6a332a12e3 100644 --- a/src/DataStreams/PushingToViewsBlockOutputStream.cpp +++ b/src/DataStreams/PushingToViewsBlockOutputStream.cpp @@ -144,14 +144,14 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream( if (!running_memory_tracker) running_memory_tracker = &total_memory_tracker; - auto thread_status = std::make_shared(); + auto thread_status = std::make_unique(); 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 { diff --git a/src/DataStreams/PushingToViewsBlockOutputStream.h b/src/DataStreams/PushingToViewsBlockOutputStream.h index 0ce74979e40..717474d4e69 100644 --- a/src/DataStreams/PushingToViewsBlockOutputStream.h +++ b/src/DataStreams/PushingToViewsBlockOutputStream.h @@ -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; diff --git a/src/Interpreters/QueryViewsLog.h b/src/Interpreters/QueryViewsLog.h index 9139da1b0fb..24a4e0fdb20 100644 --- a/src/Interpreters/QueryViewsLog.h +++ b/src/Interpreters/QueryViewsLog.h @@ -36,7 +36,7 @@ struct QueryViewsLogElement { String target_name; ViewType type = ViewType::DEFAULT; - std::shared_ptr thread_status = nullptr; + std::unique_ptr thread_status = nullptr; UInt64 elapsed_ms = 0; std::chrono::time_point event_time; ViewStatus event_status = ViewStatus::QUERY_START;