[meta](recover) change dropInfo and RecoverInfo to GSON (#13830)

This commit is contained in:
Mingyu Chen
2022-11-02 13:32:46 +08:00
committed by GitHub
parent e6080a6e4c
commit ee8dffbfb7
3 changed files with 44 additions and 32 deletions

View File

@ -196,8 +196,7 @@ public class JournalEntity implements Writable {
break;
}
case OperationType.OP_DROP_TABLE: {
data = new DropInfo();
((DropInfo) data).readFields(in);
data = DropInfo.read(in);
isRead = true;
break;
}
@ -238,14 +237,12 @@ public class JournalEntity implements Writable {
case OperationType.OP_RECOVER_DB:
case OperationType.OP_RECOVER_TABLE:
case OperationType.OP_RECOVER_PARTITION: {
data = new RecoverInfo();
((RecoverInfo) data).readFields(in);
data = RecoverInfo.read(in);
isRead = true;
break;
}
case OperationType.OP_DROP_ROLLUP: {
data = new DropInfo();
((DropInfo) data).readFields(in);
data = DropInfo.read(in);
isRead = true;
break;
}

View File

@ -19,18 +19,26 @@ package org.apache.doris.persist;
import org.apache.doris.catalog.Env;
import org.apache.doris.common.FeMetaVersion;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.persist.gson.GsonUtils;
import com.google.gson.annotations.SerializedName;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class DropInfo implements Writable {
@SerializedName(value = "dbId")
private long dbId;
@SerializedName(value = "tableId")
private long tableId;
@SerializedName(value = "indexId")
private long indexId;
@SerializedName(value = "forceDrop")
private boolean forceDrop = false;
@SerializedName(value = "recycleTime")
private long recycleTime = 0;
public DropInfo() {
@ -61,24 +69,16 @@ public class DropInfo implements Writable {
}
public Long getRecycleTime() {
return recycleTime;
return recycleTime;
}
@Override
public void write(DataOutput out) throws IOException {
out.writeLong(dbId);
out.writeLong(tableId);
out.writeBoolean(forceDrop);
if (indexId == -1L) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeLong(indexId);
}
out.writeLong(recycleTime);
Text.writeString(out, GsonUtils.GSON.toJson(this));
}
public void readFields(DataInput in) throws IOException {
@Deprecated
private void readFields(DataInput in) throws IOException {
dbId = in.readLong();
tableId = in.readLong();
forceDrop = in.readBoolean();
@ -88,15 +88,16 @@ public class DropInfo implements Writable {
} else {
indexId = -1L;
}
if (Env.getCurrentEnvJournalVersion() >= FeMetaVersion.VERSION_114) {
recycleTime = in.readLong();
}
}
public static DropInfo read(DataInput in) throws IOException {
DropInfo dropInfo = new DropInfo();
dropInfo.readFields(in);
return dropInfo;
if (Env.getCurrentEnvJournalVersion() >= FeMetaVersion.VERSION_114) {
return GsonUtils.GSON.fromJson(Text.readString(in), DropInfo.class);
} else {
DropInfo dropInfo = new DropInfo();
dropInfo.readFields(in);
return dropInfo;
}
}
public boolean equals(Object obj) {

View File

@ -21,17 +21,26 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.common.FeMetaVersion;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.persist.gson.GsonUtils;
import com.google.gson.annotations.SerializedName;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class RecoverInfo implements Writable {
@SerializedName(value = "dbId")
private long dbId;
@SerializedName(value = "newDbName")
private String newDbName;
@SerializedName(value = "tableId")
private long tableId;
@SerializedName(value = "newTableName")
private String newTableName;
@SerializedName(value = "partitionId")
private long partitionId;
@SerializedName(value = "newPartitionName")
private String newPartitionName;
public RecoverInfo() {
@ -83,15 +92,20 @@ public class RecoverInfo implements Writable {
Text.writeString(out, newPartitionName);
}
public void readFields(DataInput in) throws IOException {
dbId = in.readLong();
tableId = in.readLong();
partitionId = in.readLong();
public static RecoverInfo read(DataInput in) throws IOException {
if (Env.getCurrentEnvJournalVersion() >= FeMetaVersion.VERSION_114) {
newDbName = Text.readString(in);
newTableName = Text.readString(in);
newPartitionName = Text.readString(in);
return GsonUtils.GSON.fromJson(Text.readString(in), RecoverInfo.class);
} else {
RecoverInfo recoverInfo = new RecoverInfo();
recoverInfo.readFields(in);
return recoverInfo;
}
}
@Deprecated
private void readFields(DataInput in) throws IOException {
dbId = in.readLong();
tableId = in.readLong();
partitionId = in.readLong();
}
}