This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 861ae815641 [fix](mtmv) ignore MTMV when backup and restore (#35586)
861ae815641 is described below

commit 861ae8156418674ccf7d1e237f6586c7516b7b54
Author: zhangdong <493738...@qq.com>
AuthorDate: Thu May 30 16:05:26 2024 +0800

    [fix](mtmv) ignore MTMV when backup and restore (#35586)
    
    This is a temporary solution. In order to avoid affecting the existing
    backup function, the backup MTMV will be allowed after detailed design
---
 .../org/apache/doris/backup/BackupHandler.java     |  3 +-
 .../java/org/apache/doris/backup/BackupJob.java    |  2 +
 .../backup_restore/test_backup_restore_mtmv.groovy | 99 ++++++++++++++++++++++
 3 files changed, 103 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java 
b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
index e0c88ca8e9c..9e1956ab5a1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
@@ -388,7 +388,8 @@ public class BackupHandler extends MasterDaemon implements 
Writable {
         for (TableRef tblRef : tblRefs) {
             String tblName = tblRef.getName().getTbl();
             Table tbl = db.getTableOrDdlException(tblName);
-            if (tbl.getType() == TableType.VIEW || tbl.getType() == 
TableType.ODBC) {
+            if (tbl.getType() == TableType.VIEW || tbl.getType() == 
TableType.ODBC
+                    || tbl.getType() == TableType.MATERIALIZED_VIEW) {
                 continue;
             }
             if (tbl.getType() != TableType.OLAP) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java 
b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java
index fe13e02d9c8..0342ba70b80 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java
@@ -406,6 +406,8 @@ public class BackupJob extends AbstractJob {
             tbl.readLock();
             try {
                 switch (tbl.getType()) {
+                    case MATERIALIZED_VIEW:
+                        break;
                     case OLAP:
                         OlapTable olapTable = (OlapTable) tbl;
                         if (!checkOlapTable(olapTable, tableRef).ok()) {
diff --git 
a/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy 
b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy
new file mode 100644
index 00000000000..3646ec632bb
--- /dev/null
+++ b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy
@@ -0,0 +1,99 @@
+// 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_backup_restore_mtmv", "backup_restore") {
+    String suiteName = "test_backup_restore_mtmv"
+    String repoName = "${suiteName}_repo"
+    String dbName = "${suiteName}_db"
+    String tableName = "${suiteName}_table"
+    String mvName = "${suiteName}_mv"
+    String snapshotName = "${suiteName}_snapshot"
+
+    def syncer = getSyncer()
+    syncer.createS3Repository(repoName)
+
+    sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
+    sql "DROP TABLE IF EXISTS ${dbName}.${tableName}"
+    sql """
+        CREATE TABLE ${dbName}.${tableName} (
+            `id` LARGEINT NOT NULL,
+            `count` LARGEINT SUM DEFAULT "0")
+        AGGREGATE KEY(`id`)
+        DISTRIBUTED BY HASH(`id`) BUCKETS 2
+        PROPERTIES
+        (
+            "replication_num" = "1"
+        )
+        """
+
+    List<String> values = []
+    for (int i = 1; i <= 10; ++i) {
+        values.add("(${i}, ${i})")
+    }
+    sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}"
+    def result = sql "SELECT * FROM ${dbName}.${tableName}"
+    assertEquals(result.size(), values.size());
+
+    sql """drop materialized view if exists ${dbName}.${mvName};"""
+    sql """
+        CREATE MATERIALIZED VIEW ${dbName}.${mvName}
+        BUILD DEFERRED REFRESH COMPLETE ON MANUAL
+        DISTRIBUTED BY RANDOM BUCKETS 2
+        PROPERTIES ('replication_num' = '1')
+        AS
+        SELECT * FROM ${dbName}.${tableName};
+    """
+
+    sql """
+        BACKUP SNAPSHOT ${dbName}.${snapshotName}
+        TO `${repoName}`
+    """
+
+    syncer.waitSnapshotFinish(dbName)
+
+    def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
+    assertTrue(snapshot != null)
+
+    sql "TRUNCATE TABLE ${dbName}.${tableName}"
+    sql """drop materialized view if exists ${dbName}.${mvName};"""
+
+    sql """
+        RESTORE SNAPSHOT ${dbName}.${snapshotName}
+        FROM `${repoName}`
+        PROPERTIES
+        (
+            "backup_timestamp" = "${snapshot}",
+            "reserve_replica" = "true"
+        )
+    """
+
+    syncer.waitAllRestoreFinish(dbName)
+
+    result = sql "SELECT * FROM ${dbName}.${tableName}"
+    assertEquals(result.size(), values.size());
+
+    result = sql "show tables FROM ${dbName}"
+    // now should not contain mtmv
+    logger.info("result: " + result.toString())
+    assertFalse(result.toString().contains("${mvName}"));
+
+    sql """drop materialized view if exists ${dbName}.${mvName};"""
+    sql "DROP TABLE ${dbName}.${tableName} FORCE"
+    sql "DROP DATABASE ${dbName} FORCE"
+    sql "DROP REPOSITORY `${repoName}`"
+}
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to