Skip to content

Flink: Add RemoveDanglingDeleteFiles to maintenance API#16171

Open
sachinnn99 wants to merge 1 commit intoapache:mainfrom
sachinnn99:flink-remove-dangling-deletes
Open

Flink: Add RemoveDanglingDeleteFiles to maintenance API#16171
sachinnn99 wants to merge 1 commit intoapache:mainfrom
sachinnn99:flink-remove-dangling-deletes

Conversation

@sachinnn99
Copy link
Copy Markdown
Contributor

@sachinnn99 sachinnn99 commented Apr 30, 2026

Summary

Fixes #16138.

The RemoveDanglingDeleteFiles action currently exists only for Spark. Flink users have no equivalent, causing equality delete files to accumulate indefinitely in V2 tables managed by the Flink maintenance pipeline.

This PR adds RemoveDanglingDeleteFiles support to the Flink maintenance API across all three Flink versions (v1.20, v2.0, v2.1).

Approach:

  • Follows the ExpireSnapshots pattern (single ProcessFunction operator)
  • Mirrors RemoveDanglingDeletesSparkAction's two-method structure:
    • findDanglingDeletes — sequence-number-based detection using an O(partitions) minDataSeqByPartition map (position, equality, and DV deletes)
    • findDanglingDvs — reference-based detection for deletion vectors via a targeted data manifest scan with O(DV candidates) memory
  • Avoids collecting all live data file paths in memory, preventing OOM on large tables

New files (identical across all three Flink versions):

  • RemoveDanglingDeleteFiles.java — API builder extending MaintenanceTaskBuilder
  • RemoveDanglingDeleteFilesProcessor.java — Core operator with dangling detection logic
  • TestRemoveDanglingDeleteFiles.java — Tests covering partitioned deletes, equality delete edge cases, unpartitioned tables, and no-op scenarios

Test plan

  • TestRemoveDanglingDeleteFiles passes on Flink v1.20, v2.0, v2.1
  • All existing maintenance tests pass (no regressions)
  • Compilation succeeds across all Flink versions

@github-actions github-actions Bot added the flink label Apr 30, 2026
Copy link
Copy Markdown
Contributor

@Guosmilesmile Guosmilesmile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! It looks more like a standalone version that doesn’t need Flink . It can be done directly with the Java API. If the table is large, there could be a bottleneck.

@sachinnn99 sachinnn99 force-pushed the flink-remove-dangling-deletes branch from 9ad81d8 to b1cc71a Compare May 2, 2026 11:54
Copy link
Copy Markdown
Contributor Author

@sachinnn99 sachinnn99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! The single-operator approach follows the same pattern as ExpireSnapshotsProcessor. A distributed approach like DeleteOrphanFiles could be a follow-up for very large tables.

@Guosmilesmile
Copy link
Copy Markdown
Contributor

In the current implementation of this feature, there are places where DataFiles/DeleteFiles need to be read one by one. It also requires building a table-level Set and constructing partition-level minDataSeqByPartition. In large table scenarios, this will have performance issues and OOM. So I hope the Flink implementation can leverage distributed computing capabilities just like Spark does.

@sachinnn99 sachinnn99 force-pushed the flink-remove-dangling-deletes branch 2 times, most recently from 8b5ec5c to 6c8f4c2 Compare May 6, 2026 09:13
Closes apache#16138.

Add RemoveDanglingDeleteFiles support to the Flink maintenance API
across all three Flink versions (v1.20, v2.0, v2.1). The detection
algorithm mirrors Spark's RemoveDanglingDeletesSparkAction with two
independent checks: sequence-number-based dangling detection using
an O(partitions) min-seq-per-partition map, and a separate targeted
scan for deletion vectors referencing non-existent data files.
@sachinnn99 sachinnn99 force-pushed the flink-remove-dangling-deletes branch from 6c8f4c2 to f988732 Compare May 8, 2026 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flink: Add RemoveDanglingDeleteFiles support to the Flink maintenance API

2 participants