RewriteDataFiles (bin-pack) re-selects the same files on every run when files are 50-75% of target and group total is ~110-150% of target

未关闭
#19,142 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@suhyeon729 已经在做这个了。

开始于 2026年11月27日。

  • #19163 来自 @suhyeon729 —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
22/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java

调研方向

The loop comes from the group selection in the size-based rewrite planner (SizeBasedFileRewritePlanner, with its enoughContent and expectedOutputFiles logic) working with BinPackRewriteFilePlanner. Start by reading how enoughContent and expectedOutputFiles disagree for two files of 60 with target 100 and min 75, then reproduce with a unit test in the planner's test class. Done means the group is not selected when the rewrite cannot reduce the file count, while existing planner tests still pass. The maintainers have not yet chosen between the two proposed directions.

由索引模型根据 Issue 内容生成。

描述

Apache Iceberg version

main (development). Same symptom as #6669; I only verified the logic by reading the current main source.

Query engine

Any engine using BinPackRewriteFilePlanner / SizeBasedFileRewritePlanner (Spark, Flink)

Please describe the bug 🐞

With default options (min-file-size = 0.75 * target, max = 1.8 * target), a group of files that are each between 50% and 75% of target and whose total is roughly 110%–150% of target is selected for rewrite, but the rewrite produces the same number of files with about the same sizes. The output files are again below min-file-size-bytes, so every later run selects and rewrites them again. rewritten_data_files_count == added_data_files_count on every run and the table never converges.

This is the same symptom as #6669, which was closed by the stale bot without a fix. Here is a concrete root cause.

Root cause

Group selection and output-file-count calculation disagree.

  1. filterFiles: each file is < minFileSize, so each is selected (outsideDesiredFileSizeRange).
  2. filterFileGroups: enoughContent(group) is group.size() > 1 && inputSize(group) > targetFileSize, which is true as soon as the total exceeds target.
  3. expectedOutputFiles(inputSize) (target=100, min=75, two files of 60, total 120):
    • numFilesWithRemainder = 2, numFilesWithoutRemainder = 1
    • remainder (20) > minFileSize (75)? No.
    • avgFileSizeWithoutRemainder (120) < 1.1 * target (110)? No.
    • So it falls to the last branch and returns 2.
  4. Result: 2 files in, 2 files out, each ~60 (< min). They are selected again on the next run.

For totals of 100%–110% the remainder is distributed and the result is 1 file, so it converges. The loop happens for totals of about 110%–150%.

Reproduction (unit-level)

target=100, min=75, max=180, two tasks of length 60. planFileGroups returns one group of 2 files, and expectedOutputFiles for that group is 2.

Workaround

Set min-file-size-bytes to at most 0.5 * target so that files in 50–75% are not selected. This hides the problem and changes the compaction policy for every file.

Proposed fix

Do not select a group by enoughContent unless the rewrite can reduce the file count:

enoughContent(group) = group.size() > 1
    && inputSize(group) > targetFileSize
    && expectedOutputFiles(inputSize(group)) < group.size()

enoughInputFiles and tooMuchContent (files above max) are left unchanged. I would like to send a PR with unit tests if this direction is acceptable.

Open questions / trade-offs

  • The guard above leaves such pairs (e.g. 60+60) as two small files forever, because expectedOutputFiles refuses to merge into one file larger than 1.1 * target. An alternative is to relax that rule (merge when the average is below maxFileSize), which reduces the file count but produces files above 1.1 * target. Which direction do maintainers prefer?
  • enoughInputFiles is independent of the output count, so users with min-input-files=2 would still hit the loop. Should the same guard apply there?
  • Should the guard also apply to the position-delete rewrite planner, which shares SizeBasedFileRewritePlanner?
  • I have not verified the interaction with a different output partition spec (see #15465), where rewriting without reducing the file count may still be wanted.

Willingness to contribute

  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time
主要语言
Java
星标
9.5k
派生
3.7k
平均合并
2 天 2 小时
30 天内合并 PR
170

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/iceberg 的其他 Issue

查看 apache/iceberg 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。