Skip to content

Commit e234ad2

Browse files
seawindeyujun777
authored andcommitted
[fix](fe) Rebuild invalidated MTMV baseline on AUTO refresh (#33)
### What problem does this PR solve? Issue Number: N/A Related PR: N/A Problem Summary: Changing excluded_trigger_tables clears the refresh snapshot while leaving a successfully refreshed MTMV in NORMAL state. AUTO refresh could then run the partition freshness check with the new exclusions, incorrectly conclude that no refresh was needed, and leave stale data in the materialized view. Route only non-IVM AUTO refreshes in NORMAL/SUCCESS state without a snapshot directly to COMPLETE so the invalidated baseline is rebuilt, while preserving initial refresh and existing partition refresh behavior. ### Release note AUTO refresh now rebuilds a successfully established MTMV baseline after it has been invalidated. ### Check List (For Author) - Test: Unit Test and Regression Test - ./run-fe-ut.sh --run org.apache.doris.mtmv.MTMVTaskTest - ./run-regression-test.sh --run -d mtmv_p0 -s test_excluded_trigger_table_mtmv - Behavior changed: Yes. A non-IVM AUTO refresh rebuilds an invalidated successful baseline with COMPLETE refresh. - Does this need documentation: No
1 parent 376b597 commit e234ad2

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.apache.doris.mtmv.MTMVPartitionUtil;
5858
import org.apache.doris.mtmv.MTMVPlanUtil;
5959
import org.apache.doris.mtmv.MTMVRefreshContext;
60+
import org.apache.doris.mtmv.MTMVRefreshEnum.MTMVRefreshState;
6061
import org.apache.doris.mtmv.MTMVRefreshEnum.MTMVState;
6162
import org.apache.doris.mtmv.MTMVRefreshEnum.RefreshMethod;
6263
import org.apache.doris.mtmv.MTMVRefreshPartitionSnapshot;
@@ -449,6 +450,13 @@ private List<RefreshAttemptType> buildAttempts(RefreshRequest request, boolean c
449450
List<RefreshAttemptType> attempts = Lists.newArrayList();
450451
switch (request.refreshMode) {
451452
case AUTO:
453+
// ALTER excluded_trigger_tables clears a successful baseline without changing the MV state.
454+
if (!mtmv.isIvm() && !mtmv.hasRefreshSnapshot()
455+
&& mtmv.getStatus().getState() == MTMVState.NORMAL
456+
&& mtmv.getStatus().getRefreshState() == MTMVRefreshState.SUCCESS) {
457+
attempts.add(RefreshAttemptType.COMPLETE);
458+
break;
459+
}
452460
if (mtmv.isIvm()) {
453461
attempts.add(RefreshAttemptType.IVM);
454462
}

‎fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVTaskTest.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.apache.doris.job.extensions.mtmv.MTMVTask.MTMVTaskTriggerMode;
4040
import org.apache.doris.job.extensions.mtmv.MTMVTaskContext;
4141
import org.apache.doris.mtmv.MTMVPartitionInfo.MTMVPartitionType;
42+
import org.apache.doris.mtmv.MTMVRefreshEnum.MTMVRefreshState;
43+
import org.apache.doris.mtmv.MTMVRefreshEnum.MTMVState;
4244
import org.apache.doris.mtmv.MTMVRefreshEnum.RefreshMethod;
4345
import org.apache.doris.mtmv.ivm.IvmFailureReason;
4446
import org.apache.doris.mtmv.ivm.IvmIncrRefreshContext;
@@ -191,6 +193,34 @@ public void testBuildAttemptsAutoNonCompleteMethodKeepsPartitionsAttempt() {
191193
Assert.assertEquals(Lists.newArrayList("PARTITIONS", "COMPLETE"), toNames(attempts));
192194
}
193195

196+
@Test
197+
public void testBuildAttemptsAutoAfterSuccessfulRefreshWithoutSnapshotUsesComplete() {
198+
Mockito.when(mtmvRefreshInfo.getRefreshMethod()).thenReturn(RefreshMethod.AUTO);
199+
Mockito.when(mtmv.hasRefreshSnapshot()).thenReturn(false);
200+
MTMVStatus status = new MTMVStatus(MTMVRefreshState.SUCCESS);
201+
status.setState(MTMVState.NORMAL);
202+
Mockito.when(mtmv.getStatus()).thenReturn(status);
203+
204+
MTMVTask task = new MTMVTask(mtmv, relation, new MTMVTaskContext(MTMVTaskTriggerMode.MANUAL));
205+
Object request = Deencapsulation.invoke(task, "resolveRefreshRequest");
206+
List<?> attempts = (List<?>) Deencapsulation.invoke(task, "buildAttempts", request, false);
207+
208+
Assert.assertEquals(Lists.newArrayList("COMPLETE"), toNames(attempts));
209+
}
210+
211+
@Test
212+
public void testBuildAttemptsInitialAutoWithoutSnapshotKeepsFallbackChain() {
213+
Mockito.when(mtmvRefreshInfo.getRefreshMethod()).thenReturn(RefreshMethod.AUTO);
214+
Mockito.when(mtmv.hasRefreshSnapshot()).thenReturn(false);
215+
Mockito.when(mtmv.getStatus()).thenReturn(new MTMVStatus());
216+
217+
MTMVTask task = new MTMVTask(mtmv, relation, new MTMVTaskContext(MTMVTaskTriggerMode.MANUAL));
218+
Object request = Deencapsulation.invoke(task, "resolveRefreshRequest");
219+
List<?> attempts = (List<?>) Deencapsulation.invoke(task, "buildAttempts", request, false);
220+
221+
Assert.assertEquals(Lists.newArrayList("PARTITIONS", "COMPLETE"), toNames(attempts));
222+
}
223+
194224
@Test
195225
public void testBuildAttemptsAutoIvmIncrementalKeepsFullChain() {
196226
Mockito.when(mtmv.isIvm()).thenReturn(true);

0 commit comments

Comments
 (0)