|
| 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 | +package org.apache.doris.mtmv.ivm; |
| 19 | + |
| 20 | +import org.apache.doris.catalog.Env; |
| 21 | +import org.apache.doris.catalog.MTMV; |
| 22 | +import org.apache.doris.catalog.info.TableNameInfo; |
| 23 | +import org.apache.doris.utframe.TestWithFeService; |
| 24 | + |
| 25 | +import org.junit.jupiter.api.Assertions; |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | + |
| 28 | +public class IvmBinlogBrokenTest extends TestWithFeService { |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testTruncateMarksBinlogBroken() throws Exception { |
| 32 | + String db = "ivm_broken_truncate"; |
| 33 | + createPartitionedIvmTableAndMv(db); |
| 34 | + |
| 35 | + executeSql("TRUNCATE TABLE ivm_base"); |
| 36 | + |
| 37 | + Assertions.assertTrue(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testTruncatePartitionMarksBinlogBroken() throws Exception { |
| 42 | + String db = "ivm_broken_truncate_partition"; |
| 43 | + createPartitionedIvmTableAndMv(db); |
| 44 | + |
| 45 | + executeSql("TRUNCATE TABLE ivm_base PARTITION(p202001)"); |
| 46 | + |
| 47 | + Assertions.assertTrue(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testDropPartitionMarksBinlogBroken() throws Exception { |
| 52 | + String db = "ivm_broken_drop_partition"; |
| 53 | + createPartitionedIvmTableAndMv(db); |
| 54 | + |
| 55 | + executeSql("ALTER TABLE ivm_base DROP PARTITION p202001"); |
| 56 | + |
| 57 | + Assertions.assertTrue(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testReplacePartitionMarksBinlogBroken() throws Exception { |
| 62 | + String db = "ivm_broken_replace_partition"; |
| 63 | + createPartitionedIvmTableAndMv(db); |
| 64 | + |
| 65 | + executeSql("ALTER TABLE ivm_base ADD TEMPORARY PARTITION tp202001 " |
| 66 | + + "VALUES [('2020-01-01'), ('2020-02-01'))"); |
| 67 | + executeSql("ALTER TABLE ivm_base REPLACE PARTITION (p202001) " |
| 68 | + + "WITH TEMPORARY PARTITION (tp202001)"); |
| 69 | + |
| 70 | + Assertions.assertTrue(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testRecoverPartitionMarksBinlogBroken() throws Exception { |
| 75 | + String db = "ivm_broken_recover_partition"; |
| 76 | + createPartitionedIvmTableAndMv(db); |
| 77 | + executeSql("ALTER TABLE ivm_base DROP PARTITION p202001"); |
| 78 | + setBinlogBroken(getMtmv(db), false); |
| 79 | + |
| 80 | + executeSql("RECOVER PARTITION p202001 FROM ivm_base"); |
| 81 | + |
| 82 | + Assertions.assertTrue(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void testAddPartitionDoesNotMarkBinlogBroken() throws Exception { |
| 87 | + String db = "ivm_broken_add_partition"; |
| 88 | + createPartitionedIvmTableAndMv(db); |
| 89 | + |
| 90 | + executeSql("ALTER TABLE ivm_base ADD PARTITION p202003 " |
| 91 | + + "VALUES [('2020-03-01'), ('2020-04-01'))"); |
| 92 | + |
| 93 | + Assertions.assertFalse(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testDropTempPartitionDoesNotMarkBinlogBroken() throws Exception { |
| 98 | + String db = "ivm_broken_drop_temp_partition"; |
| 99 | + createPartitionedIvmTableAndMv(db); |
| 100 | + executeSql("ALTER TABLE ivm_base ADD TEMPORARY PARTITION tp202001 " |
| 101 | + + "VALUES [('2020-01-01'), ('2020-02-01'))"); |
| 102 | + |
| 103 | + executeSql("ALTER TABLE ivm_base DROP TEMPORARY PARTITION tp202001"); |
| 104 | + |
| 105 | + Assertions.assertFalse(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void testDropMissingPartitionIfExistsDoesNotMarkBinlogBroken() throws Exception { |
| 110 | + String db = "ivm_broken_drop_missing_partition"; |
| 111 | + createPartitionedIvmTableAndMv(db); |
| 112 | + |
| 113 | + executeSql("ALTER TABLE ivm_base DROP PARTITION IF EXISTS p_missing"); |
| 114 | + |
| 115 | + Assertions.assertFalse(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 116 | + } |
| 117 | + |
| 118 | + private void createPartitionedIvmTableAndMv(String db) throws Exception { |
| 119 | + createDatabaseAndUse(db); |
| 120 | + createTable("CREATE TABLE " + db + ".ivm_base (\n" |
| 121 | + + " dt date NOT NULL,\n" |
| 122 | + + " k1 int,\n" |
| 123 | + + " v1 int\n" |
| 124 | + + ")\n" |
| 125 | + + "DUPLICATE KEY(dt, k1)\n" |
| 126 | + + "PARTITION BY RANGE(dt) (\n" |
| 127 | + + " PARTITION p202001 VALUES [('2020-01-01'), ('2020-02-01')),\n" |
| 128 | + + " PARTITION p202002 VALUES [('2020-02-01'), ('2020-03-01'))\n" |
| 129 | + + ")\n" |
| 130 | + + "DISTRIBUTED BY HASH(k1) BUCKETS 1\n" |
| 131 | + + "PROPERTIES ('replication_num' = '1', 'binlog.enable' = 'true', 'binlog.format' = 'ROW')"); |
| 132 | + createMvByNereids("CREATE MATERIALIZED VIEW ivm_mv\n" |
| 133 | + + "BUILD DEFERRED REFRESH INCREMENTAL ON MANUAL\n" |
| 134 | + + "DISTRIBUTED BY RANDOM BUCKETS 1\n" |
| 135 | + + "PROPERTIES ('replication_num' = '1')\n" |
| 136 | + + "AS SELECT dt, k1, v1 FROM ivm_base"); |
| 137 | + Assertions.assertTrue(getMtmv(db).isIvm()); |
| 138 | + Assertions.assertFalse(getMtmv(db).getIvmInfo().isBinlogBroken()); |
| 139 | + } |
| 140 | + |
| 141 | + private MTMV getMtmv(String db) throws Exception { |
| 142 | + return (MTMV) Env.getCurrentInternalCatalog() |
| 143 | + .getDb(db).get() |
| 144 | + .getTableOrMetaException("ivm_mv"); |
| 145 | + } |
| 146 | + |
| 147 | + private void setBinlogBroken(MTMV mtmv, boolean binlogBroken) { |
| 148 | + IvmInfo info = new IvmInfo(mtmv.getIvmInfo()); |
| 149 | + info.setBinlogBroken(binlogBroken); |
| 150 | + Env.getCurrentEnv().alterMTMVIvmInfo( |
| 151 | + new TableNameInfo(mtmv.getQualifiedDbName(), mtmv.getName()), info); |
| 152 | + } |
| 153 | +} |
0 commit comments