You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "parthchandra (via GitHub)" <gi...@apache.org> on 2026/08/18 23:26:19 UTC
[PR] fix: Native shuffle fails with a 2GB task serialization OOM on jobs with many partitions [datafusion-comet]
parthchandra opened a new pull request, #5392:
URL: https://github.com/apache/datafusion-comet/pull/5392
## Which issue does this PR close?
Closes #5391.
## Rationale for this change
A native-shuffle job with a very large number of partitions fails at stage submission, before any task runs:
(From the issue:
Task serialization failed: java.lang.OutOfMemoryError: Required array length 2147483639 + 794 is too large
at java.io.ByteArrayOutputStream.ensureCapacity(...)
at org.apache.spark.scheduler.DAGScheduler.submitMissingTasks(...)
`DAGScheduler` serializes the `(RDD, ShuffleDependency)` pair into a single broadcast byte array that must fit in ~2GB. On the native-shuffle path, `CometShuffleDependency.nativeShuffleSpec` is a non-transient field holding a `perPartitionByKey` map with one scan-plan-data blob (the partition's file list) per map partition. The failing job had ~38.7M
partitions, so ~38.7M protobufs got baked into that one blob and blew the limit — even though each task only reads its own slice. Plain Spark avoids this by keeping per-partition file lists `@transient` and shipping them per task; Comet's own `CometExecRDD` does the same. The native shuffle path was the exception.
## What changes are included in this PR?
Mirror `CometExecRDD`: keep the map off the serialized dependency and give each task only its slice.
- `CometNativeShuffleInputRDD` takes `perPartitionByKey` as a `@transient` arg and, in `getPartitions` (driver-side), slices out each partition's entry onto its `Partition` object. That slice flows to the writer, which injects it instead of indexing the full map.
- `NativeExecContext.perPartitionByKey` is now `@transient` so no build path can serialize the full map, and we also empty it when building the dependency.
- `commonByKey` is unchanged — it's sized by scan count, not partition count, and the writer still needs it.
## How are these changes tested?
- A unit test serializes the input RDD at 10 vs 10,000 partitions and checks the size stays roughly constant, and that each partition carries only its own slice.
- An end-to-end test runs a native shuffle over a multi-partition native scan and compares results against Spark with an all-native plan, so a wrong slice would fail it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Native shuffle fails with a 2GB task serialization OOM on jobs with many partitions [datafusion-comet]
Posted by "sunchao (via GitHub)" <gi...@apache.org>.
sunchao commented on code in PR #5392:
URL: https://github.com/apache/datafusion-comet/pull/5392#discussion_r3815919434
##########
spark/src/test/scala/org/apache/spark/sql/comet/execution/shuffle/CometNativeShuffleInputRDDSuite.scala:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.spark.sql.comet.execution.shuffle
+
+import org.apache.spark.serializer.JavaSerializer
+import org.apache.spark.sql.CometTestBase
+
+/**
+ * Ensure that serialized RDD does not overflow in size with a very large number of partitions
+ * Lives in the `execution.shuffle` package so it can construct the `private[shuffle]`
+ * [[CometNativeShuffleInputRDD]] directly.
+ */
+class CometNativeShuffleInputRDDSuite extends CometTestBase {
+
+ test("serialized RDD size is independent of partition count") {
+ val sc = spark.sparkContext
+ val ser = new JavaSerializer(sc.getConf).newInstance()
+
+ // One scan key with a 1KB blob per map partition. Pre-fix the whole array serializes into the
+ // RDD, so 10000 partitions add ~10MB versus 10.
+ def buildRDD(numPartitions: Int): CometNativeShuffleInputRDD = {
+ val perPartitionByKey =
+ Map("scan-0" -> Array.fill(numPartitions)(new Array[Byte](1024)))
+ new CometNativeShuffleInputRDD(
+ sc,
+ inputRDDs = Seq.empty,
+ numPartitionsParam = numPartitions,
+ shuffleScanIndices = Set.empty,
+ perPartitionByKey = perPartitionByKey)
+ }
+
+ val smallSize = ser.serialize(buildRDD(10)).limit()
+ val large = buildRDD(10000)
+ val largeSize = ser.serialize(large).limit()
Review Comment:
[P2] Exercise the actual shuffle task binary
Could this also construct a native shuffle dependency and compare the serialized size of `(rdd, shuffleDependency)` for 10 and 10,000 partitions? That is what Spark broadcasts for a shuffle-map stage. Before this fix, the large map lived under `CometShuffleDependency.nativeShuffleSpec.execContext`, not on the thin RDD. In an isolated Spark serialization probe, restoring that dependency leak left the RDD at 880 bytes while the pair grew from 13,322 to 10,342,982 bytes. The current RDD-only assertion therefore stays green if those guards regress. Testing the actual pair would protect the reported 2GB failure without requiring a 2GB allocation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Native shuffle fails with a 2GB task serialization OOM on jobs with many partitions [datafusion-comet]
Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on PR #5392:
URL: https://github.com/apache/datafusion-comet/pull/5392#issuecomment-5349406709
> Thanks @parthchandra lgtm, however I never hit that error when was testing on workloads with 20k+ partitions
@comphead this happens at petabyte scale. The failure occurred at 38M partitions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Native shuffle fails with a 2GB task serialization OOM on jobs with many partitions [datafusion-comet]
Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on code in PR #5392:
URL: https://github.com/apache/datafusion-comet/pull/5392#discussion_r3817551860
##########
spark/src/test/scala/org/apache/spark/sql/comet/execution/shuffle/CometNativeShuffleInputRDDSuite.scala:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.spark.sql.comet.execution.shuffle
+
+import org.apache.spark.serializer.JavaSerializer
+import org.apache.spark.sql.CometTestBase
+
+/**
+ * Ensure that serialized RDD does not overflow in size with a very large number of partitions
+ * Lives in the `execution.shuffle` package so it can construct the `private[shuffle]`
+ * [[CometNativeShuffleInputRDD]] directly.
+ */
+class CometNativeShuffleInputRDDSuite extends CometTestBase {
+
+ test("serialized RDD size is independent of partition count") {
+ val sc = spark.sparkContext
+ val ser = new JavaSerializer(sc.getConf).newInstance()
+
+ // One scan key with a 1KB blob per map partition. Pre-fix the whole array serializes into the
+ // RDD, so 10000 partitions add ~10MB versus 10.
+ def buildRDD(numPartitions: Int): CometNativeShuffleInputRDD = {
+ val perPartitionByKey =
+ Map("scan-0" -> Array.fill(numPartitions)(new Array[Byte](1024)))
+ new CometNativeShuffleInputRDD(
+ sc,
+ inputRDDs = Seq.empty,
+ numPartitionsParam = numPartitions,
+ shuffleScanIndices = Set.empty,
+ perPartitionByKey = perPartitionByKey)
+ }
+
+ val smallSize = ser.serialize(buildRDD(10)).limit()
+ val large = buildRDD(10000)
+ val largeSize = ser.serialize(large).limit()
Review Comment:
Good suggestion; added ! This will now fail if someone removes the `@transient` on `NativeExecContext.perPartitionByKey`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Native shuffle fails with a 2GB task serialization OOM on jobs with many partitions [datafusion-comet]
Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on PR #5392:
URL: https://github.com/apache/datafusion-comet/pull/5392#issuecomment-5358793378
Merged. Thank you @sunchao, @comphead !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Native shuffle fails with a 2GB task serialization OOM on jobs with many partitions [datafusion-comet]
Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra merged PR #5392:
URL: https://github.com/apache/datafusion-comet/pull/5392
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org