[enhancement](stats) Optimize stats pre-load logic #19138

1. Don't do pre-load until stats table gets ready
2. Don't put pre-loaded unknown stats to cache
This commit is contained in:
AKIRA
2023-04-27 17:01:31 +09:00
committed by GitHub
parent a9480bdcf3
commit 7d89b57706

View File

@ -20,6 +20,7 @@ package org.apache.doris.statistics;
import org.apache.doris.common.ThreadPoolManager;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.statistics.util.InternalQueryResult.ResultRow;
import org.apache.doris.statistics.util.StatisticsUtil;
import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
import com.github.benmanes.caffeine.cache.Caffeine;
@ -146,6 +147,14 @@ public class StatisticsCache {
private void doPreHeat() {
List<ResultRow> recentStatsUpdatedCols = null;
long retryTimes = 0;
while (!StatisticsUtil.statsTblAvailable()) {
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
// IGNORE
}
}
while (retryTimes < StatisticConstants.PRELOAD_RETRY_TIMES) {
try {
recentStatsUpdatedCols = StatisticsRepository.fetchRecentStatsUpdatedCol();
@ -194,6 +203,9 @@ public class StatisticsCache {
return Optional.of(c);
}
};
if (c == ColumnStatistic.UNKNOWN) {
continue;
}
columnStatisticsCache.put(k, f);
} catch (Throwable t) {
LOG.warn("Error when preheating stats cache", t);