[Bug] Data Evolution compaction skips contiguous small files due to size/count thresholds
Search before asking
- [x] I searched in the issues and found nothing similar.
Paimon version
2.2-SNAPSHOT; upstream master inspected at commit 9c3c5187a4bd045d31b1ed9fb0decd58e6d63e8e (2026-10-09).
The two planning classes were verified byte-for-byte against this commit, then compiled locally and exercised with synthetic file metadata. This is not a full build or an end-to-end test of that master revision.
Compute Engine
Java API / paimon-core compaction planning, JDK 17. The issue was investigated in the context of Flink batch compaction, but the reproduction below does not require a Flink cluster.
Minimal reproduce step
Use a Data Evolution table's normal-file planning path with these inputs:
- One partition, 12 normal Parquet files, each 200 MiB.
- Contiguous, non-overlapping row-ID ranges: file i has firstRowId = i * 100 and rowCount = 100.
target-file-size = 512 MB,compaction.min.file-num = 5,source.split.open-file-cost = 4 MB.- No BLOB/VECTOR files, no deletion-vector materialization, large-file splitting disabled.
A minimal metadata-only reproduction can be added to the existing CompactCandidateRangeCollectorTest (its current imports already cover this method):
@Test
void testContiguousFilesExceedTargetBelowMinFileCount() {
long mib = 1024L * 1024L;
CompactCandidateRangeCollector collector =
new CompactCandidateRangeCollector(
12, 512 * mib, 1024 * mib, 4 * mib, 5, Long.MAX_VALUE);
for (int i = 0; i < 12; i++) {
collector.add(0, NORMAL_FILE, i * 100L, 100L, 200 * mib);
}
List<String> ranges = new ArrayList<>();
collector.finish((start, end, count) -> ranges.add(start + "-" + end + ":" + count));
assertThat(ranges).isNotEmpty(); // Fails: ranges is empty.
}
Run the test from the repository root:
mvn -pl paimon-core -am -Dtest=CompactCandidateRangeCollectorTest \
-Dsurefire.failIfNoSpecifiedTests=false test
A separate synthetic-metadata harness also called CompactPlanner.compactPlan directly, bypassing the candidate collector, and then via the collector-selected ranges:
| Input | Target / min files | Candidate ranges | Direct planner tasks | Tasks after candidate filtering |
|---|---|---|---|---|
| 12 x 200 MiB | 512 MiB / 5 | 0 | 0 | 0 |
| 12 x 200 MiB | 512 MiB / 2 | 4 | 4 | 4 |
| 12 x 200 MiB | 1024 MiB / 5 | 2 | 2 | 2 |
| 10 x 10 MiB | 512 MiB / 5 | 1 | 1 | 1 |
| 5 x 128 MiB | 512 MiB / 5 | 1 | 1 | 1 |
MiB means 1024 * 1024 bytes. These results test selection/planning only; no Parquet files are read or rewritten.
What doesn't meet your expectations?
Expected: compaction should be able to make progress on these contiguous normal files. Accumulating enough bytes for compaction should not repeatedly discard the group before it can satisfy the file-count condition.
Actual: every three files reach 600 MiB, exceeding the 512 MiB target. The group is flushed/drained, but rejected because it contains only 3 files (< 5). It is then cleared instead of carried forward. This repeats four times, so all 12 files produce zero candidates and zero tasks. Adding more files of the same size does not resolve this pattern.
This can make a compaction invocation finish without merging any of these files. There is no exception in the reproduction.
Anything else?
Both selection stages contain this interaction:
CompactCandidateRangeCollectorflushes the bin when its normal weight exceeds the target.CandidateBin.emitstill requires the minimum normal-file count.CompactPlannerdrains on the size threshold;triggerTaskthen applies the file-count check.
Fixing only the final planner would leave the candidate prefilter blocking these files. One possible approach is to let a bin with multiple normal files trigger on accumulated size as well as file count, while retaining partition/row-ID boundaries and avoiding unnecessary single-file rewrites.
The large-file splitting support in #9709 does not cover this case: each 200 MiB file is smaller than the 512 MiB target. Enabling it with ratio 1 or 2 still produced zero candidates/tasks in the same harness.
This report concerns core Data Evolution file selection, separately from the compact_database routing issue #10102.
Are you willing to submit a PR?
- [x] I'm willing to submit a PR!
@tzphh, are you planning to continue #10459, or was it set aside for a specific reason? I saw it was closed as WIP while this issue remains open. I can check the current collector/planner against the 12 × 200 MiB case and a small Parquet compaction round trip, but want to avoid duplicating a newer branch or repeating an approach that was ruled out.
AI-generated comment.
@hutiefang76 Thanks for checking! I closed #10459 while it was still a WIP, and there’s no follow-up PR linked to this issue. The draft allowed groups of multiple normal files to trigger compaction by size in both candidate selection and task planning. It passed the focused tests on the old branch, including a two-file Parquet compaction and read-back test. If you’re still interested, could you check whether the 12 × 200 MiB case still reproduces on current master and share what you find here? That would help us agree on the next step before opening another PR.
I ran CompactCandidateRangeCollector at 7a30ef580e with the 12 × 200 MiB metadata layout from the report (512 MiB target, 4 MiB open cost). It selected no ranges with compaction.min.file-num=5. Changing only that setting to 2 produced four ranges of three files each. The collector source is identical on current master (ee544b74f1).
I also wrote 12 batches to a local Data Evolution table and read back all 12,000 row IDs. Its $files metadata showed 12 Parquet files of 210,014 bytes each with contiguous row IDs. Feeding those values to the collector with a 512 KiB target and a 4 KiB open cost again gave zero ranges at a minimum of five files and four ranges at a minimum of two. Both checks stop at candidate selection, before any Spark or Flink compaction job rewrites files.
@tzphh, the original case still reproduces on current master, 6a9e258775f0e43431c48b8fb22469b1b02c8ca5. I independently ran both CompactCandidateRangeCollector and CompactPlanner against that revision on JDK 17, using contiguous normal-file metadata and a 4 MiB open-file cost. This agrees with @skyyyy955's collector result and confirms that the planner also blocks the original case.
| Input | Target / minimum files | Candidate ranges | Direct planner tasks | Tasks after candidate filtering |
|---|---|---|---|---|
| 12 × 200 MiB | 512 MiB / 5 | 0 | 0 | 0 |
| 12 × 200 MiB | 512 MiB / 2 | 4 | 4 | 4 |
| 12 × 200 MiB | 1024 MiB / 5 | 2 | 2 | 2 |
| 10 × 10 MiB | 512 MiB / 5 | 1 | 1 | 1 |
| 5 × 128 MiB | 512 MiB / 5 | 1 | 1 | 1 |
With minimum 2, each task contains three files; with the 1024 MiB target and minimum 5, each contains six. These are synthetic metadata checks of selection and planning. I did not read or rewrite Parquet files in this run.
Your two-stage approach still appears relevant. Before another implementation, would you prefer to resume #10459 yourself, or have me carry that approach forward after we agree on the behavior and regression cases?
AI-assisted reproduction and comment (OpenAI Codex and DeepSeek).
@hutiefang76 @tzphh Thanks for the additional reproduction. I also have a local adaptation of #10459, including integration with the current incremental and VECTOR compaction planning. I have not opened a PR yet.
On master, I verified the original metadata case and a small physical Parquet round trip: without the fix, 12 files produced no tasks at minimum 5; with the fix, four tasks compacted them into four files, preserving row IDs and payloads. Both incremental modes passed.
If that works for you, I’d be happy to open a draft PR based on the original approach. You’re both welcome to help review it and contribute to the implementation.
@lilei1128, that works for me. Please link the draft here when ready; I can review the collector/planner changes and check the regression cases. I'll leave implementation with you and @tzphh to avoid duplicating your adaptation.
AI-assisted comment (OpenAI Codex).
@lilei1128, that works for me. Please link the draft here when ready; I can review the collector/planner changes and check the regression cases. I'll leave implementation with you and @tzphh to avoid duplicating your adaptation.
AI-assisted comment (OpenAI Codex).
The draft PR link: https://github.com/apache/paimon/pull/11414