Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Seaven <[email protected]>
  • Loading branch information
Seaven committed Nov 29, 2024
1 parent 6396655 commit 538caef
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,33 @@ public void expireConnectorTableColumnStatistics(Table table, List<String> colum
connectorTableCachedStatistics.synchronous().invalidateAll(allKeys);
}

@Override
public void refreshConnectorTableColumnStatistics(Table table, List<String> columns, boolean isSync) {
Preconditions.checkState(table != null);
if (!StatisticUtils.checkStatisticTableStateNormal()) {
return;
}

List<ConnectorTableColumnKey> cacheKeys = new ArrayList<>();
for (String column : columns) {
cacheKeys.add(new ConnectorTableColumnKey(table.getUUID(), column));
}

try {
ConnectorColumnStatsCacheLoader loader = new ConnectorColumnStatsCacheLoader();
CompletableFuture<Map<ConnectorTableColumnKey, Optional<ConnectorTableColumnStats>>> future =
loader.asyncLoadAll(cacheKeys, statsCacheRefresherExecutor);
if (isSync) {
Map<ConnectorTableColumnKey, Optional<ConnectorTableColumnStats>> result = future.get();
connectorTableCachedStatistics.synchronous().putAll(result);
} else {
future.whenComplete((res, e) -> connectorTableCachedStatistics.synchronous().putAll(res));
}
} catch (Exception e) {
LOG.warn("Failed to refresh getConnectorTableStatistics", e);
}
}

@Override
public ColumnStatistic getColumnStatistic(Table table, String column) {
Preconditions.checkState(table != null);
Expand Down Expand Up @@ -362,46 +389,6 @@ public List<ColumnStatistic> getColumnStatistics(Table table, List<String> colum
}
}

@Override
public List<ColumnStatistic> getColumnStatisticsSync(Table table, List<String> columns) {
Preconditions.checkState(table != null);

// get Statistics Table column info, just return default column statistics
if (StatisticUtils.statisticTableBlackListCheck(table.getId())) {
return getDefaultColumnStatisticList(columns);
}

if (!StatisticUtils.checkStatisticTableStateNormal()) {
return getDefaultColumnStatisticList(columns);
}

List<ColumnStatsCacheKey> cacheKeys = new ArrayList<>();
long tableId = table.getId();
for (String column : columns) {
cacheKeys.add(new ColumnStatsCacheKey(tableId, column));
}

try {
Map<ColumnStatsCacheKey, Optional<ColumnStatistic>> result =
columnStatistics.synchronous().getAll(cacheKeys);
List<ColumnStatistic> columnStatistics = new ArrayList<>();

for (String column : columns) {
Optional<ColumnStatistic> columnStatistic =
result.getOrDefault(new ColumnStatsCacheKey(tableId, column), Optional.empty());
if (columnStatistic.isPresent()) {
columnStatistics.add(columnStatistic.get());
} else {
columnStatistics.add(ColumnStatistic.unknown());
}
}
return columnStatistics;
} catch (Exception e) {
LOG.warn("Get column statistic fail, message : " + e.getMessage());
return getDefaultColumnStatisticList(columns);
}
}

/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ default Map<Long, List<ColumnStatistic>> getColumnStatisticsOfPartitionLevel(Tab
return null;
}

default List<ColumnStatistic> getColumnStatisticsSync(Table table, List<String> columns) {
return getColumnStatistics(table, columns);
}

default List<ConnectorTableColumnStats> getConnectorTableStatistics(Table table, List<String> columns) {
return columns.stream().
map(col -> ConnectorTableColumnStats.unknown()).collect(Collectors.toList());
Expand Down Expand Up @@ -97,6 +93,9 @@ default void expireTableAndColumnStatistics(Table table, List<String> columns) {
default void expireConnectorTableColumnStatistics(Table table, List<String> columns) {
}

default void refreshConnectorTableColumnStatistics(Table table, List<String> columns, boolean isSync) {
}

default void expireConnectorHistogramStatistics(Table table, List<String> columns) {
}

Expand Down
10 changes: 2 additions & 8 deletions fe/fe-core/src/main/java/com/starrocks/statistic/AnalyzeMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,12 @@ public void refreshBasicStatisticsCache(Long dbId, Long tableId, List<String> co

public void refreshConnectorTableBasicStatisticsCache(String catalogName, String dbName, String tableName,
List<String> columns, boolean async) {

Table table = GlobalStateMgr.getCurrentState().getMetadataMgr().getTable(catalogName, dbName, tableName);
if (table == null) {
return;
}

GlobalStateMgr.getCurrentState().getStatisticStorage().expireConnectorTableColumnStatistics(table, columns);
if (async) {
GlobalStateMgr.getCurrentState().getStatisticStorage().getConnectorTableStatistics(table, columns);
} else {
GlobalStateMgr.getCurrentState().getStatisticStorage().getConnectorTableStatisticsSync(table, columns);
}
GlobalStateMgr.getCurrentState().getStatisticStorage()
.refreshConnectorTableColumnStatistics(table, columns, async);
}

public void replayRemoveBasicStatsMeta(BasicStatsMeta basicStatsMeta) {
Expand Down

0 comments on commit 538caef

Please sign in to comment.