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 193af6ff84f07a..66577be99dde48 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 @@ -3455,7 +3455,7 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti } // replace - truncateTableInternal(olapTable, newPartitions, truncateEntireTable); + List oldPartitions = truncateTableInternal(olapTable, newPartitions, truncateEntireTable); // write edit log TruncateTableInfo info = @@ -3483,11 +3483,13 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti LOG.info("finished to truncate table {}, partitions: {}", tblRef.getName().toSql(), tblRef.getPartitionNames()); } - private void truncateTableInternal(OlapTable olapTable, List newPartitions, boolean isEntireTable) { + private List truncateTableInternal(OlapTable olapTable, List newPartitions, boolean isEntireTable) { // use new partitions to replace the old ones. + List oldPartitions = Lists.newArrayList(); Set oldTabletIds = Sets.newHashSet(); for (Partition newPartition : newPartitions) { Partition oldPartition = olapTable.replacePartition(newPartition); + oldPartitions.add(oldPartition); // save old tablets to be removed for (MaterializedIndex index : oldPartition.getMaterializedIndices(IndexExtState.ALL)) { index.getTablets().forEach(t -> { @@ -3505,6 +3507,7 @@ private void truncateTableInternal(OlapTable olapTable, List newParti for (Long tabletId : oldTabletIds) { Env.getCurrentInvertedIndex().deleteTablet(tabletId); } + return oldPartitions; } public void replayTruncateTable(TruncateTableInfo info) throws MetaNotFoundException {