Skip to content

Commit

Permalink
[improvement](statistics)Remove retry load when load stats cache fail (
Browse files Browse the repository at this point in the history
…#28904)

Remove retry load when load stats cache fail. This case usually happens when BE is down or BE OOM, retry doesn't work in these cases and may increase BE work load.
  • Loading branch information
Jibing-Li authored Dec 27, 2023
1 parent f6850f8 commit a4e69f7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.doris.statistics;

import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.ThreadPoolManager;
import org.apache.doris.qe.InternalQueryExecutionException;
Expand Down Expand Up @@ -64,7 +63,8 @@ private Optional<ColumnStatistic> loadFromStatsTable(StatisticsCacheKey key) {
try {
columnResults = StatisticsRepository.loadColStats(key.tableId, key.idxId, key.colName);
} catch (InternalQueryExecutionException e) {
retryLoad(key);
LOG.info("Failed to load stats for table {} column {}. Reason:{}",
key.tableId, key.colName, e.getMessage());
return Optional.empty();
}
ColumnStatistic columnStatistics;
Expand All @@ -80,42 +80,4 @@ private Optional<ColumnStatistic> loadFromStatsTable(StatisticsCacheKey key) {
return Optional.of(columnStatistics);
}
}

private void retryLoad(StatisticsCacheKey key) {
singleThreadPool.submit(new RetryTask(key, 1));
}

private static class RetryTask implements Runnable {
StatisticsCacheKey key;
int retryTimes;

public RetryTask(StatisticsCacheKey key, int retryTimes) {
this.key = key;
this.retryTimes = retryTimes;
}

@Override
public void run() {
List<ResultRow> columnResults = null;
try {
columnResults = StatisticsRepository.loadColStats(key.tableId, key.idxId, key.colName);
} catch (InternalQueryExecutionException e) {
if (this.retryTimes < StatisticConstants.LOAD_RETRY_TIMES) {
retryTimes++;
singleThreadPool.submit(this);
}
return;
}
ColumnStatistic columnStatistics;
try {
columnStatistics = StatisticsUtil.deserializeToColumnStatistics(columnResults);
} catch (Exception e) {
LOG.warn("Exception to deserialize column statistics", e);
return;
}
if (columnStatistics != null) {
Env.getCurrentEnv().getStatisticsCache().putCache(key, columnStatistics);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
import org.apache.logging.log4j.Logger;

import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
Expand Down Expand Up @@ -201,7 +199,6 @@ private void doPreHeat() {
if (CollectionUtils.isEmpty(recentStatsUpdatedCols)) {
return;
}
Map<StatisticsCacheKey, ColumnStatistic> keyToColStats = new HashMap<>();
for (ResultRow r : recentStatsUpdatedCols) {
try {
StatsId statsId = new StatsId(r);
Expand All @@ -211,7 +208,6 @@ private void doPreHeat() {
final StatisticsCacheKey k =
new StatisticsCacheKey(tblId, idxId, colId);
final ColumnStatistic c = ColumnStatistic.fromResultRow(r);
keyToColStats.put(k, c);
putCache(k, c);
} catch (Throwable t) {
LOG.warn("Error when preheating stats cache", t);
Expand Down

0 comments on commit a4e69f7

Please sign in to comment.