Skip to content

[flink] Support table batching for orphan file cleanup - #9247

Open
zhuyaogai wants to merge 4 commits into
apache:masterfrom
zhuyaogai:issue-7155
Open

[flink] Support table batching for orphan file cleanup#9247
zhuyaogai wants to merge 4 commits into
apache:masterfrom
zhuyaogai:issue-7155

Conversation

@zhuyaogai

Copy link
Copy Markdown
Contributor

Purpose

Fixes #7155.

Previously, orphan file cleanup for all matched tables was unioned into a single Flink batch job. In batch mode, Flink does not put all job vertices into the same SlotSharingGroup by default, so tasks belonging to different groups cannot reuse the same slots.

As each table creates its own cleanup pipeline, running many tables in one job can require a large number of slots. Therefore, the actual resource usage may be much higher than the configured cleanup parallelism and can exhaust cluster resources.

This change processes tables in sequential batches and introduces a table_batch_size option, which defaults to 10. Only a limited number of table cleanup pipelines are included in each batch, bounding the slot resources required by a single job. Batch progress and elapsed time are also logged.

Tests

Added integration test coverage for database-level orphan file cleanup with a configured batch size.

<td>
-- Use named argument<br/>
CALL [catalog.]sys.remove_orphan_files(`table` => 'identifier', older_than => 'olderThan', dry_run => 'dryRun', mode => 'mode') <br/><br/>
CALL [catalog.]sys.remove_orphan_files(`table` => 'identifier', older_than => 'olderThan', dry_run => 'dryRun', mode => 'mode', table_batch_size => 'tableBatchSize') <br/><br/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe max_table_number?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This parameter controls the number of tables included in each batch (each submitted Flink job), rather than limiting the total number of tables to clean.

For example, 23 tables with a value of 10 will be processed in three batches: 10, 10, and 3. All 23 tables will still be cleaned.

max_table_number might be interpreted as a limit on the total number of tables to process. I think table_batch_size better reflects the current semantics. Would max_tables_per_batch be clearer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @JingsongLi, could you elaborate a bit on what you have in mind with max_table_number?

The current design submits all matched tables in sequential Flink jobs, and this parameter controls how many tables are included in each job.

I'm not sure whether your suggestion is only about the parameter name, or whether you have different semantics or an alternative design in mind. I'd like to understand your intention before changing the API.

result = result.union(clean);
DataStream<CleanOrphanFilesResult> result = null;
for (DataStream<CleanOrphanFilesResult> clean : orphanFilesCleans) {
result = result == null ? clean : result.union(clean);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't quite understand the execution process here—is it concurrent execution? Why is it described in terms of batches?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, tables within one batch are added to the same Flink JobGraph through union, so their cleanup pipelines may execute concurrently.

Different batches are executed sequentially. sum(result) calls executeAndCollect() and consumes the iterator until the current Flink job finishes. Only then does the outer loop build and submit the next job.

Therefore, the parameter limits the number of tables included in each submitted Flink job, rather than directly limiting task concurrency. Does this execution model match what you had in mind, or would you prefer a different way to control resource usage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Parallelism cannot be controlled in remove_orphan_files

2 participants