diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/AbstractJob.java b/fe/fe-core/src/main/java/org/apache/doris/backup/AbstractJob.java index 85162b281f3c953..41f28dfe281cee6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/backup/AbstractJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/backup/AbstractJob.java @@ -24,9 +24,7 @@ import org.apache.doris.common.io.Writable; import org.apache.doris.persist.gson.GsonUtils; -import com.google.common.base.Preconditions; import com.google.common.collect.Maps; -import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; import java.io.DataInput; @@ -172,53 +170,28 @@ public void setTypeRead(boolean isTypeRead) { public abstract Status updateRepo(Repository repo); public static AbstractJob read(DataInput in) throws IOException { - 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(); + if (Env.getCurrentEnvJournalVersion() < FeMetaVersion.VERSION_136) { + 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; } else { - throw new IOException("Unknown job type: " + type.name()); + return GsonUtils.GSON.fromJson(Text.readString(in), AbstractJob.class); } - - job.setTypeRead(true); - job.readFields(in); - return job; } @Override public void write(DataOutput out) throws IOException { - // ATTN: must write type first - Text.writeString(out, type.name()); - - out.writeLong(repoId); - Text.writeString(out, label); - out.writeLong(jobId); - out.writeLong(dbId); - Text.writeString(out, dbName); - - out.writeLong(createTime); - out.writeLong(finishedTime); - out.writeLong(timeoutMs); - - if (!taskErrMsg.isEmpty()) { - out.writeBoolean(true); - // we only save at most 3 err msgs - int savedNum = Math.min(3, taskErrMsg.size()); - out.writeInt(savedNum); - for (Map.Entry entry : taskErrMsg.entrySet()) { - if (savedNum == 0) { - break; - } - out.writeLong(entry.getKey()); - Text.writeString(out, entry.getValue()); - savedNum--; - } - Preconditions.checkState(savedNum == 0, savedNum); - } else { - out.writeBoolean(false); - } + Text.writeString(out, GsonUtils.GSON.toJson(this)); } @Deprecated 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 07920724d5afec4..e6220ad656ce84f 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 @@ -35,12 +35,10 @@ import org.apache.doris.catalog.Tablet; import org.apache.doris.catalog.View; import org.apache.doris.common.Config; -import org.apache.doris.common.FeMetaVersion; import org.apache.doris.common.io.Text; import org.apache.doris.common.util.TimeUtils; import org.apache.doris.datasource.property.S3ClientBEProperties; import org.apache.doris.persist.BarrierLog; -import org.apache.doris.persist.gson.GsonUtils; import org.apache.doris.task.AgentBatchTask; import org.apache.doris.task.AgentTask; import org.apache.doris.task.AgentTaskExecutor; @@ -55,7 +53,6 @@ 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; @@ -65,7 +62,6 @@ 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; @@ -984,62 +980,6 @@ public static BackupJob read(DataInput in) throws IOException { 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 { - 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 entry : properties.entrySet()) { - Text.writeString(out, entry.getKey()); - Text.writeString(out, entry.getValue()); - } - } - public void readFields(DataInput in) throws IOException { super.readFields(in);