Skip to content

Commit

Permalink
Save old partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
w41ter committed Oct 9, 2024
1 parent d3e7a5f commit 4ac50a3
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3455,7 +3455,7 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti
}

// replace
truncateTableInternal(olapTable, newPartitions, truncateEntireTable);
List<Partition> oldPartitions = truncateTableInternal(olapTable, newPartitions, truncateEntireTable);

// write edit log
TruncateTableInfo info =
Expand Down Expand Up @@ -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<Partition> newPartitions, boolean isEntireTable) {
private List<Partition> truncateTableInternal(OlapTable olapTable, List<Partition> newPartitions, boolean isEntireTable) {
// 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);
oldPartitions.add(oldPartition);
// save old tablets to be removed
for (MaterializedIndex index : oldPartition.getMaterializedIndices(IndexExtState.ALL)) {
index.getTablets().forEach(t -> {
Expand All @@ -3505,6 +3507,7 @@ private void truncateTableInternal(OlapTable olapTable, List<Partition> newParti
for (Long tabletId : oldTabletIds) {
Env.getCurrentInvertedIndex().deleteTablet(tabletId);
}
return oldPartitions;
}

public void replayTruncateTable(TruncateTableInfo info) throws MetaNotFoundException {
Expand Down

0 comments on commit 4ac50a3

Please sign in to comment.