Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dataroaring committed Jun 20, 2024
1 parent fc14d93 commit 57ba82f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 31 deletions.
36 changes: 11 additions & 25 deletions fe/fe-core/src/main/java/org/apache/doris/backup/AbstractJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,33 +172,19 @@ public void setTypeRead(boolean isTypeRead) {
public abstract Status updateRepo(Repository repo);

public static AbstractJob read(DataInput in) throws IOException {
if (Env.getCurrentEnvJournalVersion() < FeMetaVersion.VERSION_135) {
AbstractJob job = null;
JobType type = JobType.valueOf(Text.readString(in));
if (type == JobType.BACKUP) {
job = new BackupJob();
} else if (type == JobType.RESTORE) {
job = new RestoreJob();
} else {
throw new IOException("Unknown job type: " + type.name());
}

job.setTypeRead(true);
job.readFields(in);
return job;
AbstractJob job = null;
JobType type = JobType.valueOf(Text.readString(in));
if (type == JobType.BACKUP) {
job = new BackupJob();
} else if (type == JobType.RESTORE) {
job = new RestoreJob();
} else {
String json = Text.readString(in);
JsonObject jsonObject = GsonUtils.GSON.fromJson(json, JsonObject.class);
JobType type = JobType.valueOf(jsonObject.get("t").getAsString());
switch (type) {
case BACKUP:
return GsonUtils.GSON.fromJson(json, BackupJob.class);
case RESTORE:
return GsonUtils.GSON.fromJson(json, RestoreJob.class);
default:
throw new IOException("Unknown job type: " + type.name());
}
throw new IOException("Unknown job type: " + type.name());
}

job.setTypeRead(true);
job.readFields(in);
return job;
}

@Override
Expand Down
66 changes: 60 additions & 6 deletions fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
Expand All @@ -64,6 +65,7 @@
import org.apache.logging.log4j.Logger;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitOption;
Expand Down Expand Up @@ -976,14 +978,66 @@ private String getBackupObjs() {
return Joiner.on(", ").join(list);
}

public static BackupJob read(DataInput in) throws IOException {
if (Env.getCurrentEnvJournalVersion() < FeMetaVersion.VERSION_135) {
BackupJob job = new BackupJob();
job.readFields(in);
return job;
@Override
public void write(DataOutput out) throws IOException {
super.write(out);

// table refs
out.writeInt(tableRefs.size());
for (TableRef tblRef : tableRefs) {
tblRef.write(out);
}

// state
Text.writeString(out, state.name());

// times
out.writeLong(snapshotFinishedTime);
out.writeLong(snapshotUploadFinishedTime);

// snapshot info
out.writeInt(snapshotInfos.size());
for (SnapshotInfo info : snapshotInfos.values()) {
info.write(out);
}

// backup meta
if (backupMeta == null) {
out.writeBoolean(false);
} else {
return GsonUtils.GSON.fromJson(Text.readString(in), BackupJob.class);
out.writeBoolean(true);
backupMeta.write(out);
}

// No need to persist job info. It is generated then write to file

// metaInfoFilePath and jobInfoFilePath
if (Strings.isNullOrEmpty(localMetaInfoFilePath)) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
Text.writeString(out, localMetaInfoFilePath);
}

if (Strings.isNullOrEmpty(localJobInfoFilePath)) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
Text.writeString(out, localJobInfoFilePath);
}

// write properties
out.writeInt(properties.size());
for (Map.Entry<String, String> entry : properties.entrySet()) {
Text.writeString(out, entry.getKey());
Text.writeString(out, entry.getValue());
}
}

public static BackupJob read(DataInput in) throws IOException {
BackupJob job = new BackupJob();
job.readFields(in);
return job;
}

@Deprecated
Expand Down

0 comments on commit 57ba82f

Please sign in to comment.