From 03942f23f60b314af078bc1b38eda00e61fd8f69 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Tue, 2 Jul 2024 23:08:58 +0800 Subject: [PATCH] =?UTF-8?q?[fix](mtmv)fix=20when=20related=20table=20drop?= =?UTF-8?q?=20partition,mv=20partition=20is=20sync=E2=80=A6=20(#36602)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pick: https://github.com/apache/doris/pull/36547 --- .../apache/doris/mtmv/MTMVPartitionUtil.java | 5 +++++ .../apache/doris/mtmv/MTMVRefreshSnapshot.java | 9 +++++++++ .../doris/mtmv/MTMVPartitionUtilTest.java | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java index 82a649be37cf92..6595afb70f7419 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java @@ -325,6 +325,11 @@ public static boolean isSyncWithPartitions(MTMV mtmv, String mtmvPartitionName, if (!relatedTable.needAutoRefresh()) { return true; } + // check if partitions of related table if changed + Set snapshotPartitions = mtmv.getRefreshSnapshot().getSnapshotPartitions(mtmvPartitionName); + if (!Objects.equals(relatedPartitionNames, snapshotPartitions)) { + return false; + } for (String relatedPartitionName : relatedPartitionNames) { MTMVSnapshotIf relatedPartitionCurrentSnapshot = relatedTable .getPartitionSnapshot(relatedPartitionName); diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java index c1d07b2704951c..d48911275e886b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java @@ -18,6 +18,7 @@ package org.apache.doris.mtmv; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.gson.annotations.SerializedName; import org.apache.commons.collections.MapUtils; @@ -46,6 +47,14 @@ public boolean equalsWithRelatedPartition(String mtmvPartitionName, String relat return relatedPartitionSnapshot.equals(relatedPartitionCurrentSnapshot); } + public Set getSnapshotPartitions(String mtmvPartitionName) { + MTMVRefreshPartitionSnapshot partitionSnapshot = partitionSnapshots.get(mtmvPartitionName); + if (partitionSnapshot == null) { + return Sets.newHashSet(); + } + return partitionSnapshot.getPartitions().keySet(); + } + public boolean equalsWithBaseTable(String mtmvPartitionName, long baseTableId, MTMVSnapshotIf baseTableCurrentSnapshot) { MTMVRefreshPartitionSnapshot partitionSnapshot = partitionSnapshots.get(mtmvPartitionName); diff --git a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java index 261b750c79698d..c125e548d06ac6 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java @@ -130,6 +130,10 @@ public void setUp() throws NoSuchMethodException, SecurityException, AnalysisExc refreshSnapshot.equalsWithRelatedPartition(anyString, anyString, (MTMVSnapshotIf) any); minTimes = 0; result = true; + + refreshSnapshot.getSnapshotPartitions(anyString); + minTimes = 0; + result = Sets.newHashSet("name2"); } }; } @@ -160,6 +164,20 @@ public void testIsSyncWithPartition() throws AnalysisException { Assert.assertTrue(isSyncWithPartition); } + @Test + public void testIsSyncWithPartitionNotEqual() throws AnalysisException { + new Expectations() { + { + refreshSnapshot.getSnapshotPartitions(anyString); + minTimes = 0; + result = Sets.newHashSet("name2", "name3"); + } + }; + boolean isSyncWithPartition = MTMVPartitionUtil + .isSyncWithPartitions(mtmv, "name1", baseOlapTable, Sets.newHashSet("name2")); + Assert.assertFalse(isSyncWithPartition); + } + @Test public void testIsSyncWithPartitionNotSync() throws AnalysisException { new Expectations() {