This is an automated email from the ASF dual-hosted git repository.

zaynt4606 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new 6b153a5081 [CELEBORN-2576] Fix Spark sort memory threshold overflow
6b153a5081 is described below

commit 6b153a508147f211dc578be97052317b5b61317d
Author: huangxiaoping <[email protected]>
AuthorDate: Fri Nov 20 10:40:47 2026 +0800

    [CELEBORN-2576] Fix Spark sort memory threshold overflow
    
    ### What changes were proposed in this pull request?
    
    Calculate the initial sort pointer array size using `long` arithmetic, and 
keep the sorter initial size as `long`.
    
    ### Why are the changes needed?
    
    When `celeborn.client.spark.push.sort.memory.threshold` is `2g`, casting 
the threshold to `int` before dividing produces a negative array size and the 
sort-based writer fails to initialize. A `4g` threshold truncates to zero. The 
initial array remains capped at 1,048,576 longs.
    
    Using `long` for the sorter initial size also matches Spark's 
`MemoryConsumer.allocateArray(long)` API.
    
    ### Does this PR resolve a correctness bug?
    
    - [x] Yes
    
    ### Does this PR introduce _any_ user-facing change?
    
    - [x] Yes
    
    Large sort memory thresholds can initialize the writer without overflowing 
the initial pointer array size.
    
    ### How was this patch tested?
    
    - Ran `SortBasedPusherSuiteJ` and `ShuffleInMemorySorterSuiteJ` using the 
Spark 3.5 Maven profile. The former includes regression coverage for `64m`, 
`2g`, and `4g` thresholds.
    - Ran Spotless check on `client-spark/common`.
    
    Closes #3993 from huangxiaopingRD/codex/fix-spark-sort-threshold.
    
    Authored-by: huangxiaoping <[email protected]>
    Signed-off-by: zhengtao <[email protected]>
    
    AI-Contributed/Feature: 0/6
    AI-Contributed/UT: 0/32
---
 .../shuffle/celeborn/ShuffleInMemorySorter.java    |  4 +--
 .../spark/shuffle/celeborn/SortBasedPusher.java    |  2 +-
 .../shuffle/celeborn/SortBasedPusherSuiteJ.java    | 32 ++++++++++++++++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/ShuffleInMemorySorter.java
 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/ShuffleInMemorySorter.java
index c3af2ebd63..ccd1043b9a 100644
--- 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/ShuffleInMemorySorter.java
+++ 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/ShuffleInMemorySorter.java
@@ -41,9 +41,9 @@ public class ShuffleInMemorySorter {
   /** How many records could be inserted, because part of the array should be 
left for sorting. */
   private int usableCapacity = 0;
 
-  private final int initialSize;
+  private final long initialSize;
 
-  public ShuffleInMemorySorter(MemoryConsumer consumer, int initialSize) {
+  public ShuffleInMemorySorter(MemoryConsumer consumer, long initialSize) {
     this.consumer = consumer;
     assert (initialSize > 0);
     this.initialSize = initialSize;
diff --git 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/SortBasedPusher.java
 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/SortBasedPusher.java
index a4a1985b5b..4793ae06ee 100644
--- 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/SortBasedPusher.java
+++ 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/SortBasedPusher.java
@@ -202,7 +202,7 @@ public class SortBasedPusher extends MemoryConsumer {
     this.memoryThresholdManager =
         new MemoryThresholdManager(maxMemoryFactor, 
conf.clientPushSortSmallPushTolerateFactor());
 
-    int initialSize = Math.min((int) pushSortMemoryThreshold / 8, 1024 * 1024);
+    long initialSize = Math.min(pushSortMemoryThreshold / Long.BYTES, 1024L * 
1024);
     this.inMemSorter = new ShuffleInMemorySorter(this, initialSize);
     this.peakMemoryUsedBytes = getMemoryUsage();
   }
diff --git 
a/client-spark/common/src/test/java/org/apache/spark/shuffle/celeborn/SortBasedPusherSuiteJ.java
 
b/client-spark/common/src/test/java/org/apache/spark/shuffle/celeborn/SortBasedPusherSuiteJ.java
index 73c15bb70d..37d886dfd2 100644
--- 
a/client-spark/common/src/test/java/org/apache/spark/shuffle/celeborn/SortBasedPusherSuiteJ.java
+++ 
b/client-spark/common/src/test/java/org/apache/spark/shuffle/celeborn/SortBasedPusherSuiteJ.java
@@ -79,6 +79,38 @@ public class SortBasedPusherSuiteJ {
     }
   }
 
+  @Test
+  public void testLargeMemoryThreshold() throws Exception {
+    for (String threshold : new String[] {"64m", "2g", "4g"}) {
+      CelebornConf conf =
+          new 
CelebornConf().set(CelebornConf.CLIENT_PUSH_SORT_MEMORY_THRESHOLD().key(), 
threshold);
+      ShuffleClient client = new DummyShuffleClient(conf, tempFile);
+      SortBasedPusher pusher =
+          new SortBasedPusher(
+              taskMemoryManager,
+              client,
+              taskContext,
+              0,
+              0,
+              0,
+              0,
+              0,
+              0,
+              conf,
+              null,
+              null,
+              conf.clientPushSortMemoryThreshold(),
+              SendBufferPool.get(4, 30, 60));
+      try {
+        assertEquals(Utils.byteStringAsBytes(threshold), 
pusher.getPushSortMemoryThreshold());
+        assertEquals(8L * 1024 * 1024, pusher.getUsed());
+      } finally {
+        pusher.close(true);
+        client.shutdown();
+      }
+    }
+  }
+
   @Test
   public void testMemoryUsage() throws Exception {
     final ShuffleClient client = new DummyShuffleClient(conf, tempFile);

Reply via email to