Fix possible NPE when thread_group is not set

This commit is contained in:
Dmitry Novik 2021-12-14 16:39:53 +03:00
parent b81d600c1e
commit de432f9270
3 changed files with 15 additions and 5 deletions

View File

@ -66,7 +66,11 @@ void UserOvercommitTracker::pickQueryToExcludeImpl()
{
if (query.second->isKilled())
continue;
auto * memory_tracker = query.second->getMemoryTracker();
if (!memory_tracker)
continue;
auto ratio = memory_tracker->getOvercommitRatio();
LOG_DEBUG(logger, "Query has ratio {}/{}", ratio.committed, ratio.soft_limit);
if (ratio.soft_limit != 0 && current_ratio < ratio)
@ -96,6 +100,8 @@ void GlobalOvercommitTracker::pickQueryToExcludeImpl()
return;
auto * memory_tracker = query.getMemoryTracker();
if (!memory_tracker)
return;
auto ratio = memory_tracker->getOvercommitRatio(user_soft_limit);
LOG_DEBUG(logger, "Query has ratio {}/{}", ratio.committed, ratio.soft_limit);
if (current_ratio < ratio)

View File

@ -309,12 +309,14 @@ QueryStatus::~QueryStatus()
{
assert(executors.empty());
auto * memory_tracker = getMemoryTracker();
if (auto * memory_tracker = getMemoryTracker())
{
if (user_process_list)
user_process_list->user_overcommit_tracker.unsubscribe(memory_tracker);
if (auto shared_context = getContext())
shared_context->getGlobalOvercommitTracker()->unsubscribe(memory_tracker);
}
}
CancellationCode QueryStatus::cancelQuery(bool)
{

View File

@ -149,6 +149,8 @@ public:
MemoryTracker * getMemoryTracker() const
{
if (!thread_group)
return nullptr;
return &thread_group->memory_tracker;
}