hello-stephen commented on code in PR #71451:
URL: https://github.com/apache/doris/pull/71451#discussion_r4811107703
##########
fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java:
##########
@@ -1312,6 +1334,44 @@ private AttemptResultType
handleIvmFallbackResult(IvmIncrRefreshResult ivmResult
return AttemptResultType.FALLBACK_ALLOWED;
}
+ private boolean isPartialPartitionFallback() {
+ return ivmFallbackReasonEnum()
+ .map(IvmFailureReason::allowsPartialPartitionFallback)
+ .orElse(false);
+ }
+
+ private Optional<IvmFailureReason> ivmFallbackReasonEnum() {
+ if (ivmFallbackReason == null) {
+ return Optional.empty();
+ }
+ try {
+ return Optional.of(IvmFailureReason.valueOf(ivmFallbackReason));
+ } catch (IllegalArgumentException e) {
+ return Optional.empty();
+ }
+ }
+
+ private boolean canUsePartialPartitionFallback(List<String>
plannedPartitions) {
+ if (mtmv.getMvPartitionInfo() == null
+ || mtmv.getMvPartitionInfo().getPartitionType() !=
MTMVPartitionType.FOLLOW_BASE_TABLE) {
+ return false;
+ }
+ // If an earlier dirty-partition rebuild ran in the same task before
the failed delta,
+ // excludingRebuiltPartitions may have filtered out a partition that
changed again before
+ // the delta failed. Fall back to COMPLETE so no pending delete is
skipped.
+ if (!partitionSnapshots.isEmpty()) {
+ return false;
+ }
+ Set<String> allPartitions = mtmv.getPartitionNames();
+ if (allPartitions.size() <= 1 || plannedPartitions.isEmpty()) {
+ return false;
+ }
+ // Only allow PARTITIONS fallback when a strict subset of MV
partitions needs refresh.
+ // Any non-PCT base table change causes getMTMVNeedRefreshPartitions
to return all MV
+ // partitions, so strict-subset guarantees only PCT base partitions
changed.
+ return plannedPartitions.size() < allPartitions.size();
Review Comment:
[P2] Verify partition locality for each scan before resetting offsets
Consider a view partitioned by `d` whose reduced plan is:
```text
Aggregate(group by d, MIN(v))
UNION ALL
Project(t.d, t.v)
Scan(t)
Project(u.d, t.v)
InnerJoin(u.k = t.k)
Scan(u)
Scan(t)
```
With aligned January and February partitions on both sources,
`PartitionIncrementMaintainer.visitLogicalUnion` collects `t.d` from the first
arm and `u.d` from the second. That makes `t` a PCT table even though its
second scan can contribute to any month. For example, build both months in one
COMPLETE batch with `ivm_minmax_top_k=1`. Give `u` key 7 in both months and
give `t` values 10 and 20 in January and 100 in February for that key. Deleting
the 10 exhausts February's retained MIN even though its correct minimum is now
20. Only January's PCT snapshot changes, so this gate accepts a January-only
overwrite. That overwrite resets `t`'s January stream offset while February
keeps the deleted minimum, and later incremental refreshes cannot replay it.
Use COMPLETE when a reset source has a scan whose effect can cross the selected
MV partitions.
##########
fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVTaskTest.java:
##########
@@ -1857,6 +1857,60 @@ public void
testExpiredOffsetInTheRebuildBeforeTheDeltaFallsBackToComplete() thr
Deencapsulation.getField(task, "ivmFallbackReason"));
}
+ @Test
+ public void testMinMaxAndBitmapDeleteFallbackAllowsPartitionRefresh()
throws Exception {
+ Mockito.when(mtmv.isIvm()).thenReturn(true);
+ Mockito.when(mtmv.getName()).thenReturn("test_mv");
+ MTMVRefreshContext refreshContext = mockIvmIncrRefreshContext();
+
+ for (IvmFailureReason reason : Lists.newArrayList(
+ IvmFailureReason.MIN_MAX_BOUNDARY_HIT,
IvmFailureReason.BITMAP_AGG_DELETE)) {
+ MTMVTask task = new MTMVTask(mtmv, relation,
MTMVTaskContext.of(MTMVTaskTriggerMode.MANUAL, null,
+ RefreshMode.INCREMENTAL, true, null));
+ try (MockedConstruction<IvmIncrRefreshManager> ignored =
Mockito.mockConstruction(
+ IvmIncrRefreshManager.class,
+ (mock, context) ->
Mockito.when(mock.doRefresh(Mockito.any()))
+ .thenReturn(IvmIncrRefreshResult.fallback(reason,
"boundary delete")))) {
+ Object request = Deencapsulation.invoke(task,
"resolveRefreshRequest");
+ Object result = Deencapsulation.invoke(task,
"executeIvmAttempt", refreshContext, request,
+ new ConnectContext(), Lists.newArrayList());
+ Assertions.assertEquals("FALLBACK_ALLOWED", result.toString(),
Review Comment:
[P3] Exercise bitmap partition fallback through the next delta
This mock stops at `FALLBACK_ALLOWED`. The existing bitmap runtime fixture
builds a SELF_MANAGE view and exercises COMPLETE, while the changed partitioned
metrics fixture covers MIN/MAX. A bitmap fallback that takes COMPLETE or leaves
the deleted change pending would still pass. Add a real bitmap delete on a
multi-partition PCT MV, verify the rebuilt scope and bitmap result, and run a
strict incremental refresh before any explicit COMPLETE.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]