Skip to content

Commit 6770947

Browse files
authored
[fix](recyclebin) db can not be serialized with gson directly. (#37261)
Do not serialize list in recyclebin too. It may takes memory beyond 2GB.
1 parent 9ce5707 commit 6770947

File tree

2 files changed

+105
-13
lines changed

2 files changed

+105
-13
lines changed

fe/fe-common/src/main/java/org/apache/doris/common/FeMetaVersion.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ public final class FeMetaVersion {
9999

100100
public static final int VERSION_138 = 138;
101101

102+
public static final int VERSION_139 = 139;
103+
102104
// note: when increment meta version, should assign the latest version to VERSION_CURRENT
103-
public static final int VERSION_CURRENT = VERSION_138;
105+
public static final int VERSION_CURRENT = VERSION_139;
104106

105107
// all logs meta version should >= the minimum version, so that we could remove many if clause, for example
106108
// if (FE_METAVERSION < VERSION_94) ...

fe/fe-core/src/main/java/org/apache/doris/catalog/CatalogRecycleBin.java

+102-12
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ public class CatalogRecycleBin extends MasterDaemon implements Writable, GsonPos
6868
// to avoid erase log ahead of drop log
6969
private static final long minEraseLatency = 10 * 60 * 1000; // 10 min
7070

71-
@SerializedName(value = "itd")
7271
private Map<Long, RecycleDatabaseInfo> idToDatabase;
73-
@SerializedName(value = "itt")
7472
private Map<Long, RecycleTableInfo> idToTable;
75-
@SerializedName(value = "itp")
7673
private Map<Long, RecyclePartitionInfo> idToPartition;
77-
@SerializedName(value = "itr")
7874
private Map<Long, Long> idToRecycleTime;
7975

76+
// for compatible in the future
77+
@SerializedName("u")
78+
String unused;
79+
8080
public CatalogRecycleBin() {
8181
super("recycle bin", FeConstants.runningUnitTest ? 10L : DEFAULT_INTERVAL_SECONDS * 1000L);
8282
idToDatabase = Maps.newHashMap();
@@ -1287,17 +1287,75 @@ public synchronized Map<Long, Pair<Long, Long>> getDbToRecycleSize() {
12871287
// this class is not protected by any lock, will throw ConcurrentModificationException.
12881288
@Override
12891289
public synchronized void write(DataOutput out) throws IOException {
1290+
out.writeInt(idToDatabase.size());
1291+
for (Map.Entry<Long, RecycleDatabaseInfo> entry : idToDatabase.entrySet()) {
1292+
out.writeLong(entry.getKey());
1293+
entry.getValue().write(out);
1294+
}
1295+
out.writeInt(idToTable.size());
1296+
for (Map.Entry<Long, RecycleTableInfo> entry : idToTable.entrySet()) {
1297+
out.writeLong(entry.getKey());
1298+
entry.getValue().write(out);
1299+
}
1300+
out.writeInt(idToPartition.size());
1301+
for (Map.Entry<Long, RecyclePartitionInfo> entry : idToPartition.entrySet()) {
1302+
out.writeLong(entry.getKey());
1303+
entry.getValue().write(out);
1304+
}
1305+
out.writeInt(idToRecycleTime.size());
1306+
for (Map.Entry<Long, Long> entry : idToRecycleTime.entrySet()) {
1307+
out.writeLong(entry.getKey());
1308+
out.writeLong(entry.getValue());
1309+
}
12901310
Text.writeString(out, GsonUtils.GSON.toJson(this));
12911311
}
12921312

1313+
public void readFieldsWithGson(DataInput in) throws IOException {
1314+
int count = in.readInt();
1315+
for (int i = 0; i < count; i++) {
1316+
long id = in.readLong();
1317+
RecycleDatabaseInfo dbInfo = new RecycleDatabaseInfo();
1318+
dbInfo.readFields(in);
1319+
idToDatabase.put(id, dbInfo);
1320+
}
1321+
1322+
count = in.readInt();
1323+
for (int i = 0; i < count; i++) {
1324+
long id = in.readLong();
1325+
RecycleTableInfo tableInfo = new RecycleTableInfo();
1326+
tableInfo = tableInfo.read(in);
1327+
idToTable.put(id, tableInfo);
1328+
}
1329+
1330+
count = in.readInt();
1331+
for (int i = 0; i < count; i++) {
1332+
long id = in.readLong();
1333+
RecyclePartitionInfo partitionInfo = new RecyclePartitionInfo();
1334+
partitionInfo = partitionInfo.read(in);
1335+
idToPartition.put(id, partitionInfo);
1336+
}
1337+
1338+
count = in.readInt();
1339+
for (int i = 0; i < count; i++) {
1340+
long id = in.readLong();
1341+
long time = in.readLong();
1342+
idToRecycleTime.put(id, time);
1343+
}
1344+
GsonUtils.GSON.fromJson(Text.readString(in), CatalogRecycleBin.class);
1345+
}
1346+
12931347
public static CatalogRecycleBin read(DataInput in) throws IOException {
1294-
if (Env.getCurrentEnvJournalVersion() >= FeMetaVersion.VERSION_136) {
1348+
if (Env.getCurrentEnvJournalVersion() < FeMetaVersion.VERSION_136) {
1349+
CatalogRecycleBin bin = new CatalogRecycleBin();
1350+
bin.readFields(in);
1351+
return bin;
1352+
} else if (Env.getCurrentEnvJournalVersion() < FeMetaVersion.VERSION_139) {
12951353
return GsonUtils.GSON.fromJson(Text.readString(in), CatalogRecycleBin.class);
1354+
} else {
1355+
CatalogRecycleBin bin = new CatalogRecycleBin();
1356+
bin.readFieldsWithGson(in);
1357+
return bin;
12961358
}
1297-
1298-
CatalogRecycleBin bin = new CatalogRecycleBin();
1299-
bin.readFields(in);
1300-
return bin;
13011359
}
13021360

13031361
@Override
@@ -1365,12 +1423,12 @@ private void updateDbInfoForLowerVersion() {
13651423
}
13661424

13671425
public class RecycleDatabaseInfo {
1368-
@SerializedName("db")
13691426
private Database db;
1370-
@SerializedName("tns")
13711427
private Set<String> tableNames;
1372-
@SerializedName("tis")
13731428
private Set<Long> tableIds;
1429+
// for compatibility in the future
1430+
@SerializedName("u")
1431+
private String unused;
13741432

13751433
public RecycleDatabaseInfo() {
13761434
tableNames = Sets.newHashSet();
@@ -1399,6 +1457,19 @@ public Set<Long> setTableIds(Set<Long> tableIds) {
13991457
return this.tableIds = tableIds;
14001458
}
14011459

1460+
public void write(DataOutput out) throws IOException {
1461+
db.write(out);
1462+
out.writeInt(tableNames.size());
1463+
for (String tableName : tableNames) {
1464+
Text.writeString(out, tableName);
1465+
}
1466+
out.writeInt(tableIds.size());
1467+
for (Long tableId : tableIds) {
1468+
out.writeLong(tableId);
1469+
}
1470+
Text.writeString(out, GsonUtils.GSON.toJson(this));
1471+
}
1472+
14021473
public void readFields(DataInput in) throws IOException {
14031474
db = Database.read(in);
14041475

@@ -1414,6 +1485,9 @@ public void readFields(DataInput in) throws IOException {
14141485
tableIds.add(tableId);
14151486
}
14161487
}
1488+
if (Env.getCurrentEnvJournalVersion() >= FeMetaVersion.VERSION_139) {
1489+
GsonUtils.GSON.fromJson(Text.readString(in), RecycleDatabaseInfo.class);
1490+
}
14171491
}
14181492
}
14191493

@@ -1440,6 +1514,14 @@ public Table getTable() {
14401514
return table;
14411515
}
14421516

1517+
public void write(DataOutput out) throws IOException {
1518+
Text.writeString(out, GsonUtils.GSON.toJson(this));
1519+
}
1520+
1521+
public RecycleTableInfo read(DataInput in) throws IOException {
1522+
return GsonUtils.GSON.fromJson(Text.readString(in), RecycleTableInfo.class);
1523+
}
1524+
14431525
@Deprecated
14441526
public void readFields(DataInput in) throws IOException {
14451527
dbId = in.readLong();
@@ -1522,6 +1604,14 @@ public boolean isMutable() {
15221604
return isMutable;
15231605
}
15241606

1607+
public void write(DataOutput out) throws IOException {
1608+
Text.writeString(out, GsonUtils.GSON.toJson(this));
1609+
}
1610+
1611+
public RecyclePartitionInfo read(DataInput in) throws IOException {
1612+
return GsonUtils.GSON.fromJson(Text.readString(in), RecyclePartitionInfo.class);
1613+
}
1614+
15251615
public void readFields(DataInput in) throws IOException {
15261616
dbId = in.readLong();
15271617
tableId = in.readLong();

0 commit comments

Comments
 (0)