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

nicholasjiang 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 913d027ef [CELEBORN-2287] Split mode should be HARD_SPLIT when disk is 
full
913d027ef is described below

commit 913d027efd1e56d080ec8080818e05ccf8eaa025
Author: zhengtao <[email protected]>
AuthorDate: Sat Apr 11 11:44:19 2026 +0800

    [CELEBORN-2287] Split mode should be HARD_SPLIT when disk is full
    
    ### What changes were proposed in this pull request?
    
    Change the split mode to `HARD_SPLIT` when disk is full.
    
    ### Why are the changes needed?
    
    When the disk is already in a full state, continuous writing data in 
`SOFT_SPLIT` mode may cause the reserved space to be filled up as well.
    
    ### Does this PR resolve a correctness bug?
    
    No.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Manual test and UT.
    
    Closes #3653 from zaynt4606/clb2287.
    
    Authored-by: zhengtao <[email protected]>
    Signed-off-by: SteNicholas <[email protected]>
---
 .../service/deploy/worker/PushDataHandler.scala    |  43 ++--
 .../deploy/worker/PushDataHandlerSuite.scala       | 284 +++++++++++++++++++++
 2 files changed, 309 insertions(+), 18 deletions(-)

diff --git 
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/PushDataHandler.scala
 
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/PushDataHandler.scala
index 4cbff7866..50f085bf8 100644
--- 
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/PushDataHandler.scala
+++ 
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/PushDataHandler.scala
@@ -1426,7 +1426,7 @@ class PushDataHandler(val workerSource: WorkerSource) 
extends BaseMessageHandler
   }
 
   private def checkDiskFull(fileWriter: PartitionDataWriter): Boolean = {
-    val flusher = fileWriter.getFlusher;
+    val flusher = fileWriter.getFlusher
     if (flusher.isInstanceOf[LocalFlusher]) {
       val mountPoint = flusher.asInstanceOf[LocalFlusher].mountPoint
       val diskInfo = workerInfo.diskInfos.get(mountPoint)
@@ -1436,7 +1436,7 @@ class PushDataHandler(val workerSource: WorkerSource) 
extends BaseMessageHandler
     }
   }
 
-  private def checkDiskFullAndSplit(
+  private[worker] def checkDiskFullAndSplit(
       fileWriter: PartitionDataWriter,
       isPrimary: Boolean): StatusCode = {
     if (fileWriter.needHardSplitForMemoryShuffleStorage()) {
@@ -1455,25 +1455,32 @@ class PushDataHandler(val workerSource: WorkerSource) 
extends BaseMessageHandler
          |fileName:${fileWriter.getCurrentFileInfo.getFilePath}
          |""".stripMargin)
     val diskFileInfo = fileWriter.getDiskFileInfo
-    if (diskFileInfo != null) {
-      if (workerPartitionSplitEnabled && ((diskFull && 
diskFileInfo.getFileLength > partitionSplitMinimumSize) ||
-          (isPrimary && diskFileInfo.getFileLength > 
fileWriter.getSplitThreshold))) {
-        if (fileWriter.getSplitMode == PartitionSplitMode.SOFT &&
-          (fileWriter.getDiskFileInfo.getFileLength < 
partitionSplitMaximumSize)) {
-          return StatusCode.SOFT_SPLIT
+    if (workerPartitionSplitEnabled && diskFileInfo != null) {
+      val splitStatus =
+        if (diskFull && (diskFileInfo.getFileLength > 
partitionSplitMinimumSize)) {
+          StatusCode.HARD_SPLIT
+        } else if (isPrimary && diskFileInfo.getFileLength > 
fileWriter.getSplitThreshold) {
+          if (fileWriter.getSplitMode == PartitionSplitMode.SOFT &&
+            diskFileInfo.getFileLength < partitionSplitMaximumSize) {
+            StatusCode.SOFT_SPLIT
+          } else {
+            StatusCode.HARD_SPLIT
+          }
         } else {
-          logInfo(
-            s"""
-               |CheckDiskFullAndSplit hardSplit
-               |diskFull:$diskFull,
-               |partitionSplitMinimumSize:$partitionSplitMinimumSize,
-               |splitThreshold:${fileWriter.getSplitThreshold},
-               |fileLength:${diskFileInfo.getFileLength},
-               |fileName:${diskFileInfo.getFilePath}
-               |""".stripMargin)
-          return StatusCode.HARD_SPLIT
+          StatusCode.NO_SPLIT
         }
+      if (splitStatus == StatusCode.HARD_SPLIT) {
+        logInfo(
+          s"""
+             |CheckDiskFullAndSplit hardSplit
+             |diskFull:$diskFull,
+             |partitionSplitMinimumSize:$partitionSplitMinimumSize,
+             |splitThreshold:${fileWriter.getSplitThreshold},
+             |fileLength:${diskFileInfo.getFileLength},
+             |fileName:${diskFileInfo.getFilePath}
+             |""".stripMargin)
       }
+      return splitStatus
     }
     StatusCode.NO_SPLIT
   }
diff --git 
a/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/PushDataHandlerSuite.scala
 
b/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/PushDataHandlerSuite.scala
new file mode 100644
index 000000000..40639a248
--- /dev/null
+++ 
b/worker/src/test/scala/org/apache/celeborn/service/deploy/worker/PushDataHandlerSuite.scala
@@ -0,0 +1,284 @@
+/*
+ * 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.celeborn.service.deploy.worker
+
+import java.util
+
+import org.mockito.MockitoSugar._
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.meta.{DiskFileInfo, DiskInfo, 
MemoryFileInfo, WorkerInfo}
+import org.apache.celeborn.common.meta.DiskStatus
+import org.apache.celeborn.common.protocol.PartitionSplitMode
+import org.apache.celeborn.common.protocol.message.StatusCode
+import org.apache.celeborn.service.deploy.worker.storage.{LocalFlusher, 
PartitionDataWriter}
+
+/**
+ * Unit tests for [[PushDataHandler.checkDiskFullAndSplit]].
+ *
+ * The method under test has the following decision tree:
+ *   1. If needHardSplitForMemoryShuffleStorage() → HARD_SPLIT
+ *   2. If workerPartitionSplitEnabled is false or diskFileInfo is null → 
NO_SPLIT
+ *   3. If disk is full and fileLength > partitionSplitMinimumSize → HARD_SPLIT
+ *   4. If isPrimary and fileLength > splitThreshold:
+ *      a. SOFT mode and fileLength < partitionSplitMaximumSize → SOFT_SPLIT
+ *      b. Otherwise (HARD mode, or fileLength >= partitionSplitMaximumSize) → 
HARD_SPLIT
+ *   5. Otherwise → NO_SPLIT
+ */
+class PushDataHandlerSuite extends AnyFunSuite {
+
+  // ── helpers ──────────────────────────────────────────────────────────────
+
+  private val splitMinimumSize: Long = 1024L * 1024L // 1 MB
+  private val splitMaximumSize: Long = 1024L * 1024L * 10L // 10 MB
+  private val splitThreshold: Long = 1024L * 1024L * 2L // 2 MB
+  private val mountPoint = "/mnt/disk0"
+
+  /**
+   * Build a [[PushDataHandler]] with the given configuration flags, wired up
+   * with a minimal [[WorkerInfo]] that contains one disk entry for 
[[mountPoint]].
+   */
+  private def buildHandler(
+      partitionSplitEnabled: Boolean,
+      diskStatus: DiskStatus = DiskStatus.HEALTHY,
+      actualUsableSpace: Long = Long.MaxValue): PushDataHandler = {
+    val conf = new CelebornConf()
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_ENABLED.key, 
partitionSplitEnabled.toString)
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_MIN_SIZE.key, 
splitMinimumSize.toString)
+    conf.set(CelebornConf.WORKER_PARTITION_SPLIT_MAX_SIZE.key, 
splitMaximumSize.toString)
+
+    val diskInfo = new DiskInfo(mountPoint, actualUsableSpace, 0L, 0L, 0L)
+    diskInfo.setStatus(diskStatus)
+
+    val diskInfoMap = new util.HashMap[String, DiskInfo]()
+    diskInfoMap.put(mountPoint, diskInfo)
+
+    val workerInfo = new WorkerInfo("localhost", 9095, 9096, 9097, 9098, -1, 
diskInfoMap, null)
+
+    val workerSource = mock[WorkerSource]
+
+    val handler = new PushDataHandler(workerSource)
+    // Inject fields that checkDiskFullAndSplit depends on via reflection 
helpers
+    // exposed through the init path. We use a minimal mock Worker instead.
+    val mockWorker = mock[Worker]
+    when(mockWorker.conf).thenReturn(conf)
+    when(mockWorker.workerInfo).thenReturn(workerInfo)
+    // Provide no-op stubs for all other Worker fields accessed during init
+    when(mockWorker.partitionLocationInfo).thenReturn(mock[
+      org.apache.celeborn.common.meta.WorkerPartitionLocationInfo])
+    when(mockWorker.shufflePartitionType).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap[
+        String,
+        org.apache.celeborn.common.protocol.PartitionType]())
+    when(mockWorker.shufflePushDataTimeout).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap[String, Long]())
+    when(mockWorker.shuffleMapperAttempts).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap[
+        String,
+        java.util.concurrent.atomic.AtomicIntegerArray]())
+    
when(mockWorker.replicateThreadPool).thenReturn(mock[java.util.concurrent.ThreadPoolExecutor])
+    when(mockWorker.unavailablePeers).thenReturn(
+      new java.util.concurrent.ConcurrentHashMap[WorkerInfo, Long]())
+    when(mockWorker.replicateClientFactory).thenReturn(
+      mock[org.apache.celeborn.common.network.client.TransportClientFactory])
+    when(mockWorker.storageManager).thenReturn(mock[
+      org.apache.celeborn.service.deploy.worker.storage.StorageManager])
+    when(mockWorker.shutdown).thenReturn(new 
java.util.concurrent.atomic.AtomicBoolean(false))
+    when(mockWorker.registered).thenReturn(new 
java.util.concurrent.atomic.AtomicBoolean(true))
+
+    handler.init(mockWorker)
+    handler
+  }
+
+  /**
+   * Build a mock [[PartitionDataWriter]] backed by a [[LocalFlusher]] pointing
+   * at [[mountPoint]], with the given file length, split threshold, and split 
mode.
+   */
+  private def buildFileWriter(
+      fileLength: Long,
+      splitMode: PartitionSplitMode = PartitionSplitMode.SOFT,
+      needMemoryHardSplit: Boolean = false,
+      diskFileInfoNull: Boolean = false): PartitionDataWriter = {
+    val fileWriter = mock[PartitionDataWriter]
+
+    
when(fileWriter.needHardSplitForMemoryShuffleStorage()).thenReturn(needMemoryHardSplit)
+
+    if (needMemoryHardSplit) {
+      val memoryFileInfo = mock[MemoryFileInfo]
+      when(memoryFileInfo.getFileLength).thenReturn(fileLength)
+      when(fileWriter.getMemoryFileInfo).thenReturn(memoryFileInfo)
+    }
+
+    if (diskFileInfoNull) {
+      when(fileWriter.getDiskFileInfo).thenReturn(null)
+    } else {
+      val diskFileInfo = mock[DiskFileInfo]
+      when(diskFileInfo.getFileLength).thenReturn(fileLength)
+      
when(diskFileInfo.getFilePath).thenReturn(s"/data/shuffle-$fileLength.index")
+      when(fileWriter.getDiskFileInfo).thenReturn(diskFileInfo)
+    }
+
+    val localFlusher = mock[LocalFlusher]
+    when(localFlusher.mountPoint).thenReturn(mountPoint)
+    when(fileWriter.getFlusher).thenReturn(localFlusher)
+    when(fileWriter.getSplitThreshold).thenReturn(splitThreshold)
+    when(fileWriter.getSplitMode).thenReturn(splitMode)
+
+    fileWriter
+  }
+
+  // ── test cases ────────────────────────────────────────────────────────────
+
+  test("returns HARD_SPLIT when memory shuffle storage needs hard split") {
+    val handler = buildHandler(partitionSplitEnabled = true)
+    val fileWriter = buildFileWriter(fileLength = 0L, needMemoryHardSplit = 
true)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.HARD_SPLIT)
+  }
+
+  test("returns NO_SPLIT when workerPartitionSplitEnabled is false") {
+    val handler = buildHandler(partitionSplitEnabled = false)
+    // Even if file is huge, split is disabled globally
+    val fileWriter = buildFileWriter(fileLength = splitThreshold * 10)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.NO_SPLIT)
+  }
+
+  test("returns NO_SPLIT when diskFileInfo is null (e.g. memory-only writer)") 
{
+    val handler = buildHandler(partitionSplitEnabled = true)
+    val fileWriter = buildFileWriter(fileLength = splitThreshold * 10, 
diskFileInfoNull = true)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.NO_SPLIT)
+  }
+
+  test("returns HARD_SPLIT when disk is full and file exceeds 
partitionSplitMinimumSize") {
+    val handler = buildHandler(
+      partitionSplitEnabled = true,
+      diskStatus = DiskStatus.HIGH_DISK_USAGE)
+    // File is larger than the minimum split size
+    val fileWriter = buildFileWriter(fileLength = splitMinimumSize + 1)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.HARD_SPLIT)
+  }
+
+  test("returns NO_SPLIT when disk is full but file is smaller than 
partitionSplitMinimumSize") {
+    val handler = buildHandler(
+      partitionSplitEnabled = true,
+      diskStatus = DiskStatus.HIGH_DISK_USAGE)
+    // File is smaller than the minimum split size → no split triggered
+    val fileWriter = buildFileWriter(fileLength = splitMinimumSize - 1)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.NO_SPLIT)
+  }
+
+  test("returns NO_SPLIT when disk usable space is zero and file is below 
minimum split size") {
+    val handler = buildHandler(
+      partitionSplitEnabled = true,
+      actualUsableSpace = 0L)
+    val fileWriter = buildFileWriter(fileLength = splitMinimumSize - 1)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.NO_SPLIT)
+  }
+
+  test("returns HARD_SPLIT when disk usable space is zero and file exceeds 
minimum split size") {
+    val handler = buildHandler(
+      partitionSplitEnabled = true,
+      actualUsableSpace = 0L)
+    val fileWriter = buildFileWriter(fileLength = splitMinimumSize + 1)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.HARD_SPLIT)
+  }
+
+  test("returns SOFT_SPLIT for primary when file exceeds splitThreshold in 
SOFT mode and is below maximum size") {
+    val handler = buildHandler(partitionSplitEnabled = true)
+    // File is between splitThreshold and splitMaximumSize
+    val fileLength = splitThreshold + 1
+    val fileWriter = buildFileWriter(fileLength = fileLength, splitMode = 
PartitionSplitMode.SOFT)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.SOFT_SPLIT)
+  }
+
+  test("returns HARD_SPLIT for primary when file exceeds splitThreshold in 
SOFT mode but reaches maximum size") {
+    val handler = buildHandler(partitionSplitEnabled = true)
+    // File has grown beyond the maximum allowed size → force HARD_SPLIT even 
in SOFT mode
+    val fileLength = splitMaximumSize + 1
+    val fileWriter = buildFileWriter(fileLength = fileLength, splitMode = 
PartitionSplitMode.SOFT)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.HARD_SPLIT)
+  }
+
+  test("returns HARD_SPLIT for primary when file exceeds splitThreshold in 
HARD mode") {
+    val handler = buildHandler(partitionSplitEnabled = true)
+    val fileLength = splitThreshold + 1
+    val fileWriter = buildFileWriter(fileLength = fileLength, splitMode = 
PartitionSplitMode.HARD)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.HARD_SPLIT)
+  }
+
+  test("returns NO_SPLIT for replica even when file exceeds splitThreshold") {
+    val handler = buildHandler(partitionSplitEnabled = true)
+    // Replica workers never trigger a split — only primary does
+    val fileLength = splitThreshold * 5
+    val fileWriter = buildFileWriter(fileLength = fileLength, splitMode = 
PartitionSplitMode.SOFT)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = false)
+
+    assert(result === StatusCode.NO_SPLIT)
+  }
+
+  test("returns NO_SPLIT when file length is exactly at splitThreshold (not 
exceeded)") {
+    val handler = buildHandler(partitionSplitEnabled = true)
+    val fileWriter =
+      buildFileWriter(fileLength = splitThreshold, splitMode = 
PartitionSplitMode.SOFT)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.NO_SPLIT)
+  }
+
+  test("returns NO_SPLIT when file length is below splitThreshold") {
+    val handler = buildHandler(partitionSplitEnabled = true)
+    val fileWriter =
+      buildFileWriter(fileLength = splitThreshold - 1, splitMode = 
PartitionSplitMode.SOFT)
+
+    val result = handler.checkDiskFullAndSplit(fileWriter, isPrimary = true)
+
+    assert(result === StatusCode.NO_SPLIT)
+  }
+}

Reply via email to