Skip to content

[core] Compact leftover small files in batch append compaction - #11179

Open
dragonknightk wants to merge 1 commit into
apache:masterfrom
dragonknightk:append-batch-compact-leftover-files
Open

dragonknightk wants to merge 1 commit into
apache:masterfrom
dragonknightk:append-batch-compact-leftover-files

Conversation

@dragonknightk

Copy link
Copy Markdown

Purpose

Fixes #5130

In batch mode, AppendCompactCoordinator now compacts the small files that packing leaves in a partition when there are at least 2 of them. Before this change, such files were compacted only after COMPACT_AGE further planning rounds without new files in the partition. A batch compaction stops after planning its last scanned files, so the files left over in that plan stayed uncompacted.

  • The coordinator already knows the mode from its isStreaming constructor argument, which the Flink compact source, the Flink multi-table compact scan and the Spark compact procedure pass. No caller or option changes.
  • The leftover files form one extra task per partition, even when they are fewer than compaction.min.file-num. A single file is not compacted, because rewriting it alone does not reduce the file count.
  • In batch mode this applies to every plan. When the Flink batch source scans more files than compaction.file-num-limit, it plans once per chunk, so a partition can get one leftover task per chunk.
  • Streaming is unchanged: leftover files still wait for COMPACT_AGE.

Tests

  • With deletion vectors enabled and compaction.min.file-num = 3, 14 files of a third of the target size pack into 2 tasks and leave 2 files. A streaming coordinator plans the 2 tasks and keeps the 2 files. A batch coordinator plans a third task with the 2 files, so the tasks cover all 14 files and nothing is kept.
  • On a table without deletion vectors, a batch compaction of 2 committed files below compaction.min.file-num produces 1 file with both rows, while a streaming coordinator plans nothing.
  • A batch coordinator does not compact a single file.
  • The first two scenarios fail on the code before this change.

AI Disclosure

Human-led contribution. Grok Bot, working for dragonknightk, assisted with this change, including the code, tests, and description. All submitted content was reviewed by a human before submission. (๑•̀ㅂ•́)و✧

### Purpose

Closes issue 5130

In batch mode, `AppendCompactCoordinator` now compacts the small files that packing leaves in a partition when there are at least 2 of them. Before this change, such files were compacted only after `COMPACT_AGE` further planning rounds without new files in the partition. A batch compaction stops after planning its last scanned files, so the files left over in that plan stayed uncompacted.

- The coordinator already knows the mode from its `isStreaming` constructor argument, which the Flink compact source, the Flink multi-table compact scan and the Spark compact procedure pass. No caller or option changes.
- The leftover files form one extra task per partition, even when they are fewer than `compaction.min.file-num`. A single file is not compacted, because rewriting it alone does not reduce the file count.
- In batch mode this applies to every plan. When the Flink batch source scans more files than `compaction.file-num-limit`, it plans once per chunk, so a partition can get one leftover task per chunk.
- Streaming is unchanged: leftover files still wait for `COMPACT_AGE`.

### Tests

- With deletion vectors enabled and `compaction.min.file-num = 3`, 14 files of a third of the target size pack into 2 tasks and leave 2 files. A streaming coordinator plans the 2 tasks and keeps the 2 files. A batch coordinator plans a third task with the 2 files, so the tasks cover all 14 files and nothing is kept.
- On a table without deletion vectors, a batch compaction of 2 committed files below `compaction.min.file-num` produces 1 file with both rows, while a streaming coordinator plans nothing.
- A batch coordinator does not compact a single file.
- The first two scenarios fail on the code before this change.

## AI Disclosure

Human-led contribution. Grok Bot, working for dragonknightk, assisted with this change, including the code, tests, and description. All submitted content was reviewed by a human before submission.

Signed-off-by: KK <37928252+dragonknightk@users.noreply.github.com>
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] The UnawareAppendTableCompactionCoordinator may leave some small files can not be compacted

1 participant