fix data race in prewarmCaches when thread is failed to allocate

This commit is contained in:
Anton Popov 2024-11-28 19:05:21 +00:00
parent bc79653eed
commit c512c23c26

View File

@ -2405,8 +2405,6 @@ void MergeTreeData::prewarmCaches(ThreadPool & pool, MarkCachePtr mark_cache, Pr
return to_tuple(lhs) > to_tuple(rhs);
});
ThreadPoolCallbackRunnerLocal<void> runner(pool, "PrewarmCaches");
double marks_ratio_to_prewarm = getContext()->getServerSettings()[ServerSetting::mark_cache_prewarm_ratio];
double index_ratio_to_prewarm = getContext()->getServerSettings()[ServerSetting::primary_index_cache_prewarm_ratio];
@ -2418,6 +2416,10 @@ void MergeTreeData::prewarmCaches(ThreadPool & pool, MarkCachePtr mark_cache, Pr
columns_to_prewarm_marks = getColumnsToPrewarmMarks(*getSettings(), metadata_snaphost->getColumns().getAllPhysical());
}
/// Allocate runner on stack after all used local variables to make its destructor
/// is called first and all tasks stopped before local variables are being destroyed.
ThreadPoolCallbackRunnerLocal<void> runner(pool, "PrewarmCaches");
for (const auto & part : data_parts)
{
bool added_task = false;