This is an automated email from the ASF dual-hosted git repository.
w41ter 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 1f3313795f3 [fix](restore) Fix view name in atomic restore (#40876)
1f3313795f3 is described below
commit 1f3313795f37a725dbdf1a60d6518497f2458c04
Author: walter <[email protected]>
AuthorDate: Wed Sep 18 11:48:43 2024 +0800
[fix](restore) Fix view name in atomic restore (#40876)
Only olap table need to be replaced in atomic.
---
.../java/org/apache/doris/backup/RestoreJob.java | 2 +-
.../test_backup_restore_atomic_with_view.out | 60 ++++++++++
.../test_backup_restore_atomic_with_view.groovy | 124 +++++++++++++++++++++
3 files changed, 185 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
b/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
index 27ad19e1762..0098dfb3b87 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
@@ -909,7 +909,7 @@ public class RestoreJob extends AbstractJob implements
GsonPostProcessable {
if (Env.isStoredTableNamesLowerCase()) {
tableName = tableName.toLowerCase();
}
- if (isAtomicRestore) {
+ if (restoreTbl.getType() == TableType.OLAP && isAtomicRestore)
{
tableName = tableAliasWithAtomicRestore(tableName);
}
restoreTbl.setName(tableName);
diff --git
a/regression-test/data/backup_restore/test_backup_restore_atomic_with_view.out
b/regression-test/data/backup_restore/test_backup_restore_atomic_with_view.out
new file mode 100644
index 00000000000..cad6dbe8fd8
--- /dev/null
+++
b/regression-test/data/backup_restore/test_backup_restore_atomic_with_view.out
@@ -0,0 +1,60 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql --
+1 1
+2 2
+3 3
+4 4
+5 5
+6 6
+7 7
+8 8
+9 9
+10 10
+
+-- !sql --
+6 6
+7 7
+8 8
+9 9
+10 10
+
+-- !sql --
+1 1
+2 2
+3 3
+4 4
+5 5
+6 6
+7 7
+8 8
+9 9
+10 10
+
+-- !sql --
+6 6
+7 7
+8 8
+9 9
+10 10
+
+-- !sql --
+1 1
+2 2
+3 3
+4 4
+5 5
+6 6
+7 7
+8 8
+9 9
+10 10
+11 11
+
+-- !sql --
+6 6
+7 7
+8 8
+9 9
+10 10
+11 11
+
diff --git
a/regression-test/suites/backup_restore/test_backup_restore_atomic_with_view.groovy
b/regression-test/suites/backup_restore/test_backup_restore_atomic_with_view.groovy
new file mode 100644
index 00000000000..9d090281364
--- /dev/null
+++
b/regression-test/suites/backup_restore/test_backup_restore_atomic_with_view.groovy
@@ -0,0 +1,124 @@
+// 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_atomic_with_view", "backup_restore") {
+ String suiteName = "backup_restore_atomic_with_view"
+ String dbName = "${suiteName}_db"
+ String dbName1 = "${suiteName}_db_1"
+ String repoName = "repo_" + UUID.randomUUID().toString().replace("-", "")
+ String snapshotName = "${suiteName}_snapshot"
+ String tableName = "${suiteName}_table"
+ String viewName = "${suiteName}_view"
+
+ def syncer = getSyncer()
+ syncer.createS3Repository(repoName)
+ sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
+ sql "CREATE DATABASE IF NOT EXISTS ${dbName1}"
+
+ int numRows = 10;
+ sql "DROP TABLE IF EXISTS ${dbName}.${tableName} FORCE"
+ sql "DROP VIEW IF EXISTS ${dbName}.${viewName}"
+ 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 j = 1; j <= numRows; ++j) {
+ values.add("(${j}, ${j})")
+ }
+ sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}"
+
+ sql """CREATE VIEW ${dbName}.${viewName} (id, count)
+ AS
+ SELECT * FROM ${dbName}.${tableName} WHERE count > 5
+ """
+
+ qt_sql "SELECT * FROM ${dbName}.${tableName} ORDER BY id ASC"
+ qt_sql "SELECT * FROM ${dbName}.${viewName} ORDER BY id ASC"
+
+ sql """
+ BACKUP SNAPSHOT ${dbName}.${snapshotName}
+ TO `${repoName}`
+ """
+
+ syncer.waitSnapshotFinish(dbName)
+
+ def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
+ assertTrue(snapshot != null)
+
+ // restore new view
+ sql "DROP TABLE IF EXISTS ${dbName1}.${tableName} FORCE"
+ sql "DROP VIEW IF EXISTS ${dbName1}.${viewName}"
+
+ sql """
+ RESTORE SNAPSHOT ${dbName1}.${snapshotName}
+ FROM `${repoName}`
+ PROPERTIES
+ (
+ "backup_timestamp" = "${snapshot}",
+ "atomic_restore" = "true",
+ "reserve_replica" = "true"
+ )
+ """
+
+ syncer.waitAllRestoreFinish(dbName1)
+
+ qt_sql "SELECT * FROM ${dbName1}.${tableName} ORDER BY id ASC"
+ qt_sql "SELECT * FROM ${dbName1}.${viewName} ORDER BY id ASC"
+ def show_view_result = sql_return_maparray "SHOW VIEW FROM ${tableName}
FROM ${dbName1}"
+ logger.info("show view result: ${show_view_result}")
+ assertTrue(show_view_result.size() == 1);
+ def show_view = show_view_result[0]['Create View']
+ assertTrue(show_view.contains("${dbName1}"))
+ assertTrue(show_view.contains("${tableName}"))
+
+ // restore an exists view
+ sql """
+ RESTORE SNAPSHOT ${dbName}.${snapshotName}
+ FROM `${repoName}`
+ PROPERTIES
+ (
+ "backup_timestamp" = "${snapshot}",
+ "atomic_restore" = "true",
+ "reserve_replica" = "true"
+ )
+ """
+
+ syncer.waitAllRestoreFinish(dbName)
+ def restore_result = sql_return_maparray """ SHOW RESTORE FROM ${dbName}
WHERE Label ="${snapshotName}" """
+ restore_result.last()
+ logger.info("show restore result: ${restore_result}")
+ assertTrue(restore_result.last().State == "FINISHED")
+
+ // View could read the incremental data.
+ sql "INSERT INTO ${dbName}.${tableName} VALUES (11, 11)"
+
+ qt_sql "SELECT * FROM ${dbName}.${tableName} ORDER BY id ASC"
+ qt_sql "SELECT * FROM ${dbName}.${viewName} ORDER BY id ASC"
+
+ sql "DROP REPOSITORY `${repoName}`"
+}
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]