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

w41ter pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new c81182aed81 [fix](restore) Fix clean restore with view #40620 (#41186)
c81182aed81 is described below

commit c81182aed81c83bfff64e97368f7d5641f740848
Author: walter <w41te...@gmail.com>
AuthorDate: Tue Sep 24 14:10:27 2024 +0800

    [fix](restore) Fix clean restore with view #40620 (#41186)
    
    cherry pick from #40620
---
 .../java/org/apache/doris/backup/RestoreJob.java   | 28 ++++++++++-------
 .../test_backup_restore_clean_restore.groovy       | 36 ++++++++++++++++++++--
 2 files changed, 51 insertions(+), 13 deletions(-)

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 558c9ddf33c..1a937c58a0f 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
@@ -2048,22 +2048,28 @@ public class RestoreJob extends AbstractJob {
     }
 
     private Status dropAllNonRestoredTableAndPartitions(Database db) {
+        Set<String> restoredViews = jobInfo.newBackupObjects.views.stream()
+                .map(view -> view.name).collect(Collectors.toSet());
+
         try {
             for (Table table : db.getTables()) {
                 long tableId = table.getId();
                 String tableName = table.getName();
                 TableType tableType = table.getType();
-                BackupOlapTableInfo backupTableInfo = 
jobInfo.backupOlapTableObjects.get(tableName);
-                if (tableType != TableType.OLAP && tableType != TableType.ODBC 
&& tableType != TableType.VIEW) {
-                    continue;
-                }
-                if (tableType == TableType.OLAP && backupTableInfo != null) {
-                    // drop the non restored partitions.
-                    dropNonRestoredPartitions(db, (OlapTable) table, 
backupTableInfo);
-                } else if (isCleanTables) {
-                    // otherwise drop the entire table.
-                    LOG.info("drop non restored table {}({}). {}", tableName, 
tableId, this);
-                    boolean isForceDrop = false; // move this table into 
recyclebin.
+                if (tableType == TableType.OLAP) {
+                    BackupOlapTableInfo backupTableInfo = 
jobInfo.backupOlapTableObjects.get(tableName);
+                    if (tableType == TableType.OLAP && backupTableInfo != 
null) {
+                        // drop the non restored partitions.
+                        dropNonRestoredPartitions(db, (OlapTable) table, 
backupTableInfo);
+                    } else if (isCleanTables) {
+                        // otherwise drop the entire table.
+                        LOG.info("drop non restored table {}, table id: {}. 
{}", tableName, tableId, this);
+                        boolean isForceDrop = false; // move this table into 
recyclebin.
+                        env.getInternalCatalog().dropTableWithoutCheck(db, 
table, isForceDrop);
+                    }
+                } else if (tableType == TableType.VIEW && isCleanTables && 
!restoredViews.contains(tableName)) {
+                    LOG.info("drop non restored view {}, table id: {}. {}", 
tableName, tableId, this);
+                    boolean isForceDrop = false; // move this view into 
recyclebin.
                     env.getInternalCatalog().dropTableWithoutCheck(db, table, 
isForceDrop);
                 }
             }
diff --git 
a/regression-test/suites/backup_restore/test_backup_restore_clean_restore.groovy
 
b/regression-test/suites/backup_restore/test_backup_restore_clean_restore.groovy
index 3b27a32b69d..88e07f9e769 100644
--- 
a/regression-test/suites/backup_restore/test_backup_restore_clean_restore.groovy
+++ 
b/regression-test/suites/backup_restore/test_backup_restore_clean_restore.groovy
@@ -77,6 +77,7 @@ suite("test_backup_restore_clean_restore", "backup_restore") {
         )
     """
 
+
     sql "INSERT INTO ${dbName}.${tableName2} VALUES ${values.join(",")}"
     result = sql "SELECT * FROM ${dbName}.${tableName2}"
     assertEquals(result.size(), numRows);
@@ -106,6 +107,25 @@ suite("test_backup_restore_clean_restore", 
"backup_restore") {
     result = sql "SELECT * FROM ${dbName}.${tableName3}"
     assertEquals(result.size(), numRows);
 
+    // view 1 must exists
+    String viewName1 = "${tableNamePrefix}_4"
+    sql "DROP VIEW IF EXISTS ${dbName}.${viewName1}"
+    sql """
+        CREATE VIEW ${dbName}.${viewName1} (k1, k2)
+        AS
+        SELECT id as k1, count as k2 FROM ${dbName}.${tableName1}
+        WHERE id in (1,3,5,7,9)
+    """
+
+    // view 2 will be deleted
+    String viewName2 = "${tableNamePrefix}_5"
+    sql "DROP VIEW IF EXISTS ${dbName}.${viewName2}"
+    sql """
+        CREATE VIEW ${dbName}.${viewName2} (k1, k2)
+        AS
+        SELECT id as k1, count as k2 FROM ${dbName}.${tableName3}
+        WHERE id in (1,3,5,7,9)
+    """
 
     sql """
         BACKUP SNAPSHOT ${dbName}.${snapshotName}
@@ -117,13 +137,14 @@ suite("test_backup_restore_clean_restore", 
"backup_restore") {
     def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
     assertTrue(snapshot != null)
 
-    // restore table1, partition 3 of table2
+    // restore table1, partition 3 of table2, view1
     sql """
         RESTORE SNAPSHOT ${dbName}.${snapshotName}
         FROM `${repoName}`
         ON (
             `${tableName1}`,
-            `${tableName2}` PARTITION (`p3`)
+            `${tableName2}` PARTITION (`p3`),
+            `${viewName1}`
         )
         PROPERTIES
         (
@@ -144,12 +165,23 @@ suite("test_backup_restore_clean_restore", 
"backup_restore") {
     result = sql "SELECT * FROM ${dbName}.${tableName2}"
     assertEquals(result.size(), numRows-10)
 
+    // view1 are exists
+    result = sql """ SHOW VIEW FROM ${tableName1} FROM ${dbName} """
+    assertEquals(result.size(), 1)
+
+    // view2 are dropped
+    result = sql """
+        SHOW TABLE STATUS FROM ${dbName} LIKE "${viewName2}"
+    """
+    assertEquals(result.size(), 0)
+
     // table3 are dropped
     result = sql """
         SHOW TABLE STATUS FROM ${dbName} LIKE "${tableName3}"
     """
     assertEquals(result.size(), 0)
 
+    sql "DROP VIEW ${dbName}.${viewName1}"
     sql "DROP TABLE ${dbName}.${tableName1} FORCE"
     sql "DROP TABLE ${dbName}.${tableName2} FORCE"
     sql "DROP DATABASE ${dbName} FORCE"


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

Reply via email to