This is an automated email from the ASF dual-hosted git repository.

w41ter pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new df96db3f96d [fix](backup) Read BackupMeta with the specified meta 
version (#38396)
df96db3f96d is described below

commit df96db3f96d17213d0c010ea2b4aac2c2f62c28d
Author: walter <w41te...@gmail.com>
AuthorDate: Fri Jul 26 13:59:48 2024 +0800

    [fix](backup) Read BackupMeta with the specified meta version (#38396)
    
    Cherry-pick #38370
---
 .../org/apache/doris/backup/BackupHandler.java     | 33 +++++++++++-----------
 .../java/org/apache/doris/backup/BackupMeta.java   | 18 +++++++-----
 2 files changed, 28 insertions(+), 23 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java 
b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
index 23aa04c9709..31e2db4100b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
@@ -66,9 +66,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
-import java.io.ByteArrayInputStream;
 import java.io.DataInput;
-import java.io.DataInputStream;
 import java.io.DataOutput;
 import java.io.File;
 import java.io.IOException;
@@ -498,22 +496,25 @@ public class BackupHandler extends MasterDaemon 
implements Writable {
         // Create a restore job
         RestoreJob restoreJob;
         if (stmt.isLocal()) {
-            ByteArrayInputStream byteArrayInputStream = new 
ByteArrayInputStream(stmt.getMeta());
-            DataInputStream dataInputStream = new 
DataInputStream(byteArrayInputStream);
+            int metaVersion = stmt.getMetaVersion();
+            if (metaVersion == -1) {
+                metaVersion = jobInfo.metaVersion;
+            }
+
+            BackupMeta backupMeta;
             try {
-                BackupMeta backupMeta = BackupMeta.read(dataInputStream);
-                String backupTimestamp =
-                        TimeUtils.longToTimeString(jobInfo.getBackupTime(),
-                                
TimeUtils.getDatetimeFormatWithHyphenWithTimeZone());
-                restoreJob = new RestoreJob(stmt.getLabel(), backupTimestamp,
-                        db.getId(), db.getFullName(), jobInfo, 
stmt.allowLoad(), stmt.getReplicaAlloc(),
-                        stmt.getTimeoutMs(), stmt.getMetaVersion(), 
stmt.reserveReplica(),
-                        stmt.reserveDynamicPartitionEnable(), 
stmt.isBeingSynced(),
-                        env, Repository.KEEP_ON_LOCAL_REPO_ID, backupMeta);
+                backupMeta = BackupMeta.fromBytes(stmt.getMeta(), metaVersion);
             } catch (IOException e) {
-                LOG.warn("create restore job failed, current meta version {}", 
Env.getCurrentEnvJournalVersion(), e);
-                throw new DdlException("create restore job failed", e);
-            }
+                LOG.warn("read backup meta failed, current meta version {}", 
Env.getCurrentEnvJournalVersion(), e);
+                throw new DdlException("read backup meta failed", e);
+            }
+            String backupTimestamp = TimeUtils.longToTimeString(
+                    jobInfo.getBackupTime(), 
TimeUtils.getDatetimeFormatWithHyphenWithTimeZone());
+            restoreJob = new RestoreJob(stmt.getLabel(), backupTimestamp,
+                    db.getId(), db.getFullName(), jobInfo, stmt.allowLoad(), 
stmt.getReplicaAlloc(),
+                    stmt.getTimeoutMs(), metaVersion, stmt.reserveReplica(),
+                    stmt.reserveDynamicPartitionEnable(), stmt.isBeingSynced(),
+                    env, Repository.KEEP_ON_LOCAL_REPO_ID, backupMeta);
         } else {
             restoreJob = new RestoreJob(stmt.getLabel(), 
stmt.getBackupTimestamp(),
                 db.getId(), db.getFullName(), jobInfo, stmt.allowLoad(), 
stmt.getReplicaAlloc(),
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 e22bb7f33ce..6a973ea45a2 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
@@ -26,6 +26,7 @@ import org.apache.doris.persist.gson.GsonUtils;
 import com.google.common.collect.Maps;
 import com.google.gson.annotations.SerializedName;
 
+import java.io.ByteArrayInputStream;
 import java.io.DataInput;
 import java.io.DataInputStream;
 import java.io.DataOutput;
@@ -34,6 +35,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
 import java.util.Map;
 
@@ -83,11 +85,18 @@ public class BackupMeta implements Writable {
     }
 
     public static BackupMeta fromFile(String filePath, int metaVersion) throws 
IOException {
-        File file = new File(filePath);
+        return fromInputStream(new FileInputStream(filePath), metaVersion);
+    }
+
+    public static BackupMeta fromBytes(byte[] bytes, int metaVersion) throws 
IOException {
+        return fromInputStream(new ByteArrayInputStream(bytes), metaVersion);
+    }
+
+    protected static BackupMeta fromInputStream(InputStream stream, int 
metaVersion) throws IOException {
         MetaContext metaContext = new MetaContext();
         metaContext.setMetaVersion(metaVersion);
         metaContext.setThreadLocalInfo();
-        try (DataInputStream dis = new DataInputStream(new 
FileInputStream(file))) {
+        try (DataInputStream dis = new DataInputStream(stream)) {
             BackupMeta backupMeta = BackupMeta.read(dis);
             return backupMeta;
         } finally {
@@ -105,11 +114,6 @@ public class BackupMeta implements Writable {
         }
     }
 
-    public boolean compatibleWith(BackupMeta other) {
-        // TODO
-        return false;
-    }
-
     public static BackupMeta read(DataInput in) throws IOException {
         BackupMeta backupMeta = new BackupMeta();
         backupMeta.readFields(in);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to