← Back to Pull requests

fix: cut JVM columnar shuffle batches by bytes as well as rows #7787

Open
unknown opened this pull request with 476 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 29, 2026 21:03 UTC
Author

Which issue does this PR close?

Closes #7497. Part of #7267. The one case left, a single row whose string decodes past 2 GiB, is #7803.

Rationale for this change

The JVM columnar shuffle converts sorted UnsafeRows to Arrow in batches of spark.comet.shuffle.jvm.batchSize rows (capped by spark.comet.batchSize). Both entry points, process_sorted_row_partition and the sort-based process_sorted_partitions, cut batches by row count only. Arrow indexes a string or binary column's values with i32 offsets, so once one column of one batch passes 2 GiB (about 256 KiB per value at 8192 rows) the task panics with byte array offset overflow, or fails with OffsetOverflowError when a dictionary column falls back to plain values. Spark shuffles rows and has no batch to overflow, so the same query succeeds without Comet. The only workaround was lowering the batch size for every shuffle.

What changes are included in this PR?

  • Byte budget. A batch ends at the row limit, or before the sum of its UnsafeRow sizes passes 1 GiB, whichever comes first (BatchLimits::has_room). A row's size bounds what it adds to any one binary column, including values nested in arrays, maps and structs, so the cut needs no look at the values. A batch always takes its first row.

  • String weighting. get_string replaces each invalid UTF-8 byte with the three bytes of U+FFFD, so when the schema holds a string anywhere, each row counts three times (row_weight). One column of a batch then holds at most about 1 GiB even if every byte is invalid.

  • Oversized blocks are split. A batch's Arrow form can be far larger than its rows: Spark stores a null element of an array of structs in one slot, Arrow in every child array. When the encoded block of a batch of several rows passes i32::MAX, which the block writer and the JVM reader (NativeBatchDecoderIterator) cannot take, encode_batch drops it before it reaches the checksum or the file and encodes each half instead. The buffer gives back the capacity afterwards.

  • The limits are passed to private *_within functions as BatchLimits, so tests can inject small ones. The public signatures and the JNI call sites are unchanged.

  • Docs: the write path in jvm_shuffle.md, the config tables in jvm_shuffle.md and native_shuffle.md, the Batch Size section of memory.md, and the .doc(...) of spark.comet.shuffle.jvm.batchSize.
  • How are these changes tested?

  • sorted_row_partition_ends_batches_at_the_byte_budget: six batch-size and budget combinations through process_sorted_row_partition, including a budget below one row; checks the blocks written and that the values read back unchanged and in order.

  • sorted_partitions_end_batches_at_the_byte_budget: records laid out in a page as Spark's sorter stores them, across two partitions and an empty one; checks the blocks per partition, partition_lengths against the file, and the round-tripped values.

  • row_weight_triples_rows_whose_schema_holds_a_string and string_columns_budget_for_invalid_utf8_tripling: nested schemas, and a budget that holds three binary rows but one string row.

  • oversized_blocks_are_split_before_the_checksum_and_the_file: a small injected block limit halves the batch, or splits it down to single rows, and the returned checksum matches the file's bytes.

  • #[ignore], need several GiB, run locally with --ignored: invalid_utf8_strings_tripled_past_2_gib_do_not_overflow and blocks_past_i32_max_from_null_structs_are_split rebuild both cases from the review at full size. Each checks that the old cut fails (overflow, or exceeds maximum size from the block writer) and that the new one writes every row intact.

  • Existing CometShuffleSuite, DisableAQECometShuffleSuite and CometShuffleChecksumDisabledSuite pass.
  • Diff: 476 lines (+357 / -119) across 5 files Reviewer: sunchao Review duration: 1783m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 476 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.369
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7787"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.8% (MEDIUM) · Higher = larger blast radius
    45.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.4% · Safe to merge
    24.4%