diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java index d0f02d85ff96cb7..cf47bcc2c7b3355 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java @@ -454,7 +454,7 @@ private void prepareAndSendSnapshotTask() { } } - backupMeta = new BackupMeta(copiedTables, copiedResources); + backupMeta = new BackupMeta(db.getName(), copiedTables, copiedResources); // send tasks for (AgentTask task : batchTask.getAllTasks()) { @@ -991,8 +991,6 @@ public void readFields(DataInput in) throws IOException { // table refs int size = in.readInt(); - LOG.info("read {} tablerefs ", size); - tableRefs = Lists.newArrayList(); for (int i = 0; i < size; i++) { TableRef tblRef = TableRef.read(in); @@ -1007,8 +1005,6 @@ public void readFields(DataInput in) throws IOException { // snapshot info size = in.readInt(); - LOG.info("read {} snapshotinfo ", size); - for (int i = 0; i < size; i++) { SnapshotInfo snapshotInfo = SnapshotInfo.read(in); snapshotInfos.put(snapshotInfo.getTabletId(), snapshotInfo); @@ -1016,7 +1012,6 @@ public void readFields(DataInput in) throws IOException { // backup meta if (in.readBoolean()) { - LOG.info("read backup meta"); backupMeta = BackupMeta.read(in); } @@ -1032,8 +1027,6 @@ public void readFields(DataInput in) throws IOException { } // read properties size = in.readInt(); - LOG.info("read {} property ", size); - for (int i = 0; i < size; i++) { String key = Text.readString(in); String value = Text.readString(in); diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupMeta.java b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupMeta.java index e27c8d19a840a29..c08d8c160027c8f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupMeta.java +++ b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupMeta.java @@ -42,7 +42,8 @@ import java.util.Map; public class BackupMeta implements Writable, GsonPostProcessable { - + @SerializedName(value = "db") + private String dbName; // tbl name -> tbl @SerializedName(value = "tblNameMap") private Map tblNameMap = Maps.newHashMap(); @@ -55,7 +56,9 @@ public class BackupMeta implements Writable, GsonPostProcessable { private BackupMeta() { } - public BackupMeta(List tables, List resources) { + public BackupMeta(String dbName, List
tables, List resources) { + this.dbName = dbName; + for (Table table : tables) { tblNameMap.put(table.getName(), table); tblIdMap.put(table.getId(), table); @@ -65,6 +68,10 @@ public BackupMeta(List
tables, List resources) { } } + public String getDbName() { + return dbName; + } + public Map getTables() { return tblNameMap; } 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 098c473d32e22ef..ac94e03f2524d80 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 @@ -783,7 +783,8 @@ private void checkAndPrepareMeta() { return; } } else { - remoteView.resetIdsForRestore(env); + String srcDbName = backupMeta.getDbName(); + remoteView.resetIdsForRestore(env, srcDbName, db.getFullName()); restoredTbls.add(remoteView); } } 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 4d2558f8748ab8b..8285dedc0941b84 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 @@ -250,8 +250,13 @@ public static View read(DataInput in) throws IOException { return GsonUtils.GSON.fromJson(Text.readString(in), View.class); } - public void resetIdsForRestore(Env env) { + public void resetIdsForRestore(Env env, String srcDbName, String dbName) { id = env.getNextId(); + + // the source db name is not setted in old BackupMeta, keep compatible with the old one. + if (srcDbName != null) { + inlineViewDef = inlineViewDef.replaceAll(srcDbName, dbName); + } } @Override diff --git a/fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.java b/fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.java index 97e689b697256c4..5de2be6c9ee5f05 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.java @@ -212,7 +212,7 @@ public Status getSnapshotInfoFile(String label, String backupTimestamp, List tbls = Lists.newArrayList(); tbls.add(tbl); List resources = Lists.newArrayList(); - BackupMeta backupMeta = new BackupMeta(tbls, resources); + BackupMeta backupMeta = new BackupMeta(null, tbls, resources); Map snapshotInfos = Maps.newHashMap(); for (Partition part : tbl.getPartitions()) { for (MaterializedIndex idx : part.getMaterializedIndices(IndexExtState.VISIBLE)) { diff --git a/fe/fe-core/src/test/java/org/apache/doris/backup/RestoreJobTest.java b/fe/fe-core/src/test/java/org/apache/doris/backup/RestoreJobTest.java index 71cad0438c90220..43bdc5c2675cf97 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/backup/RestoreJobTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/backup/RestoreJobTest.java @@ -258,7 +258,7 @@ boolean await(long timeout, TimeUnit unit) { List
tbls = Lists.newArrayList(); List resources = Lists.newArrayList(); tbls.add(expectedRestoreTbl); - backupMeta = new BackupMeta(tbls, resources); + backupMeta = new BackupMeta(null, tbls, resources); } @Test