Skip to content

Commit

Permalink
[BugFix] Use a separate thread pool for dictionary collection (backport
Browse files Browse the repository at this point in the history
  • Loading branch information
2 people authored and lijinbin committed Jan 6, 2025
1 parent 4148d94 commit 6e555f7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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;
Expand Down Expand Up @@ -54,7 +55,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();
Expand Down Expand Up @@ -107,6 +108,8 @@ public CompletableFuture<Optional<ColumnDict>> asyncReload(

private final AsyncLoadingCache<ColumnIdentifier, Optional<ColumnDict>> dictStatistics = Caffeine.newBuilder()
.maximumSize(Config.statistic_dict_columns)
.executor(ThreadPoolManager.newDaemonCacheThreadPool(Config.dict_collect_thread_pool_size, "cache-dict",
false))
.buildAsync(dictLoader);

private Optional<ColumnDict> deserializeColumnDict(long tableId, ColumnId columnName, TStatisticData statisticData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit 6e555f7

Please sign in to comment.