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 48a22d2f956 [fix](restore) Fix view signature (#41120)
48a22d2f956 is described below
commit 48a22d2f95677afb96c7ddb860feb9d5405e73b5
Author: walter <[email protected]>
AuthorDate: Mon Sep 23 17:58:53 2024 +0800
[fix](restore) Fix view signature (#41120)
1. reset with dbName instead of dbFullName, to be compatible with doris
2.0(full name has prefix `default_cluster:`)
2. since the referred db name of the restored view has changed, the next
time to restore the view, the signature is not matched, so the db names
should be reset and compared with the signature again.
---
.../java/org/apache/doris/backup/RestoreJob.java | 21 ++++++++++++++-------
.../java/org/apache/doris/catalog/OlapTable.java | 2 +-
.../main/java/org/apache/doris/catalog/View.java | 4 +++-
.../test_backup_restore_with_view.groovy | 17 +++++++++++++++++
4 files changed, 35 insertions(+), 9 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 d5d2754fa92..ded9b6a843b 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
@@ -833,16 +833,23 @@ public class RestoreJob extends AbstractJob implements
GsonPostProcessable {
if (localTbl != null) {
Preconditions.checkState(localTbl.getType() ==
TableType.VIEW);
View localView = (View) localTbl;
- if
(!localView.getSignature(BackupHandler.SIGNATURE_VERSION)
-
.equals(remoteView.getSignature(BackupHandler.SIGNATURE_VERSION))) {
- status = new Status(ErrCode.COMMON_ERROR, "View "
- +
jobInfo.getAliasByOriginNameIfSet(backupViewName)
- + " already exist but with different schema");
- return;
+ String localViewSignature =
localView.getSignature(BackupHandler.SIGNATURE_VERSION);
+ // keep compatible with old version, compare the signature
without reset view def
+ if
(!localViewSignature.equals(remoteView.getSignature(BackupHandler.SIGNATURE_VERSION)))
{
+ // reset view def to dest db name and compare
signature again
+ String srcDbName = jobInfo.dbName;
+ remoteView.resetViewDefForRestore(srcDbName,
db.getName());
+ if
(!localViewSignature.equals(remoteView.getSignature(BackupHandler.SIGNATURE_VERSION)))
{
+ status = new Status(ErrCode.COMMON_ERROR, "View "
+ +
jobInfo.getAliasByOriginNameIfSet(backupViewName)
+ + " already exist but with different
schema");
+ return;
+ }
}
} else {
String srcDbName = jobInfo.dbName;
- remoteView.resetIdsForRestore(env, srcDbName,
db.getFullName());
+ remoteView.resetViewDefForRestore(srcDbName, db.getName());
+ remoteView.resetIdsForRestore(env);
restoredTbls.add(remoteView);
}
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
index 1f591d1b7bf..07916231118 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
@@ -791,7 +791,7 @@ public class OlapTable extends Table implements
MTMVRelatedTableIf, GsonPostProc
baseIndexId = newIdxId;
}
MaterializedIndexMeta indexMeta =
origIdxIdToMeta.get(entry.getKey());
- indexMeta.resetIndexIdForRestore(newIdxId, srcDbName,
db.getFullName());
+ indexMeta.resetIndexIdForRestore(newIdxId, srcDbName,
db.getName());
indexIdToMeta.put(newIdxId, indexMeta);
indexNameToId.put(entry.getValue(), newIdxId);
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java
index 707464aeaf7..236a1f0fc28 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java
@@ -258,9 +258,11 @@ public class View extends Table implements
GsonPostProcessable {
return GsonUtils.GSON.fromJson(Text.readString(in), View.class);
}
- public void resetIdsForRestore(Env env, String srcDbName, String dbName) {
+ public void resetIdsForRestore(Env env) {
id = env.getNextId();
+ }
+ public void resetViewDefForRestore(String srcDbName, String dbName) {
// the source db name is not setted in old BackupMeta, keep compatible
with the old one.
if (srcDbName != null) {
inlineViewDef = inlineViewDef.replaceAll(srcDbName, dbName);
diff --git
a/regression-test/suites/backup_restore/test_backup_restore_with_view.groovy
b/regression-test/suites/backup_restore/test_backup_restore_with_view.groovy
index be776995323..10b21bb3442 100644
--- a/regression-test/suites/backup_restore/test_backup_restore_with_view.groovy
+++ b/regression-test/suites/backup_restore/test_backup_restore_with_view.groovy
@@ -109,6 +109,23 @@ suite("test_backup_restore_with_view", "backup_restore") {
logger.info("show restore result: ${restore_result}")
assertTrue(restore_result.last().State == "FINISHED")
+ // restore to db1, test the view signature.
+ sql """
+ RESTORE SNAPSHOT ${dbName1}.${snapshotName}
+ FROM `${repoName}`
+ PROPERTIES
+ (
+ "backup_timestamp" = "${snapshot}",
+ "reserve_replica" = "true"
+ )
+ """
+
+ syncer.waitAllRestoreFinish(dbName1)
+ restore_result = sql_return_maparray """ SHOW RESTORE FROM ${dbName1}
WHERE Label ="${snapshotName}" """
+ restore_result.last()
+ logger.info("show restore result: ${restore_result}")
+ assertTrue(restore_result.last().State == "FINISHED")
+
sql "DROP TABLE ${dbName}.${tableName} FORCE"
sql "DROP VIEW ${dbName}.${viewName}"
sql "DROP DATABASE ${dbName} FORCE"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]