Fix thread accounting for max_part_removal_threads

This commit is contained in:
Azat Khuzhin 2021-04-11 11:42:44 +03:00
parent dfe3699e77
commit 6e71757814
2 changed files with 18 additions and 2 deletions

View File

@ -56,6 +56,8 @@
#include <boost/range/adaptor/filtered.hpp>
#include <boost/algorithm/string/join.hpp>
#include <ext/scope_guard_safe.h>
#include <algorithm>
#include <iomanip>
#include <optional>
@ -1217,8 +1219,15 @@ void MergeTreeData::clearPartsFromFilesystem(const DataPartsVector & parts_to_re
/// NOTE: Under heavy system load you may get "Cannot schedule a task" from ThreadPool.
for (const DataPartPtr & part : parts_to_remove)
{
pool.scheduleOrThrowOnError([&]
pool.scheduleOrThrowOnError([&, thread_group = CurrentThread::getGroup()]
{
SCOPE_EXIT_SAFE(
if (thread_group)
CurrentThread::detachQueryIfNotDetached();
);
if (thread_group)
CurrentThread::attachTo(thread_group);
LOG_DEBUG(log, "Removing part from filesystem {}", part->name);
part->remove();
});

View File

@ -5714,8 +5714,15 @@ void StorageReplicatedMergeTree::removePartsFromFilesystem(const DataPartsVector
/// NOTE: Under heavy system load you may get "Cannot schedule a task" from ThreadPool.
for (const DataPartPtr & part : parts)
{
pool.scheduleOrThrowOnError([&]
pool.scheduleOrThrowOnError([&, thread_group = CurrentThread::getGroup()]
{
SCOPE_EXIT_SAFE(
if (thread_group)
CurrentThread::detachQueryIfNotDetached();
);
if (thread_group)
CurrentThread::attachTo(thread_group);
LOG_DEBUG(log, "Removing part from filesystem {}", part->name);
try
{