Vallishp commented on code in PR #43107: URL: https://github.com/apache/doris/pull/43107#discussion_r1835953847
########## fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java: ########## @@ -3729,76 +3732,51 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti } private List<Partition> truncateTableInternal(OlapTable olapTable, List<Partition> newPartitions, - boolean isEntireTable) { + boolean isEntireTable, Map<Long, RecyclePartitionParam> recyclePartitionParamMap, boolean isforceDrop) { // use new partitions to replace the old ones. List<Partition> oldPartitions = Lists.newArrayList(); - Set<Long> oldTabletIds = Sets.newHashSet(); for (Partition newPartition : newPartitions) { - Partition oldPartition = olapTable.replacePartition(newPartition); + RecyclePartitionParam recyclePartitionParam = new RecyclePartitionParam(); + Partition oldPartition = olapTable.replacePartition(newPartition, recyclePartitionParam); oldPartitions.add(oldPartition); - // save old tablets to be removed - for (MaterializedIndex index : oldPartition.getMaterializedIndices(IndexExtState.ALL)) { - index.getTablets().forEach(t -> { - oldTabletIds.add(t.getId()); - }); - } + recyclePartitionParamMap.put(oldPartition.getId(), recyclePartitionParam); } if (isEntireTable) { Set<Long> oldPartitionsIds = oldPartitions.stream().map(Partition::getId).collect(Collectors.toSet()); for (Partition partition : olapTable.getAllTempPartitions()) { if (!oldPartitionsIds.contains(partition.getId())) { + RecyclePartitionParam recyclePartitionParam = new RecyclePartitionParam(); + olapTable.fillInfo(partition, recyclePartitionParam); oldPartitions.add(partition); + recyclePartitionParamMap.put(partition.getId(), recyclePartitionParam); + // clear temp partition from memory. + // tablet may be moved to recycle bin or deleted inside + // dropPartitionForTruncate function. + olapTable.dropTempPartition(partition.getName(), false); } } - // drop all temp partitions - olapTable.dropAllTempPartitions(); } - // remove the tablets in old partitions - for (Long tabletId : oldTabletIds) { - Env.getCurrentInvertedIndex().deleteTablet(tabletId); + for (Map.Entry<Long, RecyclePartitionParam> pair : recyclePartitionParamMap.entrySet()) { + olapTable.dropPartitionForTruncate(olapTable.getDatabase().getId(), isforceDrop, pair.getValue()); } return oldPartitions; } public void replayTruncateTable(TruncateTableInfo info) throws MetaNotFoundException { - List<Partition> oldPartitions = Lists.newArrayList(); + boolean isForceDrop = info.getForce(); Database db = (Database) getDbOrMetaException(info.getDbId()); OlapTable olapTable = (OlapTable) db.getTableOrMetaException(info.getTblId(), TableType.OLAP); olapTable.writeLock(); try { - truncateTableInternal(olapTable, info.getPartitions(), info.isEntireTable()); - - // add tablet to inverted index - TabletInvertedIndex invertedIndex = Env.getCurrentInvertedIndex(); Review Comment: > this code is to add tablets meta of the new partitions to TabletInvertIndex. why delete this code Thanks. its adding the tabletInvertIndex for info.getPartitions() , which is old partitions. i think now it is not necessary to added. i have tested like, truncate table, restart FE , and check table content and recover table from recycle bin. Any thing extra need to test? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org