Skip to content

Commit

Permalink
[fix](restore) Fix view signature (#41120)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
w41ter authored Sep 23, 2024
1 parent 7348e73 commit 48a22d2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
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

0 comments on commit 48a22d2

Please sign in to comment.