From 64c7e357e8cfb56428aeddcc97cf22559bb33c1b Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 8 Oct 2018 08:30:03 +0300 Subject: [PATCH] Fixed error #3230 --- dbms/src/Common/MemoryTracker.cpp | 5 +++-- dbms/src/Common/MemoryTracker.h | 8 +------- dbms/src/Interpreters/ProcessList.cpp | 14 +++++++++++++- dbms/src/Interpreters/ProcessList.h | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dbms/src/Common/MemoryTracker.cpp b/dbms/src/Common/MemoryTracker.cpp index 95344522b15..326f93c754d 100644 --- a/dbms/src/Common/MemoryTracker.cpp +++ b/dbms/src/Common/MemoryTracker.cpp @@ -73,7 +73,7 @@ void MemoryTracker::alloc(Int64 size) */ Int64 will_be = size + amount.fetch_add(size, std::memory_order_relaxed); - if (!parent.load(std::memory_order_relaxed)) + if (metric != CurrentMetrics::end()) CurrentMetrics::add(metric, size); Int64 current_limit = limit.load(std::memory_order_relaxed); @@ -153,7 +153,8 @@ void MemoryTracker::free(Int64 size) if (auto loaded_next = parent.load(std::memory_order_relaxed)) loaded_next->free(size); - else + + if (metric != CurrentMetrics::end()) CurrentMetrics::sub(metric, size); } diff --git a/dbms/src/Common/MemoryTracker.h b/dbms/src/Common/MemoryTracker.h index 68c145393fe..9f439c7550c 100644 --- a/dbms/src/Common/MemoryTracker.h +++ b/dbms/src/Common/MemoryTracker.h @@ -7,12 +7,6 @@ #include -namespace CurrentMetrics -{ - extern const Metric MemoryTracking; -} - - /** Tracks memory consumption. * It throws an exception if amount of consumed memory become greater than certain limit. * The same memory tracker could be simultaneously used in different threads. @@ -31,7 +25,7 @@ class MemoryTracker std::atomic parent {}; /// You could specify custom metric to track memory usage. - CurrentMetrics::Metric metric = CurrentMetrics::MemoryTracking; + CurrentMetrics::Metric metric = CurrentMetrics::end(); /// This description will be used as prefix into log messages (if isn't nullptr) const char * description = nullptr; diff --git a/dbms/src/Interpreters/ProcessList.cpp b/dbms/src/Interpreters/ProcessList.cpp index 07dca964c4f..557a006663d 100644 --- a/dbms/src/Interpreters/ProcessList.cpp +++ b/dbms/src/Interpreters/ProcessList.cpp @@ -14,6 +14,11 @@ #include +namespace CurrentMetrics +{ + extern const Metric MemoryTracking; +} + namespace DB { @@ -74,6 +79,13 @@ static bool isUnlimitedQuery(const IAST * ast) } +ProcessList::ProcessList(size_t max_size_) + : max_size(max_size_) +{ + total_memory_tracker.setMetric(CurrentMetrics::MemoryTracking); +} + + ProcessList::EntryPtr ProcessList::insert(const String & query_, const IAST * ast, Context & query_context) { EntryPtr res; @@ -207,7 +219,7 @@ ProcessListEntry::~ProcessListEntry() /// Destroy all streams to avoid long lock of ProcessList it->releaseQueryStreams(); - std::lock_guard lock(parent.mutex); + std::lock_guard lock(parent.mutex); String user = it->getClientInfo().current_user; String query_id = it->getClientInfo().current_query_id; diff --git a/dbms/src/Interpreters/ProcessList.h b/dbms/src/Interpreters/ProcessList.h index 56d46f2aaa3..87e43162202 100644 --- a/dbms/src/Interpreters/ProcessList.h +++ b/dbms/src/Interpreters/ProcessList.h @@ -287,7 +287,7 @@ protected: QueryStatus * tryGetProcessListElement(const String & current_query_id, const String & current_user); public: - ProcessList(size_t max_size_ = 0) : max_size(max_size_) {} + ProcessList(size_t max_size_ = 0); using EntryPtr = std::shared_ptr;