From c5bac191e12870fa514d885e7b1fcd582d9ac91e Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Wed, 29 May 2024 10:21:42 +0800 Subject: [PATCH 1/6] 1 --- .../src/main/java/org/apache/doris/backup/BackupHandler.java | 3 ++- 1 file changed, 2 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 c3e59e269f6cc7..44b60acbc397da 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 @@ private void backup(Repository repository, Database db, BackupStmt stmt) throws 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) { From 6396167459dbca65d76449fce9ccd54f641b2ccf Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Wed, 29 May 2024 12:15:46 +0800 Subject: [PATCH 2/6] 1 --- fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java | 2 ++ 1 file changed, 2 insertions(+) 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 5404fcca064dde..8dfe95f8910ce9 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 @@ -403,6 +403,8 @@ private void prepareAndSendSnapshotTask() { tbl.readLock(); try { switch (tbl.getType()) { + case MATERIALIZED_VIEW: + break; case OLAP: OlapTable olapTable = (OlapTable) tbl; if (!checkOlapTable(olapTable, tableRef).ok()) { From caa732046f53c5939f53d18dd212c799c3568402 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Wed, 29 May 2024 14:31:27 +0800 Subject: [PATCH 3/6] 1 --- .../test_backup_restore_mtmv.groovy | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy 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 00000000000000..c1add29b12b211 --- /dev/null +++ b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy @@ -0,0 +1,93 @@ +// 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" + 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 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 ${mvName};""" + sql """ + CREATE MATERIALIZED VIEW ${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 """ + 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()); + + sql """drop materialized view if exists ${mvName};""" + sql "DROP TABLE ${dbName}.${tableName} FORCE" + sql "DROP DATABASE ${dbName} FORCE" + sql "DROP REPOSITORY `${repoName}`" +} + From c04f8f16338390389575c91cbd2f233583538393 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Wed, 29 May 2024 17:02:43 +0800 Subject: [PATCH 4/6] 1 --- .../suites/backup_restore/test_backup_restore_mtmv.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy index c1add29b12b211..8bf0adf7c439e7 100644 --- a/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy @@ -16,7 +16,7 @@ // under the License. suite("test_backup_restore_mtmv", "backup_restore") { - String suiteName = "test_backup_restore" + String suiteName = "test_backup_restore_mtmv" String repoName = "${suiteName}_repo" String dbName = "${suiteName}_db" String tableName = "${suiteName}_table" From 51a9085f83768c582152214916aaddcc559e99e4 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 30 May 2024 10:16:22 +0800 Subject: [PATCH 5/6] 1 --- .../suites/backup_restore/test_backup_restore_mtmv.groovy | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy index 8bf0adf7c439e7..54c1c5b9b07066 100644 --- a/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy @@ -69,6 +69,7 @@ suite("test_backup_restore_mtmv", "backup_restore") { assertTrue(snapshot != null) sql "TRUNCATE TABLE ${dbName}.${tableName}" + sql """drop materialized view if exists ${mvName};""" sql """ RESTORE SNAPSHOT ${dbName}.${snapshotName} @@ -85,6 +86,10 @@ suite("test_backup_restore_mtmv", "backup_restore") { result = sql "SELECT * FROM ${dbName}.${tableName}" assertEquals(result.size(), values.size()); + result = sql "show tables FROM ${dbName}" + // now should not contain mtmv + assertFalse(result.toString().contains("${mvName}")); + sql """drop materialized view if exists ${mvName};""" sql "DROP TABLE ${dbName}.${tableName} FORCE" sql "DROP DATABASE ${dbName} FORCE" From 1a0b0c3ca375d7636344bf8167a03ee90f5ece56 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 30 May 2024 10:19:55 +0800 Subject: [PATCH 6/6] 1 --- .../backup_restore/test_backup_restore_mtmv.groovy | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy index 54c1c5b9b07066..3646ec632bba4e 100644 --- a/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore_mtmv.groovy @@ -48,9 +48,9 @@ suite("test_backup_restore_mtmv", "backup_restore") { def result = sql "SELECT * FROM ${dbName}.${tableName}" assertEquals(result.size(), values.size()); - sql """drop materialized view if exists ${mvName};""" + sql """drop materialized view if exists ${dbName}.${mvName};""" sql """ - CREATE MATERIALIZED VIEW ${mvName} + CREATE MATERIALIZED VIEW ${dbName}.${mvName} BUILD DEFERRED REFRESH COMPLETE ON MANUAL DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ('replication_num' = '1') @@ -69,7 +69,7 @@ suite("test_backup_restore_mtmv", "backup_restore") { assertTrue(snapshot != null) sql "TRUNCATE TABLE ${dbName}.${tableName}" - sql """drop materialized view if exists ${mvName};""" + sql """drop materialized view if exists ${dbName}.${mvName};""" sql """ RESTORE SNAPSHOT ${dbName}.${snapshotName} @@ -88,9 +88,10 @@ suite("test_backup_restore_mtmv", "backup_restore") { 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 ${mvName};""" + sql """drop materialized view if exists ${dbName}.${mvName};""" sql "DROP TABLE ${dbName}.${tableName} FORCE" sql "DROP DATABASE ${dbName} FORCE" sql "DROP REPOSITORY `${repoName}`"