From ad5973a69e0a1046a02a1f5f22157761a51d9201 Mon Sep 17 00:00:00 2001 From: kaijianding Date: Mon, 9 Dec 2024 12:09:36 +0800 Subject: [PATCH] [Enhancement] should do compensation when mv is loose mode (#53562) Signed-off-by: kaijian.ding --- .../catalog/mv/MVTimelinessArbiter.java | 19 +++++++++++++++++++ .../mv/MVTimelinessListPartitionArbiter.java | 1 + .../mv/MVTimelinessRangePartitionArbiter.java | 1 + 3 files changed, 21 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessArbiter.java b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessArbiter.java index ffcf975ecd9fa..4627feffc66d2 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessArbiter.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessArbiter.java @@ -175,6 +175,25 @@ protected Map> collectBaseTableUpdatePartitionNames(Map> refBaseTableAndColumns = mv.getRefBaseTablePartitionColumns(); + // collect & update mv's to refresh partitions based on base table's partition changes + collectBaseTableUpdatePartitionNames(refBaseTableAndColumns, mvUpdateInfo); + Set
refBaseTables = mv.getRefBaseTablePartitionColumns().keySet(); + MaterializedView.AsyncRefreshContext context = mv.getRefreshScheme().getAsyncRefreshContext(); + for (Table table : refBaseTables) { + Map mvBaseTableVisibleVersionMap = + context.getBaseTableVisibleVersionMap() + .computeIfAbsent(table.getId(), k -> Maps.newHashMap()); + for (String partitionName : mvBaseTableVisibleVersionMap.keySet()) { + if (mvUpdateInfo.getBaseTableToRefreshPartitionNames(table) != null) { + // in loose mode, ignore partition that both exists in baseTable and mv + mvUpdateInfo.getBaseTableToRefreshPartitionNames(table).remove(partitionName); + } + } + } + } + /** * If base table is materialized view, add partition name to cell mapping into base table partition mapping; * otherwise base table(mv) may lose partition names of the real base table changed partitions. diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessListPartitionArbiter.java b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessListPartitionArbiter.java index b30a2d3ff0a8c..98346b5d9f9dc 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessListPartitionArbiter.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessListPartitionArbiter.java @@ -149,6 +149,7 @@ public MvUpdateInfo getMVTimelinessUpdateInfoInLoose() { mvUpdateInfo.getMvToRefreshPartitionNames().add(mvPartitionName); } addEmptyPartitionsToRefresh(mvUpdateInfo); + collectBaseTableUpdatePartitionNamesInLoose(mvUpdateInfo); return mvUpdateInfo; } } \ No newline at end of file diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessRangePartitionArbiter.java b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessRangePartitionArbiter.java index 7972318351bf5..b691671b38856 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessRangePartitionArbiter.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessRangePartitionArbiter.java @@ -180,6 +180,7 @@ protected MvUpdateInfo getMVTimelinessUpdateInfoInLoose() { mvUpdateInfo.addMvToRefreshPartitionNames(mvPartitionName); } addEmptyPartitionsToRefresh(mvUpdateInfo); + collectBaseTableUpdatePartitionNamesInLoose(mvUpdateInfo); return mvUpdateInfo; } }