Skip to content

fix: size JVM shuffle pointer array growth from the array, not the data pages - #5907

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:fix/shuffle-pointer-array-growth
Open

fix: size JVM shuffle pointer array growth from the array, not the data pages#5907
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:fix/shuffle-pointer-array-growth

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

Part of #5905 (finding J2). Does not close it.

Rationale for this change

CometShuffleExternalSorter.growPointerArrayIfNecessary sizes the replacement pointer array from SpillSorter.getMemoryUsage(), which Comet overrides to return the pointer array bytes plus all allocated data pages. Spark's ShuffleExternalSorter sizes it from inMemSorter.getMemoryUsage(), the array alone.

The result is that the first growth, which happens after initialSize / 2 records because half the array is reserved for radix sort, requests 2 x (pageBytes + arrayBytes) / 8 entries instead of 2 x arrayBytes / 8. With the default page size that is tens of megabytes of pointer array for a couple of thousand rows, and every later growth compounds on top of the pages allocated since. Under the bounded allocator this either wastes memory that should have gone to data pages or fails the allocation and forces a spill after very few rows.

What changes are included in this PR?

  • SpillSorter gains getPointerArrayMemoryUsage(), returning only the in-memory sorter's array size under the same lock as getMemoryUsage().
  • CometShuffleExternalSorter.growPointerArrayIfNecessary uses it to size the new array, matching Spark's behaviour of doubling the pointer array.

getMemoryUsage() itself is unchanged, so peak memory reporting and spill sizing still include the data pages.

How are these changes tested?

New test in SpillSorterSuite that inserts enough records to trigger the first pointer-array growth against a private off-heap allocator and asserts that memory in use afterwards equals one data page plus twice the initial array. Before this change the assertion fails because the array grows to more than the page size.

…ta pages

CometShuffleExternalSorter.growPointerArrayIfNecessary sized the replacement
pointer array from SpillSorter.getMemoryUsage(), which includes every data
page, so the first growth requested an array proportional to the page size
instead of doubling the array as Spark's ShuffleExternalSorter does. Add
SpillSorter.getPointerArrayMemoryUsage() and use it for growth.
@github-actions github-actions Bot added bug Something isn't working area:shuffle Shuffle (JVM and native) labels Sep 13, 2026
@andygrove
andygrove marked this pull request as draft September 13, 2026 23:03
@andygrove
andygrove marked this pull request as ready for review September 14, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:shuffle Shuffle (JVM and native) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant