yujun777 commented on code in PR #71404: URL: https://github.com/apache/doris/pull/71404#discussion_r4807058250
########## regression-test/suites/mtmv_p0/test_chain_on_commit_coalesce.groovy: ########## @@ -0,0 +1,188 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_chain_on_commit_coalesce") { + def dbName = context.config.getDbNameByFile(context.file) + def tableName = "test_chain_on_commit_coalesce_tbl" + def mvUp = "test_chain_on_commit_coalesce_mv_up" + def mvDown = "test_chain_on_commit_coalesce_mv_down" + def mvDown2 = "test_chain_on_commit_coalesce_mv_down2" + + def getLatestTask = { String mvName -> + def rows = sql_return_maparray """ + SELECT TaskId, Status, CreateTime, FinishTime, RefreshMode, TaskContext FROM tasks('type'='mv') + WHERE MvDatabaseName='${dbName}' AND MvName='${mvName}' + ORDER BY CreateTime DESC, TaskId DESC LIMIT 1 + """ + assertFalse(rows.isEmpty(), "Expected at least one task for ${mvName}") + return rows[0] + } + + def getCommitTaskCount = { String mvName -> + def rows = sql_return_maparray """ + SELECT TaskId FROM tasks('type'='mv') + WHERE MvDatabaseName='${dbName}' AND MvName='${mvName}' + AND TaskContext LIKE '%"triggerMode":"COMMIT"%' + """ + return rows.size() + } + + def waitCommitTaskReached = { String mvName, int minCount -> + long deadline = System.currentTimeMillis() + 60_000L + while (System.currentTimeMillis() < deadline) { + if (getCommitTaskCount(mvName) >= minCount) { + return + } + Thread.sleep(200) + } + assertTrue(getCommitTaskCount(mvName) >= minCount, + "Expected at least ${minCount} COMMIT tasks for ${mvName}, got ${getCommitTaskCount(mvName)}") + } + + sql """drop materialized view if exists ${mvDown2};""" + sql """drop materialized view if exists ${mvDown};""" + sql """drop materialized view if exists ${mvUp};""" + sql """drop table if exists ${tableName};""" + + sql """ + CREATE TABLE ${tableName} ( + k1 INT NOT NULL, + dt DATE NOT NULL, + v1 INT NOT NULL + ) ENGINE=OLAP + DUPLICATE KEY(k1, dt) + PARTITION BY RANGE(dt) ( + PARTITION p1 VALUES [('2024-01-01'), ('2024-01-02')), + PARTITION p2 VALUES [('2024-01-02'), ('2024-01-03')), + PARTITION p3 VALUES [('2024-01-03'), ('2024-01-04')), + PARTITION p4 VALUES [('2024-01-04'), ('2024-01-05')), + PARTITION p5 VALUES [('2024-01-05'), ('2024-01-06')), + PARTITION p6 VALUES [('2024-01-06'), ('2024-01-07')) + ) + DISTRIBUTED BY HASH(k1) BUCKETS 2 + PROPERTIES ('replication_num' = '1'); + """ + + sql """ + INSERT INTO ${tableName} VALUES + (1, '2024-01-01', 10), + (2, '2024-01-02', 20), + (3, '2024-01-03', 30), + (4, '2024-01-04', 40), + (5, '2024-01-05', 50), + (6, '2024-01-06', 60); + """ + + // Upstream partitioned MV refreshes 1 partition per batch (6 separate batch commits) + sql """ + CREATE MATERIALIZED VIEW ${mvUp} + BUILD DEFERRED REFRESH AUTO ON MANUAL + PARTITION BY (dt) + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1', + 'refresh_partition_num' = '1' + ) + AS SELECT k1, dt, v1 FROM ${tableName}; + """ + + // Downstream 2nd-level and 3rd-level ON COMMIT MVs + sql """ + CREATE MATERIALIZED VIEW ${mvDown} + BUILD DEFERRED REFRESH AUTO ON COMMIT + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS SELECT dt, SUM(v1) AS total_v1 FROM ${mvUp} GROUP BY dt; + """ + + sql """ + CREATE MATERIALIZED VIEW ${mvDown2} + BUILD DEFERRED REFRESH AUTO ON COMMIT + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS SELECT COUNT(*) AS day_cnt, SUM(total_v1) AS grand_total FROM ${mvDown}; + """ + + def jobUp = getJobName(dbName, mvUp) + def jobDown = getJobName(dbName, mvDown) + def jobDown2 = getJobName(dbName, mvDown2) + + // 1. Refresh all 6 partitions in 6 batches -> downstream MVs must each trigger only once + sql """REFRESH MATERIALIZED VIEW ${mvUp} AUTO;""" + waitingMTMVTaskFinishedByMvName(mvUp, dbName) + waitCommitTaskReached(mvDown, 1) + waitingMTMVTaskFinished(jobDown) + waitCommitTaskReached(mvDown2, 1) + waitingMTMVTaskFinished(jobDown2) + + assertEquals(1, getCommitTaskCount(mvDown)) + assertEquals(1, getCommitTaskCount(mvDown2)) + def upTask1 = getLatestTask(mvUp) + def downTask1 = getLatestTask(mvDown) + def down2Task1 = getLatestTask(mvDown2) + assertTrue(downTask1.CreateTime >= upTask1.FinishTime, + "Expected ${mvDown} task (${downTask1.CreateTime}) to be created after ${mvUp} finished (${upTask1.FinishTime})") + assertTrue(down2Task1.CreateTime >= downTask1.FinishTime, + "Expected ${mvDown2} task (${down2Task1.CreateTime}) to be created after ${mvDown} finished (${downTask1.FinishTime})") + order_qt_mv_down_initial "SELECT dt, total_v1 FROM ${mvDown}" + order_qt_mv_down2_initial "SELECT day_cnt, grand_total FROM ${mvDown2}" + + // 2. No-op refresh (NOT_REFRESH) -> must not trigger downstream + sql """REFRESH MATERIALIZED VIEW ${mvUp} AUTO;""" + waitingMTMVTaskFinishedByMvName(mvUp, dbName) + def upNoopTask = getLatestTask(mvUp) + assertEquals("NOT_REFRESH", upNoopTask.RefreshMode) + Thread.sleep(1000) + assertEquals(1, getCommitTaskCount(mvDown)) + assertEquals(1, getCommitTaskCount(mvDown2)) + + // 3. Partition drop alignment on upstream -> triggers downstream once + sql """ALTER TABLE ${tableName} DROP PARTITION p6 FORCE;""" + sql """REFRESH MATERIALIZED VIEW ${mvUp} AUTO;""" + waitingMTMVTaskFinishedByMvName(mvUp, dbName) + waitCommitTaskReached(mvDown, 2) + waitingMTMVTaskFinished(jobDown) + waitCommitTaskReached(mvDown2, 2) + waitingMTMVTaskFinished(jobDown2) + + assertEquals(2, getCommitTaskCount(mvDown)) + assertEquals(2, getCommitTaskCount(mvDown2)) + order_qt_mv_down_after_drop "SELECT dt, total_v1 FROM ${mvDown}" + order_qt_mv_down2_after_drop "SELECT day_cnt, grand_total FROM ${mvDown2}" + + // 4. Direct insert into upstream MV outside refresh -> triggers downstream immediately + try { + sql """SET allow_modify_materialized_view_data = true;""" + sql """INSERT INTO ${mvUp} VALUES (7, '2024-01-05', 5);""" + } finally { + sql """SET allow_modify_materialized_view_data = false;""" + } + waitCommitTaskReached(mvDown, 3) + waitingMTMVTaskFinished(jobDown) + waitCommitTaskReached(mvDown2, 3) + waitingMTMVTaskFinished(jobDown2) + + assertEquals(3, getCommitTaskCount(mvDown)) + assertEquals(3, getCommitTaskCount(mvDown2)) + order_qt_mv_down_after_direct_insert "SELECT dt, total_v1 FROM ${mvDown}" + order_qt_mv_down2_after_direct_insert "SELECT day_cnt, grand_total FROM ${mvDown2}" + + sql """drop materialized view if exists ${mvDown2};""" Review Comment: Fixed in a2ca987d6e0. Removed the final teardown `DROP` statements so the test tables and MVs remain available for inspection. ########## fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVService.java: ########## @@ -209,7 +274,8 @@ public void processEvent(Event event) throws EventException { jobManager.onCommit(mtmv); } } catch (Exception e) { - throw new EventException(e); + LOG.warn("trigger downstream mtmv failed, baseTable: {}, mtmv: {}", Review Comment: Rejecting a submission when `TaskProcessor`'s queue (`mtmv_task_queue_size`, default 1024) is full without a background retry queue is pre-existing behavior for all `ON COMMIT` triggers, and coalescing upstream batch events significantly reduces queue pressure compared to enqueueing on every batch. Adding a separate retry queue for rejected `TaskProcessor` submissions is out of scope for this fix. -- 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]
