Spark: SparkBatch broadcasts the table and FileIO on every planInputPartitions call, exhausting driver memory with nested DPP filters
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- java, spark
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
Start with SparkBatch.java and trace how SparkScan.toBatch() creates SparkBatch instances and how planInputPartitions() creates the table and FileIO broadcasts. The issue reproduces the problem with repeated calls on one scan and gives a seven table Spark SQL query for broader verification. Done means repeated planning for the same scan reuses its broadcasts, so broadcast counts grow with scans rather than planning calls.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Apache Iceberg version
1.11.0
Query engine
Spark
Please describe the bug 🐞
Problem
SparkBatch.planInputPartitions() creates a new table broadcast and a new FileIO broadcast every time it is called:
Broadcast<Table> tableBroadcast =
sparkContext.broadcast(SerializableTableWithSize.copyOf(table));
Broadcast<FileIO> fileIOBroadcast =
sparkContext.broadcast(SerializableFileIOWithSize.wrap(fileIO.get()));
SparkScan.toBatch() returns a new SparkBatch on each call, so nothing is reused between calls, even though the table and the FileIO do not change during the lifetime of a scan.
Spark calls planInputPartitions() once per copy of a scan's physical node, while it is still planning the query. When dynamic partition pruning filters nest over a chain of joins on a partition column - something similar to SPARK-48486 - Spark plans an exponential number of copies, and each one adds two broadcasts to the driver. Iceberg never destroys these broadcasts, so they stay in the driver's block manager until the plans that reference them are garbage collected.
What we saw
A production query on Spark 4.1.1 with Iceberg 1.11.0, with 17 left joins of which 10 are on the partition column:
- the driver created 264,382 broadcasts, exactly half from each of the two
sparkContext.broadcastcalls above and none from anywhere else - the driver's
MemoryStorewent from 14.2 GiB free to about 1 MiB in roughly 6.5 minutes and never recovered - the driver failed without starting a job or a stage
The same query succeeds with spark.sql.optimizer.dynamicPartitionPruning.enabled=false.
The Spark 3.5, 4.0, 4.1 and 4.2 modules on main have the same code.
Expected
Planning input partitions again for the same scan should reuse the broadcasts it already created. The number of broadcasts should grow with the number of scans in the query, not with the number of times Spark plans them.
How to reproduce
Create seven small partitioned tables and join them on the partition column, with a selective filter on the first one:
CREATE TABLE t0 (id BIGINT, ds STRING) USING iceberg PARTITIONED BY (ds);
INSERT INTO t0 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
-- repeat for t1 .. t6
SELECT t0.id
FROM t0
LEFT JOIN t1 ON t0.ds = t1.ds AND t0.id = t1.id
LEFT JOIN t2 ON t0.ds = t2.ds AND t0.id = t2.id
LEFT JOIN t3 ON t0.ds = t3.ds AND t0.id = t3.id
LEFT JOIN t4 ON t0.ds = t4.ds AND t0.id = t4.id
LEFT JOIN t5 ON t0.ds = t5.ds AND t0.id = t5.id
LEFT JOIN t6 ON t0.ds = t6.ds AND t0.id = t6.id
WHERE t0.id < 3;
With default settings this query creates 415 to 429 broadcasts on main, depending on the Spark version, for seven tables of four rows each. The count can be read from the Created broadcast N from broadcast at SparkBatch.java lines in the driver log, or from the ID of a broadcast created before and after the query. Each additional join on ds roughly doubles it.
Calling scan.toBatch().planInputPartitions() repeatedly on a single scan shows the same thing in isolation: every call creates two new broadcasts.
Scope
The exponential number of DPP subqueries is a Spark planning problem and is tracked in SPARK-48486 (it is unverified if this spark issue is exactly the nesting root cause) . This issue is only about Iceberg creating new broadcasts for every one of those planning calls, which turns slow planning into a driver out-of-memory failure.
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
- Ngôn ngữ chính
- Java
- Star
- 9.4k
- Fork
- 3.7k
- Merge trung bình
- 2 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 169
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/iceberg
-
Spark: Test INSERT targets with computed IDENTIFIER expressionsCó thể đã có người làm @shivadarshan-devadiga đã nhận 8 ngày trước. Đang mởimprovement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Core] TestAvroPartitionStatsHandler fails on Windows due to unclosed partition statistics scanCó thể đã có người làm @Ankitkj1999 đã nhận 10 ngày trước. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Flink: JdbcLockFactory concurrent lock-table creation can fail with "table already exists" and restart the jobCó thể đã có người làm @adiranjan25 đã nhận 17 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/iceberg#18797 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Core: TableMetadata.Builder allows adding encryption keys to v1/v2 tablesCó thể đã có người làm @yusufyildiz34 đã nhận 29 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/iceberg#18632 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Kafka: Filter empty strings and whitespace in IcebergSinkConfig stringToListCó thể đã có người làm @mohamed-elbrik đã nhận 34 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/iceberg
Issue tương tự
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Handle TSP error code 212Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
bug module: hybrid priority: high
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bancolombia/bin-stash#92 ·
-
Pub/Sub nackSplit drops other splits' empty checkpoint entries and lowers pendingCheckpointsĐang mởbug module:pubsub priority:P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
flink-gcp/flink-connector-gcp#2325 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
eclipse-dirigible/dirigible#8877 ·
Maintainer thường phản hồi trong vòng 1 ngày