Skip to content

Commit 3304abe

Browse files
authored
[core] Only remove tag metadata when deleting tags (#10823)
1 parent ec1c37b commit 3304abe

32 files changed

Lines changed: 154 additions & 424 deletions

‎docs/docs/concepts/spec/manifest.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ skip manifests before opening them.
6161
| `_EXTRA_FILES` | ARRAY of STRING, nullable | Names of additional files in the manifest directory; defaults to null. |
6262

6363
Each extra file belongs exclusively to one manifest. It is retained and cleaned up together with
64-
that manifest during snapshot, tag, or changelog deletion.
64+
that manifest during snapshot or changelog expiration and orphan file cleanup. Tag deletion retains
65+
both the manifest and its extra files for later orphan file cleanup.
6566

6667
### Manifest Sidecar
6768

‎docs/docs/maintenance/manage-snapshots.mdx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,10 @@ changelog producer.
398398
399399
## Remove Orphan Files
400400
401-
Paimon files are deleted physically only when expiring snapshots. However, it is possible that some unexpected errors occurred
402-
when deleting files, so that there may exist files that are not used by Paimon snapshots (so-called "orphan files"). You can
403-
submit a `remove_orphan_files` job to clean them:
401+
Snapshot expiration physically deletes unused files. Deleting a tag only removes its tag file,
402+
and unexpected errors during file deletion can also leave unused files behind. Files that are no longer
403+
referenced by any snapshot, tag, or changelog are called "orphan files". You can submit a `remove_orphan_files` job
404+
to clean them:
404405
405406
<Tabs groupId="remove-orphan-files">
406407

‎docs/docs/maintenance/manage-tags.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ CALL sys.create_tag(table => 'test.t', tag => 'test_tag');
177177
178178
You can delete a tag by its name.
179179
180+
Deleting a tag only removes the tag file. Its manifest, index, and data files are retained.
181+
Use [Remove Orphan Files](./manage-snapshots#remove-orphan-files) to reclaim files that are no longer
182+
referenced by any snapshot, tag, or changelog, subject to the orphan file cleanup retention period.
183+
180184
<Tabs groupId="delete-tag">
181185
182186
<TabItem value="flink-sql" label="Flink SQL">

‎paimon-core/src/main/java/org/apache/paimon/AbstractFileStore.java‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.apache.paimon.operation.NormalPartitionExpire;
4747
import org.apache.paimon.operation.PartitionExpire;
4848
import org.apache.paimon.operation.SnapshotDeletion;
49-
import org.apache.paimon.operation.TagDeletion;
5049
import org.apache.paimon.operation.commit.CommitRollback;
5150
import org.apache.paimon.operation.commit.ConflictDetection;
5251
import org.apache.paimon.partition.PartitionExpireStrategy;
@@ -367,20 +366,6 @@ public TagManager newTagManager() {
367366
return new TagManager(fileIO, options.path(), options.branch(), options);
368367
}
369368

370-
@Override
371-
public TagDeletion newTagDeletion() {
372-
return new TagDeletion(
373-
fileIO,
374-
pathFactory(),
375-
manifestFileFactory().create(),
376-
manifestListFactory().create(),
377-
newIndexFileHandler(),
378-
newStatsFileHandler(),
379-
options.cleanEmptyDirectories(),
380-
options.fileOperationThreadNum(),
381-
options.scanManifestParallelism());
382-
}
383-
384369
public abstract Comparator<InternalRow> newKeyComparator();
385370

386371
@Override
@@ -573,11 +558,7 @@ private PartitionModification newPartitionModificationForBranch(String branchNam
573558
@Override
574559
public TagAutoManager newTagAutoManager(FileStoreTable table) {
575560
return TagAutoManager.create(
576-
options,
577-
snapshotManager(),
578-
newTagManager(),
579-
newTagDeletion(),
580-
createTagCallbacks(table));
561+
options, snapshotManager(), newTagManager(), createTagCallbacks(table));
581562
}
582563

583564
@Override

‎paimon-core/src/main/java/org/apache/paimon/FileStore.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.paimon.operation.PartitionExpire;
3131
import org.apache.paimon.operation.SnapshotDeletion;
3232
import org.apache.paimon.operation.SplitRead;
33-
import org.apache.paimon.operation.TagDeletion;
3433
import org.apache.paimon.partition.PartitionExpireStrategy;
3534
import org.apache.paimon.service.ServiceManager;
3635
import org.apache.paimon.stats.StatsFileHandler;
@@ -100,8 +99,6 @@ public interface FileStore<T> {
10099

101100
TagManager newTagManager();
102101

103-
TagDeletion newTagDeletion();
104-
105102
@Nullable
106103
PartitionExpire newPartitionExpire(String commitUser, FileStoreTable table);
107104

‎paimon-core/src/main/java/org/apache/paimon/operation/TagDeletion.java‎

Lines changed: 0 additions & 124 deletions
This file was deleted.

‎paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,7 @@ public void replaceTag(
769769

770770
@Override
771771
public void deleteTag(String tagName) {
772-
tagManager()
773-
.deleteTag(
774-
tagName,
775-
store().newTagDeletion(),
776-
snapshotManager(),
777-
store().createTagCallbacks(this));
772+
tagManager().deleteTag(tagName, store().createTagCallbacks(this));
778773
}
779774

780775
@Override

‎paimon-core/src/main/java/org/apache/paimon/table/Table.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ default String uuid() {
143143
@Experimental
144144
void replaceTag(String tagName, @Nullable Long fromSnapshotId, @Nullable Duration timeRetained);
145145

146-
/** Delete a tag by name. */
146+
/** Delete a tag by name, leaving its referenced files to orphan file cleanup. */
147147
@Experimental
148148
void deleteTag(String tagName);
149149

‎paimon-core/src/main/java/org/apache/paimon/tag/BatchReadTagCreator.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ public String createReadTag(long snapshotId) {
7878
public void deleteReadTag(String tagName) {
7979
try {
8080
if (tagManager.tagExists(tagName)) {
81-
// Directly delete the tag metadata file instead of using TagManager.deleteTag(),
82-
// which would also scan and delete unreferenced data files — too heavyweight for a
83-
// read-path cleanup. Any orphan data files left behind will be reclaimed by
84-
// OrphanFilesClean.
81+
// Read protection tags do not need deletion callbacks. Any orphan files left
82+
// behind will be reclaimed by OrphanFilesClean.
8583
snapshotManager.fileIO().deleteQuietly(tagManager.tagPath(tagName));
8684
LOG.info("Deleted batch read protection tag '{}'.", tagName);
8785
}

‎paimon-core/src/main/java/org/apache/paimon/tag/TagAutoCreation.java‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.paimon.CoreOptions;
2222
import org.apache.paimon.Snapshot;
2323
import org.apache.paimon.annotation.VisibleForTesting;
24-
import org.apache.paimon.operation.TagDeletion;
2524
import org.apache.paimon.table.sink.TagCallback;
2625
import org.apache.paimon.tag.TagTimeExtractor.ProcessTimeExtractor;
2726
import org.apache.paimon.tag.TagTimeExtractor.WatermarkExtractor;
@@ -53,7 +52,6 @@ public class TagAutoCreation {
5352

5453
private final SnapshotManager snapshotManager;
5554
private final TagManager tagManager;
56-
private final TagDeletion tagDeletion;
5755
private final TagTimeExtractor timeExtractor;
5856
private final TagPeriodHandler periodHandler;
5957
private final Duration delay;
@@ -70,7 +68,6 @@ public class TagAutoCreation {
7068
private TagAutoCreation(
7169
SnapshotManager snapshotManager,
7270
TagManager tagManager,
73-
TagDeletion tagDeletion,
7471
TagTimeExtractor timeExtractor,
7572
TagPeriodHandler periodHandler,
7673
Duration delay,
@@ -82,7 +79,6 @@ private TagAutoCreation(
8279
ZoneId sinkProcessTimeZone) {
8380
this.snapshotManager = snapshotManager;
8481
this.tagManager = tagManager;
85-
this.tagDeletion = tagDeletion;
8682
this.timeExtractor = timeExtractor;
8783
this.periodHandler = periodHandler;
8884
this.delay = delay;
@@ -196,7 +192,7 @@ private void tryToCreateTags(Snapshot snapshot) {
196192
"Delete tag {}, because the number of auto-created tags reached numRetainedMax of {}.",
197193
toDeleteTag,
198194
numRetainedMax);
199-
tagManager.deleteTag(toDeleteTag, tagDeletion, snapshotManager, callbacks);
195+
tagManager.deleteTag(toDeleteTag, callbacks);
200196
i++;
201197
if (i == toDelete) {
202198
break;
@@ -225,7 +221,6 @@ public static TagAutoCreation create(
225221
CoreOptions options,
226222
SnapshotManager snapshotManager,
227223
TagManager tagManager,
228-
TagDeletion tagDeletion,
229224
List<TagCallback> callbacks) {
230225
TagTimeExtractor extractor = TagTimeExtractor.createForAutoTag(options);
231226
if (extractor == null) {
@@ -234,7 +229,6 @@ public static TagAutoCreation create(
234229
return new TagAutoCreation(
235230
snapshotManager,
236231
tagManager,
237-
tagDeletion,
238232
extractor,
239233
TagPeriodHandler.create(options),
240234
options.tagCreationDelay(),

0 commit comments

Comments
 (0)