[WIP] Core: rewrite_position_delete_files can hide a live row after its data file is re-added
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
調査の方向性
Start with RewritePositionDeletesCommitManager.java, RewritePositionDeletesGroup.java, and SparkRewritePositionDeleteRunner.java, using the linked lines as entry points. Read RewriteFiles.java's sequence-number requirements, then trace how the runner groups delete rows and how the commit manager assigns output sequence numbers. Reproduce the supplied Spark SQL case and verify that rewriting preserves the rows returned before the rewrite, including the re-added data file.
索引モデルが issue の本文から書いたものです。
説明
Apache Iceberg version
1.12.0 (latest release)
Query engine
Spark
Please describe the bug 🐞
rewrite_position_delete_files commits every delete file it writes for a group at the highest data sequence number among the group's delete files. A position delete applies to a data file only when the data file's data sequence number is less than or equal to the delete's, Scan Planning. Take a delete at 3 that names a live data file at 5, in a group that also holds a delete at 6. The rewritten delete is committed at 6 and starts to apply, since 3 < 5 ≤ 6, and the row it names disappears.
Plain Spark SQL builds such a table:
- A metadata delete removes a data file, and its v2 position delete stays live.
add_filesregisters the same file again at its old path, at a higher data sequence number.
The spec advises against this: "It is not recommended to add a deleted file back to a table", spec, a note under Deleting Files on main. Spark's add_files accepts it, though. Once the file is live again, scan planning leaves the older delete out. A rewrite should not change that: replace snapshots change files "without changing table data", Snapshots, and RewriteFiles requires the new state to be "logically equivalent to the original table state", RewriteFiles.
On Spark 3.5.10, with /tmp/wh empty and the statements below saved as rewrite.sql:
spark-sql --packages org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.12.0 \
--conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions \
--conf spark.sql.catalog.local=org.apache.iceberg.spark.SparkCatalog \
--conf spark.sql.catalog.local.type=hadoop \
--conf spark.sql.catalog.local.warehouse=file:/tmp/wh \
--conf spark.sql.defaultCatalog=local \
-f rewrite.sql
CREATE TABLE db.t (id int, grp int) USING iceberg TBLPROPERTIES (
'format-version' = '2', 'write.delete.mode' = 'merge-on-read', 'write.data.path' = 'file:/tmp/wh/a');
-- data file A, data sequence number 1
INSERT INTO db.t SELECT /*+ REPARTITION(1) */ * FROM VALUES (1, 0), (2, 0), (3, 0);
ALTER TABLE db.t SET TBLPROPERTIES ('write.data.path' = 'file:/tmp/wh/b');
-- data file B, 2
INSERT INTO db.t SELECT /*+ REPARTITION(1) */ * FROM VALUES (4, 1), (5, 1);
-- position deletes at 3, one of them for A at position 0
DELETE FROM db.t WHERE id IN (1, 4);
-- metadata delete of A at 4, which leaves A's delete file live
DELETE FROM db.t WHERE grp = 0;
-- A again, at 5
CALL system.add_files(table => 'db.t', source_table => '`parquet`.`file:/tmp/wh/a`');
-- 1, 2, 3, 5: the delete at 3 does not apply to A at 5
SELECT id FROM db.t ORDER BY id;
-- B's deletes, now at 6
DELETE FROM db.t WHERE id = 5;
-- 1, 2, 3
SELECT id FROM db.t ORDER BY id;
SELECT data_file.content, sequence_number, data_file.file_path FROM db.t.entries WHERE status != 2 ORDER BY 1, 2;
CALL system.rewrite_position_delete_files(table => 'db.t', options => map('rewrite-all', 'true'));
SELECT data_file.content, sequence_number, data_file.file_path FROM db.t.entries WHERE status != 2 ORDER BY 1, 2;
-- 2, 3
SELECT id FROM db.t ORDER BY id;
The two entries queries and the rewrite give:
0 2 file:/tmp/wh/b/00000-6-...-0-00001.parquet -- B
0 5 file:/tmp/wh/a/00000-3-...-0-00001.parquet -- A
1 3 file:/tmp/wh/b/00000-8-...-00001-deletes.parquet -- the delete for A's position 0
1 6 file:/tmp/wh/b/00000-419-...-00001-deletes.parquet -- B's deletes
2 2 2713 2713 -- rewritten 2, added 2
0 2 file:/tmp/wh/b/00000-6-...-0-00001.parquet
0 5 file:/tmp/wh/a/00000-3-...-0-00001.parquet
1 6 file:/tmp/wh/b/00000-427-...-00001-deletes.parquet
1 6 file:/tmp/wh/b/00000-427-...-00002-deletes.parquet
The file: scheme in the paths matters: add_files records it, so the delete names the re-added file only if Spark wrote the same spelling.
- Other runs: the same SQL loses row 1 on 1.10.0, and on 1.12.0 with
'format-version' = '3'set before the rewrite, where the deletion vector written for A also takes 6. - PyIceberg: in a run of the same steps through PySpark on 1.12.0, PyIceberg 0.12.0 read the same rows as Spark before and after the rewrite.
- Main: it commits rewritten deletes the same way, RewritePositionDeletesCommitManager.
Where it happens:
- The commit manager calls
rewriteFiles.addFile(file, group.maxRewrittenDataSequenceNumber())for every new delete file, RewritePositionDeletesCommitManager. - The group computes that max over its delete files, RewritePositionDeletesGroup.
- The runner keeps a delete row by its
file_pathalone within the group's partition, SparkRewritePositionDeleteRunner.
RewriteFiles says the max keeps "the set of applicable delete records" unchanged, L100-L115. That holds unless a replaced delete names a live data file whose data sequence number lies above the delete's own and at or below the group's max. The max dates from #7651; before it, rewritten deletes took "the current data sequence number of the table", #7624. #4988 raised this case in 2022 and proposed a spec rule against it; it was closed unmerged.
The rewrite could drop the delete rows whose live data file has a higher data sequence number than their own delete file, since they do not apply to it. On v2, it could instead keep the deletes of each source data sequence number in their own output file, and commit each file at that number. On v3 a data file has at most one deletion vector, so the rewrite has to drop such positions before it merges them.
This report was drafted with an AI assistant, which also ran the reproduction on 1.12.0 and 1.10.0 and checked the linked lines.
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時間
- マージ済み PR(30日)
- 170
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/iceberg のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Spark: Test INSERT targets with computed IDENTIFIER expressions対応中かも @shivadarshan-devadiga が 15 日前に担当しました。 オープンimprovement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
[Core] TestAvroPartitionStatsHandler fails on Windows due to unclosed partition statistics scan対応中かも @Ankitkj1999 が 17 日前に担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
Core: TableMetadata.Builder allows adding encryption keys to v1/v2 tables対応中かも @yusufyildiz34 が 37 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/iceberg#18632 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Kafka: Filter empty strings and whitespace in IcebergSinkConfig stringToList対応中かも @mohamed-elbrik が 42 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug vault
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
bancolombia/secrets-manager#150 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
HexaHexes/neoforge-mod-template#124 ·
メンテナーはふだん 1 日以内に返信
-
awaiting triage java new feature P2
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
source-survicate: pagination reads pagination and stops after one page; substreams drop survey_idオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
OpenLiberty/open-liberty#36410 ·
メンテナーはふだん 1 日以内に返信