Merge pull request #72611 from CurtizJ/fix-prewarm-caches-race

Fix data race in prewarm of mark cache
This commit is contained in:
Anton Popov 2024-11-29 22:14:24 +00:00 committed by GitHub
commit 6e760f4e45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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;