spark-test commented on code in PR #60183:
URL: https://github.com/apache/spark/pull/60183#discussion_r4504710620
##########
python/pyspark/serializers.py:
##########
@@ -161,7 +161,7 @@ def _write_with_length(self, obj, stream):
serialized = self.dumps(obj)
if serialized is None:
raise ValueError("serialized value should not be None")
- if len(serialized) > (1 << 31):
+ if len(serialized) >= (1 << 31):
Review Comment:
**Non-blocking (P2):** This check only covers frames written through
`_write_with_length`. `AutoBatchedSerializer.dump_stream` frames
`self.serializer.dumps(vs)` itself with `write_int(len(bytes), stream)` (line
262), so it never reaches this check. That is the default `SparkContext` RDD
serializer (`batchSize=0`, `core/context.py:255-256`), and it also backs
`RDD._pickled`, the foreach writers, MLlib conversion and shuffle spill.
On that path, a serialized batch of exactly 2**31 bytes or more still raises
`struct.error: 'i' format requires -2147483648 <= number <= 2147483647`.
Meanwhile, `parallelize` and a non-zero `batchSize` now raise `ValueError: can
not serialize object larger than 2G`. A batch starts at a single object, so one
record that pickles to 2 GiB is enough to hit this. The description's statement
that exactly 2 GiB payloads now raise the existing `ValueError` therefore holds
only off the default path. `struct.error` is not a `ValueError` subclass, so
code that handles one error does not handle the other. Nothing is written or
corrupted on either path. The module-level `write_with_length` helper has the
same gap.
One way to close it: add this check to `write_with_length` ahead of the
header, and have `AutoBatchedSerializer.dump_stream` write each batch through
that helper. `_write_with_length` can stay as it is here.
**Verification:**
- **Regression:** When the serialized batch length is reported as exactly
2**31 and as 2**31 + 1 bytes, the default auto-batched serializer raises the
descriptive 'can not serialize object larger than 2G' ValueError and writes
nothing to the stream. write_with_length does the same for a payload of those
lengths. On the base branch, both raise struct.error.
- **Behavior:** At 2**31 - 1 bytes, the auto-batched serializer and
write_with_length still write a length header that decodes to that length,
followed by the payload. The framed-serializer boundary checks this PR adds
keep passing.
- **Compatibility:** Ordinary round trips through the auto-batched, batched,
compressed and framed serializers produce unchanged bytes and objects for
payloads below the limit, and the existing serializer tests keep passing.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]