Avoid accounting memory from another mutation/merge

Before this path it was possible that one merge/mutation may account
memory from another, due to ThreadStatus::untracked_memory.

And this cause flakiness of 01200_mutations_memory_consumption.
This commit is contained in:
Azat Khuzhin 2021-10-13 23:47:28 +03:00
parent fd38cbb0df
commit 8cc45bea7b
2 changed files with 7 additions and 0 deletions

View File

@ -34,6 +34,11 @@ MemoryTrackerThreadSwitcher::MemoryTrackerThreadSwitcher(MemoryTracker * memory_
prev_untracked_memory_limit = current_thread->untracked_memory_limit;
current_thread->untracked_memory_limit = untracked_memory_limit;
/// Avoid accounting memory from another mutation/merge
/// (NOTE: consider moving such code to ThreadFromGlobalPool and related places)
prev_untracked_memory = current_thread->untracked_memory;
current_thread->untracked_memory = 0;
}
@ -45,6 +50,7 @@ MemoryTrackerThreadSwitcher::~MemoryTrackerThreadSwitcher()
background_thread_memory_tracker->setParent(background_thread_memory_tracker_prev_parent);
current_thread->untracked_memory_limit = prev_untracked_memory_limit;
current_thread->untracked_memory = prev_untracked_memory;
}
MergeListElement::MergeListElement(

View File

@ -68,6 +68,7 @@ private:
MemoryTracker * background_thread_memory_tracker;
MemoryTracker * background_thread_memory_tracker_prev_parent = nullptr;
UInt64 prev_untracked_memory_limit;
UInt64 prev_untracked_memory;
};
using MemoryTrackerThreadSwitcherPtr = std::unique_ptr<MemoryTrackerThreadSwitcher>;