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
33 changes: 17 additions & 16 deletions fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@
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;
Expand Down Expand Up @@ -512,22 +510,25 @@ private void restore(Repository repository, Database db, RestoreStmt stmt) throw
// 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(),
Expand Down
32 changes: 13 additions & 19 deletions fe/fe-core/src/main/java/org/apache/doris/backup/BackupMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand All @@ -38,12 +39,14 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class BackupMeta implements Writable, GsonPostProcessable {
@SerializedName(value = "db")
private String dbName;

// tbl name -> tbl
@SerializedName(value = "tblNameMap")
private Map<String, Table> tblNameMap = Maps.newHashMap();
Expand Down Expand Up @@ -93,12 +96,19 @@ public Table getTable(Long tblId) {
}

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))) {
BackupMeta backupMeta = BackupMeta.read(dis, metaVersion);
try (DataInputStream dis = new DataInputStream(stream)) {
BackupMeta backupMeta = BackupMeta.read(dis);
return backupMeta;
} finally {
MetaContext.remove();
Expand All @@ -115,22 +125,6 @@ public void writeToFile(File metaInfoFile) throws IOException {
}
}

public boolean compatibleWith(BackupMeta other) {
// TODO
return false;
}

public static BackupMeta read(DataInput in, int metaVersion) throws IOException {
if (metaVersion < FeMetaVersion.VERSION_136) {
BackupMeta backupMeta = new BackupMeta();
backupMeta.readFields(in);
return backupMeta;
} else {
String json = Text.readString(in);
return GsonUtils.GSON.fromJson(json, BackupMeta.class);
}
}

public static BackupMeta read(DataInput in) throws IOException {
if (Env.getCurrentEnvJournalVersion() < FeMetaVersion.VERSION_136) {
BackupMeta backupMeta = new BackupMeta();
Expand Down