|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +import org.awaitility.Awaitility |
| 19 | +import static java.util.concurrent.TimeUnit.SECONDS |
| 20 | + |
| 21 | +suite("test_ivm_strict_failure_partition_atomicity", "nonConcurrent") { |
| 22 | + sql """DROP MATERIALIZED VIEW IF EXISTS ivm_strict_atomicity_mv""" |
| 23 | + sql """DROP TABLE IF EXISTS ivm_strict_atomicity_t""" |
| 24 | + sql """ |
| 25 | + CREATE TABLE ivm_strict_atomicity_t ( |
| 26 | + dt DATE NOT NULL, |
| 27 | + id BIGINT NOT NULL, |
| 28 | + v INT |
| 29 | + ) |
| 30 | + UNIQUE KEY(dt, id) |
| 31 | + PARTITION BY RANGE(dt) ( |
| 32 | + PARTITION p1 VALUES [('2026-01-01'), ('2026-02-01')), |
| 33 | + PARTITION p2 VALUES [('2026-02-01'), ('2026-03-01')), |
| 34 | + PARTITION p3 VALUES [('2026-03-01'), ('2026-04-01')) |
| 35 | + ) |
| 36 | + DISTRIBUTED BY HASH(id) BUCKETS 1 |
| 37 | + PROPERTIES ( |
| 38 | + "replication_num" = "1", |
| 39 | + "enable_unique_key_merge_on_write" = "true", |
| 40 | + "binlog.enable" = "true", |
| 41 | + "binlog.format" = "ROW", |
| 42 | + "binlog.need_historical_value" = "true" |
| 43 | + ) |
| 44 | + """ |
| 45 | + sql """INSERT INTO ivm_strict_atomicity_t VALUES |
| 46 | + ('2026-01-10', 1, 10), |
| 47 | + ('2026-02-10', 2, 20), |
| 48 | + ('2026-03-10', 3, 30)""" |
| 49 | + sql """ |
| 50 | + CREATE MATERIALIZED VIEW ivm_strict_atomicity_mv |
| 51 | + BUILD DEFERRED REFRESH INCREMENTAL ON MANUAL |
| 52 | + PARTITION BY(dt) |
| 53 | + DISTRIBUTED BY HASH(id) BUCKETS 1 |
| 54 | + PROPERTIES ("replication_num" = "1") |
| 55 | + AS SELECT dt, id, v FROM ivm_strict_atomicity_t |
| 56 | + """ |
| 57 | + sql """REFRESH MATERIALIZED VIEW ivm_strict_atomicity_mv COMPLETE""" |
| 58 | + waitingMTMVTaskFinishedByMvName("ivm_strict_atomicity_mv") |
| 59 | + order_qt_before_ddl """ |
| 60 | + SELECT dt, id, v FROM ivm_strict_atomicity_mv ORDER BY dt, id |
| 61 | + """ |
| 62 | + |
| 63 | + sql """TRUNCATE TABLE ivm_strict_atomicity_t PARTITION(p1)""" |
| 64 | + sql """ALTER TABLE ivm_strict_atomicity_t DROP PARTITION p2""" |
| 65 | + def previousTaskId = sql(""" |
| 66 | + SELECT TaskId FROM tasks('type'='mv') |
| 67 | + WHERE MvDatabaseName = '${context.dbName}' AND MvName = 'ivm_strict_atomicity_mv' |
| 68 | + ORDER BY CreateTime DESC, TaskId DESC LIMIT 1 |
| 69 | + """)[0][0].toString() |
| 70 | + |
| 71 | + sql """REFRESH MATERIALIZED VIEW ivm_strict_atomicity_mv INCREMENTAL""" |
| 72 | + Awaitility.await().atMost(300, SECONDS).pollInterval(2, SECONDS).until({ |
| 73 | + def task = sql_return_maparray(""" |
| 74 | + SELECT TaskId, Status FROM tasks('type'='mv') |
| 75 | + WHERE MvDatabaseName = '${context.dbName}' AND MvName = 'ivm_strict_atomicity_mv' |
| 76 | + ORDER BY CreateTime DESC, TaskId DESC LIMIT 1 |
| 77 | + """) |
| 78 | + return !task.isEmpty() |
| 79 | + && task[0].TaskId.toString() != previousTaskId |
| 80 | + && task[0].Status.toString() != 'PENDING' |
| 81 | + && task[0].Status.toString() != 'RUNNING' |
| 82 | + }) |
| 83 | + order_qt_strict_task """ |
| 84 | + SELECT Status, IvmFallbackReason, |
| 85 | + ErrorMsg LIKE '%baseline rebuild is pending%' |
| 86 | + FROM tasks('type'='mv') |
| 87 | + WHERE MvDatabaseName = '${context.dbName}' AND MvName = 'ivm_strict_atomicity_mv' |
| 88 | + ORDER BY CreateTime DESC, TaskId DESC LIMIT 1 |
| 89 | + """ |
| 90 | + order_qt_after_strict_failure """ |
| 91 | + SELECT dt, id, v FROM ivm_strict_atomicity_mv ORDER BY dt, id |
| 92 | + """ |
| 93 | + |
| 94 | + sql """REFRESH MATERIALIZED VIEW ivm_strict_atomicity_mv AUTO""" |
| 95 | + waitingMTMVTaskFinishedByMvName("ivm_strict_atomicity_mv") |
| 96 | + order_qt_after_auto_recovery """ |
| 97 | + SELECT dt, id, v FROM ivm_strict_atomicity_mv ORDER BY dt, id |
| 98 | + """ |
| 99 | +} |
0 commit comments