Merge pull request #71368 from CurtizJ/better-prewarm-mark-cache

Allow to prewarm mark cache by system command without enabled setting
This commit is contained in:
Anton Popov 2024-11-04 18:10:28 +00:00 committed by GitHub
commit 2b417d3f85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 41 additions and 4 deletions

View File

@ -1310,7 +1310,7 @@ RefreshTaskList InterpreterSystemQuery::getRefreshTasks()
void InterpreterSystemQuery::prewarmMarkCache()
{
if (table_id.empty())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table is not specified for prewarming marks cache");
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table is not specified for PREWARM MARK CACHE command");
getContext()->checkAccess(AccessType::SYSTEM_PREWARM_MARK_CACHE, table_id);

View File

@ -2343,11 +2343,16 @@ void MergeTreeData::stopOutdatedAndUnexpectedDataPartsLoadingTask()
}
}
void MergeTreeData::prewarmMarkCache(ThreadPool & pool)
void MergeTreeData::prewarmMarkCacheIfNeeded(ThreadPool & pool)
{
if (!(*getSettings())[MergeTreeSetting::prewarm_mark_cache])
return;
prewarmMarkCache(pool);
}
void MergeTreeData::prewarmMarkCache(ThreadPool & pool)
{
auto * mark_cache = getContext()->getMarkCache().get();
if (!mark_cache)
return;

View File

@ -508,6 +508,7 @@ public:
/// Prewarm mark cache for the most recent data parts.
void prewarmMarkCache(ThreadPool & pool);
void prewarmMarkCacheIfNeeded(ThreadPool & pool);
String getLogName() const { return log.loadName(); }

View File

@ -155,7 +155,7 @@ StorageMergeTree::StorageMergeTree(
loadMutations();
loadDeduplicationLog();
prewarmMarkCache(getActivePartsLoadingThreadPool().get());
prewarmMarkCacheIfNeeded(getActivePartsLoadingThreadPool().get());
}

View File

@ -509,7 +509,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
}
loadDataParts(skip_sanity_checks, expected_parts_on_this_replica);
prewarmMarkCache(getActivePartsLoadingThreadPool().get());
prewarmMarkCacheIfNeeded(getActivePartsLoadingThreadPool().get());
if (LoadingStrictnessLevel::ATTACH <= mode)
{

View File

@ -0,0 +1,4 @@
20000
20000
1
0

View File

@ -0,0 +1,27 @@
-- Tags: no-parallel, no-shared-merge-tree
DROP TABLE IF EXISTS t_prewarm_cache;
CREATE TABLE t_prewarm_cache (a UInt64, b UInt64, c UInt64)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/03254_prewarm_mark_cache_smt/t_prewarm_cache', '1')
ORDER BY a SETTINGS prewarm_mark_cache = 0;
SYSTEM DROP MARK CACHE;
INSERT INTO t_prewarm_cache SELECT number, rand(), rand() FROM numbers(20000);
SELECT count() FROM t_prewarm_cache WHERE NOT ignore(*);
SYSTEM DROP MARK CACHE;
SYSTEM PREWARM MARK CACHE t_prewarm_cache;
SELECT count() FROM t_prewarm_cache WHERE NOT ignore(*);
SYSTEM FLUSH LOGS;
SELECT ProfileEvents['LoadedMarksCount'] > 0 FROM system.query_log
WHERE current_database = currentDatabase() AND type = 'QueryFinish' AND query LIKE 'SELECT count() FROM t_prewarm_cache%'
ORDER BY event_time_microseconds;
DROP TABLE IF EXISTS t_prewarm_cache;