Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -833,16 +833,23 @@ private void checkAndPrepareMeta() {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public Status resetIdsForRestore(Env env, Database db, ReplicaAllocation restore
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);
}
Expand Down
4 changes: 3 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/catalog/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ public static View read(DataInput in) throws IOException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading