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 b9300bc058ee66..147a60d181e978 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 @@ -3814,8 +3814,10 @@ public void truncateTable(String dbName, String tableName, PartitionNamesInfo pa //replace Map recyclePartitionParamMap = new HashMap<>(); + long version = Config.isNotCloudMode() ? olapTable.getNextVersion() : 0L; + long versionTimeMs = Config.isNotCloudMode() ? System.currentTimeMillis() : 0L; oldPartitions = truncateTableInternal(olapTable, newPartitions, - truncateEntireTable, recyclePartitionParamMap, forceDrop); + truncateEntireTable, recyclePartitionParamMap, forceDrop, version, versionTimeMs); if (truncateEntireTable) { Env.getCurrentEnv().getAnalysisManager().removeTableStats(olapTable.getId()); } else { @@ -3827,7 +3829,7 @@ public void truncateTable(String dbName, String tableName, PartitionNamesInfo pa TruncateTableInfo info = new TruncateTableInfo(db.getId(), db.getFullName(), olapTable.getId(), olapTable.getName(), newPartitions, truncateEntireTable, - rawTruncateSql, oldPartitions, forceDrop, updateRecords); + rawTruncateSql, oldPartitions, forceDrop, updateRecords, version, versionTimeMs); Env.getCurrentEnv().getEditLog().logTruncateTable(info); } catch (DdlException e) { failedCleanCallback.run(); @@ -3843,7 +3845,8 @@ public void truncateTable(String dbName, String tableName, PartitionNamesInfo pa } private List truncateTableInternal(OlapTable olapTable, List newPartitions, - boolean isEntireTable, Map recyclePartitionParamMap, boolean isforceDrop) { + boolean isEntireTable, Map recyclePartitionParamMap, boolean isforceDrop, + long version, long versionTimeMs) { // use new partitions to replace the old ones. List oldPartitions = Lists.newArrayList(); for (Partition newPartition : newPartitions) { @@ -3873,9 +3876,13 @@ private List truncateTableInternal(OlapTable olapTable, List 0) { + // Persisted values make the version transition deterministic during journal replay. + olapTable.updateVisibleVersionAndTime(version, versionTimeMs); + } else { + // Preserve legacy replay and Cloud's local cache invalidation behavior. + olapTable.resetVisibleVersion(); + } return oldPartitions; } @@ -3889,7 +3896,8 @@ public void replayTruncateTable(TruncateTableInfo info) throws MetaNotFoundExcep try { Map recyclePartitionParamMap = new HashMap<>(); truncateTableInternal(olapTable, info.getPartitions(), info.isEntireTable(), - recyclePartitionParamMap, isForceDrop); + recyclePartitionParamMap, isForceDrop, + info.getVersion(), info.getVersionTimeMs()); // add tablet to inverted index TabletInvertedIndex invertedIndex = Env.getCurrentInvertedIndex(); 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 b846d1acbdc1a9..7edffceaf0be2c 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 @@ -60,6 +60,10 @@ public class TruncateTableInfo implements Writable { private Map updateRecords; @SerializedName(value = "ut") private long updateTime; + @SerializedName(value = "version") + private long version; + @SerializedName(value = "versionTime") + private long versionTimeMs; public TruncateTableInfo() { @@ -68,7 +72,7 @@ public TruncateTableInfo() { // for internal table public TruncateTableInfo(long dbId, String db, long tblId, String table, List partitions, boolean isEntireTable, String rawSql, List oldPartitions, boolean force, - Map updateRecords) { + Map updateRecords, long version, long versionTimeMs) { this.dbId = dbId; this.db = db; this.tblId = tblId; @@ -81,6 +85,8 @@ public TruncateTableInfo(long dbId, String db, long tblId, String table, List