diff --git a/fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java b/fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java index ecdc1b2ade7e89..079a3c6527af79 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java +++ b/fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java @@ -318,7 +318,7 @@ public void addTruncateTable(TruncateTableInfo info, long commitSeq) { TruncateTableRecord record = new TruncateTableRecord(info); String data = record.toJson(); - addBinlog(dbId, tableIds, commitSeq, timestamp, type, data, false, info); + addBinlog(dbId, tableIds, commitSeq, timestamp, type, data, false, record); } public void addTableRename(TableInfo info, long commitSeq) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/binlog/DBBinlog.java b/fe/fe-core/src/main/java/org/apache/doris/binlog/DBBinlog.java index 8469bdcc7d1200..86cf8085a42b10 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/binlog/DBBinlog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/binlog/DBBinlog.java @@ -141,6 +141,13 @@ public void recoverBinlog(TBinlog binlog, boolean dbBinlogEnable) { } } } + } else if (binlog.getType() == TBinlogType.TRUNCATE_TABLE) { + TruncateTableRecord record = TruncateTableRecord.fromJson(binlog.data); + if (record != null) { + for (long partitionId : record.getOldPartitionIds()) { + droppedPartitions.add(Pair.of(partitionId, binlog.getCommitSeq())); + } + } } if (tableIds == null) { @@ -214,6 +221,11 @@ public void addBinlog(TBinlog binlog, Object raw) { } } } + } else if (binlog.getType() == TBinlogType.TRUNCATE_TABLE && raw instanceof TruncateTableRecord) { + TruncateTableRecord truncateTableRecord = (TruncateTableRecord) raw; + for (long partitionId : truncateTableRecord.getOldPartitionIds()) { + droppedPartitions.add(Pair.of(partitionId, binlog.getCommitSeq())); + } } switch (binlog.getType()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/binlog/TruncateTableRecord.java b/fe/fe-core/src/main/java/org/apache/doris/binlog/TruncateTableRecord.java index 0c43ce781cd5e3..cb5b5641889a69 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/binlog/TruncateTableRecord.java +++ b/fe/fe-core/src/main/java/org/apache/doris/binlog/TruncateTableRecord.java @@ -22,6 +22,11 @@ import com.google.gson.annotations.SerializedName; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + public class TruncateTableRecord { @SerializedName(value = "dbId") private long dbId; @@ -35,6 +40,8 @@ public class TruncateTableRecord { private boolean isEntireTable = false; @SerializedName(value = "rawSql") private String rawSql = ""; + @SerializedName(value = "op") + private Map oldPartitions = new HashMap<>(); public TruncateTableRecord(TruncateTableInfo info) { this.dbId = info.getDbId(); @@ -43,9 +50,18 @@ public TruncateTableRecord(TruncateTableInfo info) { this.table = info.getTable(); this.isEntireTable = info.isEntireTable(); this.rawSql = info.getRawSql(); + this.oldPartitions = info.getOldPartitions(); + } + + public Collection getOldPartitionIds() { + return oldPartitions == null ? new ArrayList<>() : oldPartitions.keySet(); } public String toJson() { return GsonUtils.GSON.toJson(this); } + + public static TruncateTableRecord fromJson(String json) { + return GsonUtils.GSON.fromJson(json, TruncateTableRecord.class); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 9f7d27669d8d74..d2176de0100753 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -3698,8 +3698,7 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti // write edit log TruncateTableInfo info = new TruncateTableInfo(db.getId(), db.getFullName(), olapTable.getId(), olapTable.getName(), - newPartitions, - truncateEntireTable, truncateTableStmt.toSqlWithoutTable()); + newPartitions, truncateEntireTable, truncateTableStmt.toSqlWithoutTable(), oldPartitions); Env.getCurrentEnv().getEditLog().logTruncateTable(info); } catch (DdlException e) { failedCleanCallback.run(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/TruncateTableInfo.java b/fe/fe-core/src/main/java/org/apache/doris/persist/TruncateTableInfo.java index a9a91f28839c1a..b252b2a38233f7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/persist/TruncateTableInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/TruncateTableInfo.java @@ -28,7 +28,9 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class TruncateTableInfo implements Writable { @SerializedName(value = "dbId") @@ -45,13 +47,15 @@ public class TruncateTableInfo implements Writable { private boolean isEntireTable = false; @SerializedName(value = "rawSql") private String rawSql = ""; + @SerializedName(value = "op") + private Map oldPartitions = new HashMap<>(); public TruncateTableInfo() { } public TruncateTableInfo(long dbId, String db, long tblId, String table, List partitions, - boolean isEntireTable, String rawSql) { + boolean isEntireTable, String rawSql, List oldPartitions) { this.dbId = dbId; this.db = db; this.tblId = tblId; @@ -59,6 +63,9 @@ public TruncateTableInfo(long dbId, String db, long tblId, String table, List getPartitions() { return partitions; } + public Map getOldPartitions() { + return oldPartitions == null ? new HashMap<>() : oldPartitions; + } + public boolean isEntireTable() { return isEntireTable; }