Attempt to fix inconsistent values in total memory tracker #3143

This commit is contained in:
Alexey Milovidov 2018-09-26 23:45:40 +03:00
parent 836c20b2d3
commit dd88c092b7
2 changed files with 4 additions and 4 deletions

View File

@ -43,8 +43,7 @@ MemoryTracker::~MemoryTracker()
* then memory usage of 'next' memory trackers will be underestimated,
* because amount will be decreased twice (first - here, second - when real 'free' happens).
*/
if (auto value = amount.load(std::memory_order_relaxed))
free(value);
reset();
}
@ -170,7 +169,8 @@ void MemoryTracker::resetCounters()
void MemoryTracker::reset()
{
if (!parent.load(std::memory_order_relaxed))
CurrentMetrics::sub(metric, amount.load(std::memory_order_relaxed));
if (auto value = amount.load(std::memory_order_relaxed))
free(value);
resetCounters();
}

View File

@ -133,7 +133,7 @@ void ThreadStatus::detachQuery(bool exit_if_already_detached, bool thread_exits)
/// Detach from thread group
performance_counters.setParent(&ProfileEvents::global_counters);
memory_tracker.setParent(nullptr);
memory_tracker.reset();
query_context = nullptr;
thread_group.reset();