This is an automated email from the ASF dual-hosted git repository.
w41ter pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new d5d5f8f9e19 [fix](restore) Fix clean restore with view #40620 (#41185)
d5d5f8f9e19 is described below
commit d5d5f8f9e191a65aacbf298541f82ab9bda7b421
Author: walter <[email protected]>
AuthorDate: Tue Sep 24 11:14:46 2024 +0800
[fix](restore) Fix clean restore with view #40620 (#41185)
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 56921b6d02c..6e2fb3bcb6a 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
@@ -2003,22 +2003,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 c80bc0d0060..b667e0cfcc3 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}
@@ -119,13 +139,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
(
@@ -148,12 +169,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: [email protected]
For additional commands, e-mail: [email protected]