提交 f6f92cb7 编写于 作者: A Alexey Milovidov

Fixed error with falsely reported large memory consumption of long running...

Fixed error with falsely reported large memory consumption of long running INSERT queries [#METR-23288].
上级 eec90875
......@@ -86,3 +86,22 @@ public:
* Таким образом, его нужно всего-лишь протащить во все потоки, в которых обрабатывается один запрос.
*/
extern __thread MemoryTracker * current_memory_tracker;
#include <boost/noncopyable.hpp>
struct TemporarilyDisableMemoryTracker : private boost::noncopyable
{
MemoryTracker * memory_tracker;
TemporarilyDisableMemoryTracker()
{
memory_tracker = current_memory_tracker;
current_memory_tracker = nullptr;
}
~TemporarilyDisableMemoryTracker()
{
current_memory_tracker = memory_tracker;
}
};
......@@ -107,21 +107,7 @@ public:
/** During synchronous loading of external dictionaries at moment of query execution,
* we should not use per query memory limit.
*/
struct TemporarilyDisableMemoryTracker
{
MemoryTracker * memory_tracker;
TemporarilyDisableMemoryTracker()
{
memory_tracker = current_memory_tracker;
current_memory_tracker = nullptr;
}
~TemporarilyDisableMemoryTracker()
{
current_memory_tracker = memory_tracker;
}
} temporarily_disable_memory_tracker;
TemporarilyDisableMemoryTracker temporarily_disable_memory_tracker;
reloadImpl(throw_on_error);
}
......
......@@ -442,6 +442,15 @@ private:
}
}
{
/** While filling index (index_columns), disable memory tracker.
* Because memory is allocated here (maybe in context of INSERT query),
* but then freed in completely different place (while merging parts), where query memory_tracker is not available.
* And otherwise it will look like excessively growing memory consumption in context of query.
* (observed in long INSERT SELECTs)
*/
TemporarilyDisableMemoryTracker temporarily_disable_memory_tracker;
/// Пишем индекс. Индекс содержит значение Primary Key для каждой index_granularity строки.
for (size_t i = index_offset; i < rows; i += storage.index_granularity)
{
......@@ -457,6 +466,7 @@ private:
++marks_count;
}
}
size_t written_for_last_mark = (storage.index_granularity - index_offset + rows) % storage.index_granularity;
index_offset = (storage.index_granularity - written_for_last_mark) % storage.index_granularity;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册