diff --git a/fe/fe-core/src/main/java/com/starrocks/common/Config.java b/fe/fe-core/src/main/java/com/starrocks/common/Config.java index 374fd9f0a4c13d..df8a2ba08dd08e 100644 --- a/fe/fe-core/src/main/java/com/starrocks/common/Config.java +++ b/fe/fe-core/src/main/java/com/starrocks/common/Config.java @@ -1868,6 +1868,9 @@ public class Config extends ConfigBase { @ConfField public static long statistic_dict_columns = 100000; + @ConfField + public static int dict_collect_thread_pool_size = 16; + /** * The column statistic cache update interval */ diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/CacheDictManager.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/CacheDictManager.java index e1b4c02ae9a163..c67aa0fd515b30 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/CacheDictManager.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/CacheDictManager.java @@ -24,6 +24,7 @@ import com.starrocks.common.Config; import com.starrocks.common.Pair; import com.starrocks.common.Status; +import com.starrocks.common.ThreadPoolManager; import com.starrocks.memory.MemoryTrackable; import com.starrocks.qe.ConnectContext; import com.starrocks.server.GlobalStateMgr; @@ -53,7 +54,7 @@ public class CacheDictManager implements IDictManager, MemoryTrackable { public static final Integer LOW_CARDINALITY_THRESHOLD = 255; - private CacheDictManager() { + public CacheDictManager() { } private static final CacheDictManager INSTANCE = new CacheDictManager(); @@ -106,6 +107,8 @@ public CompletableFuture> asyncReload( private final AsyncLoadingCache> dictStatistics = Caffeine.newBuilder() .maximumSize(Config.statistic_dict_columns) + .executor(ThreadPoolManager.newDaemonCacheThreadPool(Config.dict_collect_thread_pool_size, "cache-dict", + false)) .buildAsync(dictLoader); private Optional deserializeColumnDict(long tableId, String columnName, TStatisticData statisticData) { diff --git a/fe/fe-core/src/test/java/com/starrocks/catalog/CacheDictManagerTest.java b/fe/fe-core/src/test/java/com/starrocks/catalog/CacheDictManagerTest.java new file mode 100644 index 00000000000000..51fa0d051f7f1c --- /dev/null +++ b/fe/fe-core/src/test/java/com/starrocks/catalog/CacheDictManagerTest.java @@ -0,0 +1,35 @@ +// Copyright 2021-present StarRocks, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.starrocks.catalog; + +import com.starrocks.sql.optimizer.statistics.CacheDictManager; +import mockit.Expectations; +import org.junit.Test; + +import java.util.Optional; + +public class CacheDictManagerTest { + @Test + public void test() { + CacheDictManager manager = new CacheDictManager(); + new Expectations(manager) { + { + manager.getGlobalDict(anyLong, ColumnId.create("val")); + result = Optional.empty(); + } + }; + manager.getGlobalDict(1, ColumnId.create("val")); + } +}