You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@celeborn.apache.org by "CodingCat (via GitHub)" <gi...@apache.org> on 2025/02/19 00:42:57 UTC

[PR] [WIP] clean failed shuffle disk [celeborn]

CodingCat opened a new pull request, #3109:
URL: https://github.com/apache/celeborn/pull/3109

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     - Make sure the PR title start w/ a JIRA ticket, e.g. '[CELEBORN-XXXX] Your PR title ...'.
     - Be sure to keep the PR description updated to reflect all changes.
     - Please write your PR title to summarize what this PR proposes.
     - If possible, provide a concise example to reproduce the issue for a faster review.
   -->
   
   ### What changes were proposed in this pull request?
   
   
   
   ### Why are the changes needed?
   
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   
   
   ### How was this patch tested?
   
   


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2094534868


##########
tests/spark-it/src/test/scala/org/apache/spark/SparkContextHelper.scala:
##########
@@ -18,6 +18,7 @@
 package org.apache.spark
 
 object SparkContextHelper {
+

Review Comment:
   nit: unnecessary change



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "FMX (via GitHub)" <gi...@apache.org>.
FMX commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2002715218


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]

Review Comment:
   Why do you record all cleaned shuffle IDs? Looks like there is no cleaning for this set. This will be a problem for the long-running applications like spark thrift server.



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(
+      celebornShuffleId: Int,
+      appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = appShuffleIdentifier.split('-')
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (pastAppShuffleIdentifier, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          val Array(_, stageId, attemptId) = pastAppShuffleIdentifier.split('-')
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    lifecycleManager.compareAndSet(null, ref)
+  }
+
+  private def noRunningDownstreamStage(shuffleId: Int): Boolean = {
+    val allReferringStageIds = celebornShuffleIdToReferringStages.get(shuffleId)
+    require(allReferringStageIds != null, s"no stage referring to shuffle $shuffleId")
+    val ret =
+      allReferringStageIds.count(stageId => runningStageManager.isRunningStage(stageId)) == 0
+    if (ret) {
+      logInfo(s"no running downstream stages refers to $shuffleId")
+    } else {
+      logInfo(s"there is more than one running downstream stage referring to shuffle $shuffleId," +
+        s" ignore it for cleanup ")
+    }
+    ret
+  }
+
+  private val cleanerThread = new Thread() {

Review Comment:
   Can be replaced by `newDaemonSingleThreadScheduledExecutor` and `scheduleWithFixedDelay`.



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(
+      celebornShuffleId: Int,
+      appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = appShuffleIdentifier.split('-')
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (pastAppShuffleIdentifier, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          val Array(_, stageId, attemptId) = pastAppShuffleIdentifier.split('-')
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    lifecycleManager.compareAndSet(null, ref)
+  }
+
+  private def noRunningDownstreamStage(shuffleId: Int): Boolean = {

Review Comment:
   The input parameter should be celebornShuffleId.



##########
client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala:
##########
@@ -1815,6 +1820,17 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
     appShuffleTrackerCallback = Some(callback)
   }
 
+  // expecting celeborn shuffle id and application shuffle identifier
+  @volatile private var getShuffleIdForWriterCallback: Option[BiConsumer[Integer, String]] = None
+  def registerGetShuffleIdForWriterCallback(callback: BiConsumer[Integer, String]): Unit = {
+    getShuffleIdForWriterCallback = Some(callback)
+  }
+  // expecting celeborn shuffle id and application shuffle identifier
+  @volatile private var getShuffleIdForReaderCallback: Option[BiConsumer[Integer, String]] = None

Review Comment:
   ```suggestion
     @volatile private var recordShuffleIdReference: Option[BiConsumer[Integer, String]] = None
   ```



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(
+      celebornShuffleId: Int,
+      appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = appShuffleIdentifier.split('-')
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (pastAppShuffleIdentifier, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          val Array(_, stageId, attemptId) = pastAppShuffleIdentifier.split('-')
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    lifecycleManager.compareAndSet(null, ref)
+  }
+
+  private def noRunningDownstreamStage(shuffleId: Int): Boolean = {
+    val allReferringStageIds = celebornShuffleIdToReferringStages.get(shuffleId)
+    require(allReferringStageIds != null, s"no stage referring to shuffle $shuffleId")
+    val ret =
+      allReferringStageIds.count(stageId => runningStageManager.isRunningStage(stageId)) == 0
+    if (ret) {
+      logInfo(s"no running downstream stages refers to $shuffleId")
+    } else {
+      logInfo(s"there is more than one running downstream stage referring to shuffle $shuffleId," +
+        s" ignore it for cleanup ")
+    }
+    ret
+  }
+
+  private val cleanerThread = new Thread() {

Review Comment:
   Here can be more parameters to change to clean failed shuffle interval.



##########
client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala:
##########
@@ -1815,6 +1820,17 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
     appShuffleTrackerCallback = Some(callback)
   }
 
+  // expecting celeborn shuffle id and application shuffle identifier
+  @volatile private var getShuffleIdForWriterCallback: Option[BiConsumer[Integer, String]] = None

Review Comment:
   ```suggestion
     @volatile private var validateCelebornShuffleIdForClean: Option[BiConsumer[Integer, String]] = None
   ```



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(
+      celebornShuffleId: Int,
+      appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = appShuffleIdentifier.split('-')
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (pastAppShuffleIdentifier, (celebornShuffleId, _)) => {

Review Comment:
   You have skipped the input parameter of `celebornShuffleId`. 



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(
+      celebornShuffleId: Int,
+      appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = appShuffleIdentifier.split('-')
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (pastAppShuffleIdentifier, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          val Array(_, stageId, attemptId) = pastAppShuffleIdentifier.split('-')

Review Comment:
   Unused definition.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "FMX (via GitHub)" <gi...@apache.org>.
FMX commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2002776133


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()

Review Comment:
   ```suggestion
       ConcurrentHashMap.newKeySet[Int]()
   ```
   This can remove the synchronized block.



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()

Review Comment:
   ```suggestion
       ConcurrentHashMap.newKeySet[Int]()
   ```
   This can remove the synchronized block.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2839075059

   @YutingWang98 taking a look for the upstream version?


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067968447


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   could you cover it likes SparkUtilsSuite?
   
   by checking the runningStages is not empty



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2844012878

   
   
   > I meant, why check for running stages, etc - we know it is going to fail- always abandon/delete ?
   
   this is a good question, there are some corner cases we need to consider
   
   e.g. stage 0, 1, 2, 
   
   0 -> 1, 0-> 2
   
   after stage 2 finished reading some partitions of 0, 1 failed to fetch the same partitions, in this case, we should not delete shuffle output from stage 0, if 2 is still running, since there is possibility that 2 can continue reading without any problem
   
   
   but if 2 is not running, we can safely delete shuffle 0,
   
   but if shuffle 0 is failed to be fetched because commit failure, then we can safely delete it as well since both 1 and 2 will eventually fail
   


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2098383322


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/fetch/failure/FetchFailureTestBase.scala:
##########
@@ -57,7 +58,7 @@ private[tests] trait FetchFailureTestBase extends SparkTestBase {
       if (enableFailedShuffleCleaner) {
         baseBuilder.config("spark.celeborn.client.spark.fetch.cleanFailedShuffle", "true")
       } else {
-        baseBuilder
+        baseBuilder.config("spark.celeborn.client.spark.stageRerun.enabled", "false")

Review Comment:
   In fact, this config is usually true.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2098322513


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -86,13 +76,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
 
   test("celeborn spark integration test - unregister shuffle with throwsFetchFailure disabled") {
     if (Spark3OrNewer) {
-      val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
-      val sparkSession = SparkSession.builder()
-        .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
-        .config("spark.sql.shuffle.partitions", 2)
-        .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
-        .config("spark.celeborn.client.spark.stageRerun.enabled", "false")

Review Comment:
   I recommend to revert the refactor the test module to prevent mistake. 



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "YutingWang98 (via GitHub)" <gi...@apache.org>.
YutingWang98 commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2839709003

   > @YutingWang98 taking a look for the upstream version?
   
   Thanks! lgtm


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2840457908

   gentle ping @FMX 


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069206171


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFailedDiskCleanUtils.scala:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.tests.spark
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+
+import org.apache.celeborn.common.protocol.ShuffleMode
+import org.apache.celeborn.spark.FailedShuffleCleaner
+
+class CelebornFailedDiskCleanUtils extends SparkTestBase {
+  test("test correctness of RunningStageManager") {
+    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
+    val sparkSession = SparkSession.builder()
+      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
+      .config("spark.sql.shuffle.partitions", 2)
+      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
+      .config("spark.celeborn.client.spark.fetch.throwsFetchFailure", "true")
+      .config(
+        "spark.shuffle.manager",
+        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
+      .getOrCreate()
+    val t = new Thread {
+      override def run(): Unit = {
+        try {
+          sparkSession.sparkContext.parallelize(List(1, 2, 3)).foreach(_ =>
+            Thread.sleep(60 * 1000))
+        } catch {
+          case _: Throwable =>
+          // swallow everything
+        }
+      }
+    }
+    t.start()
+    Thread.sleep(20 * 1000)

Review Comment:
   then you can remove `Thread.sleep(20 * 1000)`.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2065461936


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.spark
+
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.shuffle.celeborn.{RunningStageManagerImpl, SparkCommonUtils}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    val Array(_, stageId, _) = SparkCommonUtils.decodeAppShuffleIdentifier(appShuffleIdentifier)
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int])
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean =
+    lock.synchronized {
+      val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+        celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+      if (ret) {
+        logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+      }
+      ret
+    }
+
+  def addShuffleIdToBeCleaned(appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = SparkCommonUtils.decodeAppShuffleIdentifier(
+      appShuffleIdentifier)
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (_, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    val firstSet = lifecycleManager.compareAndSet(null, ref)
+    if (firstSet) {
+      cleanerThreadPool.scheduleWithFixedDelay(
+        new Runnable {
+          override def run(): Unit = {
+            val allShuffleIds = new util.ArrayList[Int]
+            shufflesToBeCleand.drainTo(allShuffleIds)
+            allShuffleIds.asScala.foreach { shuffleId =>
+              if (!cleanedShuffleIds.contains(shuffleId)) {
+                lifecycleManager.get().unregisterShuffle(shuffleId)
+                logInfo(
+                  s"sent unregister shuffle request for shuffle $shuffleId (celeborn shuffle id)")
+                cleanedShuffleIds += shuffleId
+              }
+            }
+          }
+        },
+        cleanInterval,
+        cleanInterval,
+        TimeUnit.MILLISECONDS)
+    }
+  }
+
+  def removeCleanedShuffleId(celebornShuffleId: Int): Unit = {
+    cleanedShuffleIds.remove(celebornShuffleId)
+  }
+
+  private def noRunningDownstreamStage(celebornShuffleId: Int): Boolean = lock.synchronized {
+    val allReferringStageIds = celebornShuffleIdToReferringStages.get(celebornShuffleId)
+    require(allReferringStageIds != null, s"no stage referring to shuffle $celebornShuffleId")
+    val ret =
+      allReferringStageIds.count(stageId => runningStageManager.isRunningStage(stageId)) == 0
+    if (ret) {
+      logInfo(s"no running downstream stages refers to $celebornShuffleId")
+    } else {
+      logInfo(
+        s"there is more than one running downstream stage referring to shuffle $celebornShuffleId," +
+          s" ignore it for cleanup ")
+    }
+    ret
+  }
+
+  private var cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+    "failedShuffleCleanerThreadPool")

Review Comment:
   updated



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.spark
+
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.shuffle.celeborn.{RunningStageManagerImpl, SparkCommonUtils}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    val Array(_, stageId, _) = SparkCommonUtils.decodeAppShuffleIdentifier(appShuffleIdentifier)
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int])
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean =
+    lock.synchronized {
+      val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+        celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+      if (ret) {
+        logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+      }
+      ret
+    }
+
+  def addShuffleIdToBeCleaned(appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = SparkCommonUtils.decodeAppShuffleIdentifier(
+      appShuffleIdentifier)
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (_, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    val firstSet = lifecycleManager.compareAndSet(null, ref)
+    if (firstSet) {
+      cleanerThreadPool.scheduleWithFixedDelay(
+        new Runnable {
+          override def run(): Unit = {
+            val allShuffleIds = new util.ArrayList[Int]
+            shufflesToBeCleand.drainTo(allShuffleIds)
+            allShuffleIds.asScala.foreach { shuffleId =>
+              if (!cleanedShuffleIds.contains(shuffleId)) {
+                lifecycleManager.get().unregisterShuffle(shuffleId)
+                logInfo(
+                  s"sent unregister shuffle request for shuffle $shuffleId (celeborn shuffle id)")
+                cleanedShuffleIds += shuffleId
+              }

Review Comment:
   updated



##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private final Field idField;
+
+  public RunningStageManagerImpl()
+      throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
+    Class<?> stageClass = Class.forName("org.apache.spark.scheduler.Stage");
+    idField = stageClass.getDeclaredField("id");
+    idField.setAccessible(true);
+  }
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      Class<?> dagSchedulerClz = SparkContext$.MODULE$.getActive().get().dagScheduler().getClass();
+      Field runningStagesField = dagSchedulerClz.getDeclaredField("runningStages");

Review Comment:
   updated



##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private final Field idField;
+
+  public RunningStageManagerImpl()
+      throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
+    Class<?> stageClass = Class.forName("org.apache.spark.scheduler.Stage");
+    idField = stageClass.getDeclaredField("id");
+    idField.setAccessible(true);

Review Comment:
   updated



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2065461714


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.spark
+
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.shuffle.celeborn.{RunningStageManagerImpl, SparkCommonUtils}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(

Review Comment:
   updated



##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java:
##########
@@ -150,13 +151,34 @@ private void initializeLifecycleManager(String appId) {
 
             lifecycleManager.registerShuffleTrackerCallback(
                 shuffleId -> SparkUtils.unregisterAllMapOutput(mapOutputTracker, shuffleId));
-

Review Comment:
   updated



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2094532010


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -331,19 +264,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
   }
 
   test(s"celeborn spark integration test - resubmit a failed barrier stage across jobs") {
-    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2]")
-    val sparkSession = SparkSession.builder()
-      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
-      .config("spark.sql.shuffle.partitions", 2)
-      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
-      .config("spark.celeborn.client.spark.stageRerun.enabled", "true")
-      .config("spark.celeborn.client.push.buffer.max.size", 0)
-      .config("spark.stage.maxConsecutiveAttempts", "1")
-      .config("spark.stage.maxAttempts", "1")
-      .config(
-        "spark.shuffle.manager",
-        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
-      .getOrCreate()
+    val sparkSession = createSparkSession(overrideShuffleMgr = false)

Review Comment:
   ```suggestion
       val sparkSession = createSparkSession()
   ```



##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -25,14 +25,15 @@ import org.apache.spark.celeborn.ExceptionMakerHelper
 import org.apache.spark.rdd.RDD
 import org.apache.spark.shuffle.celeborn.{SparkShuffleManager, SparkUtils, TestCelebornShuffleManager}
 import org.apache.spark.sql.SparkSession
-import org.scalatest.BeforeAndAfterEach
+import org.scalatest.{BeforeAndAfterEach, Ignore}

Review Comment:
   NIT: seems unnecessary change



##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -285,17 +228,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
   }
 
   test(s"celeborn spark integration test - fetch failure in child of an unordered barrier stage with throwsFetchFailure enabled") {
-    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2]")
-    val sparkSession = SparkSession.builder()
-      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
-      .config("spark.sql.shuffle.partitions", 2)
-      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
-      .config("spark.celeborn.client.spark.stageRerun.enabled", "true")
-      .config("spark.celeborn.client.push.buffer.max.size", 0)
-      .config(
-        "spark.shuffle.manager",
-        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
-      .getOrCreate()
+    val sparkSession = createSparkSession(overrideShuffleMgr = false)

Review Comment:
   ```suggestion
       val sparkSession = createSparkSession()
   ```



##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -241,17 +194,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
   }
 
   test(s"celeborn spark integration test - resubmit an unordered barrier stage with throwsFetchFailure enabled") {
-    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2]")
-    val sparkSession = SparkSession.builder()
-      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
-      .config("spark.sql.shuffle.partitions", 2)
-      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
-      .config("spark.celeborn.client.spark.stageRerun.enabled", "true")
-      .config("spark.celeborn.client.push.buffer.max.size", 0)
-      .config(
-        "spark.shuffle.manager",
-        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
-      .getOrCreate()
+    val sparkSession = createSparkSession(overrideShuffleMgr = false)

Review Comment:
   ```suggestion
       val sparkSession = createSparkSession()
   ```



##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/fetch/failure/FetchFailureTestBase.scala:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.tests.spark.fetch.failure
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+
+import org.apache.celeborn.common.protocol.ShuffleMode
+import org.apache.celeborn.tests.spark.SparkTestBase
+
+private[tests] trait FetchFailureTestBase extends SparkTestBase {
+
+  def createSparkSession(
+      overrideShuffleMgr: Boolean = true,
+      enableFailedShuffleCleaner: Boolean = false,
+      enableCustomizedRunningStageMgr: Boolean = false): SparkSession = {

Review Comment:
   seems you can remove this flag



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2052721896


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')

Review Comment:
   sure, moved 



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2052721530


##########
client-spark/common/src/main/scala/org/apache/spark/scheduler/RunningStageManager.scala:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.spark.scheduler
+
+import org.apache.spark.SparkContext
+
+trait RunningStageManager {
+  def isRunningStage(stageId: Int): Boolean
+}
+
+class RunningStageManagerImpl extends RunningStageManager {
+  private def dagScheduler = SparkContext.getActive.get.dagScheduler
+  override def isRunningStage(stageId: Int): Boolean = {
+    dagScheduler.runningStages.map(_.id).contains(stageId)

Review Comment:
   sounds reasonable, changed 



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2062834788


##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -4750,6 +4753,23 @@ object CelebornConf extends Logging {
       .booleanConf
       .createWithDefault(true)
 
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE: ConfigEntry[Boolean] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffle")
+      .categories("client")
+      .version("0.6.0")
+      .doc("whether to clean those disk space occupied by shuffles which cannot be fetched")
+      .booleanConf
+      .createWithDefault(false)
+
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE_INTERVAL: ConfigEntry[Long] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffleIntervalMs")
+      .categories("client")
+      .version("0.6.0")
+      .doc("the interval to clean the failed-to-fetch shuffle files, only valid when" +
+        s" ${CLIENT_FETCH_CLEAN_FAILED_SHUFFLE.key} is enabled")
+      .longConf

Review Comment:
   ```  
       .timeConf(TimeUnit.MILLISECONDS)
   ```



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2843609234

   > the current failed test probably is just the spark job somehow runs slower than expected in this case
   
   
   Could you try to enhance it to prevent it became a flaky test after merged?


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2843488213

   Maybe need to reset the `FailedShuffleCleaner` before each test.


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069741826


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import scala.collection.JavaConverters;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField id_FIELD =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+  private static final DynFields.UnboundField runningStages_FIELD =
+      DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      return new HashSet<>(
+          JavaConverters.asJavaCollectionConverter(
+                  (scala.collection.mutable.HashSet<?>)
+                      runningStages_FIELD.bind(dagScheduler).get())
+              .asJavaCollection());

Review Comment:
   do you have any suggestion to access runningStage information?
   
   



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2816220931

   @FMX @RexXiong thank you for the review, I addressed the comments, would you please take another look?


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045886083


##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java:
##########
@@ -606,4 +608,22 @@ public static void invalidateSerializedGetReducerFileGroupResponse(Integer shuff
           return null;
         });
   }
+
+  public static void addWriterShuffleIdsToBeCleaned(
+      LifecycleManager lifecycleManager, String appShuffleIdentifier) {
+    FailedShuffleCleaner.setLifecycleManager(lifecycleManager);
+    FailedShuffleCleaner.addShuffleIdToBeCleaned(appShuffleIdentifier);
+  }
+
+  public static void addShuffleIdRefCount(
+      LifecycleManager lifecycleManager, int celebornShuffeId, String appShuffleIdentifier) {

Review Comment:
   oops, fixed



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045883119


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')

Review Comment:
   you mean make it as a method of SparkUtils? 
   
   we may not be able to do that since SparkUtils is a spark version specific class, but for the reason mentioned above, FailedShuffleCleaner has to be in spark-common



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045880494


##########
client-spark/common/src/main/scala/org/apache/spark/scheduler/RunningStageManager.scala:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.spark.scheduler

Review Comment:
   yes, we need to access runningStages in DAGScheduler which is a private[scheduler] variable



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045877447


##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java:
##########
@@ -150,13 +150,26 @@ private void initializeLifecycleManager(String appId) {
 
             lifecycleManager.registerShuffleTrackerCallback(
                 shuffleId -> SparkUtils.unregisterAllMapOutput(mapOutputTracker, shuffleId));
-
             if (celebornConf.clientAdaptiveOptimizeSkewedPartitionReadEnabled()) {
               lifecycleManager.registerCelebornSkewShuffleCheckCallback(
                   SparkUtils::isCelebornSkewShuffleOrChildShuffle);
             }
           }
 
+          if (lifecycleManager.conf().clientFetchCleanFailedShuffle()) {
+            lifecycleManager.registerValidateCelebornShuffleIdForCleanCallback(

Review Comment:
   yes, you are right, added the check to ensure that stage rerun is enabled when this feature is turned on



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069206171


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFailedDiskCleanUtils.scala:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.tests.spark
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+
+import org.apache.celeborn.common.protocol.ShuffleMode
+import org.apache.celeborn.spark.FailedShuffleCleaner
+
+class CelebornFailedDiskCleanUtils extends SparkTestBase {
+  test("test correctness of RunningStageManager") {
+    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
+    val sparkSession = SparkSession.builder()
+      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
+      .config("spark.sql.shuffle.partitions", 2)
+      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
+      .config("spark.celeborn.client.spark.fetch.throwsFetchFailure", "true")
+      .config(
+        "spark.shuffle.manager",
+        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
+      .getOrCreate()
+    val t = new Thread {
+      override def run(): Unit = {
+        try {
+          sparkSession.sparkContext.parallelize(List(1, 2, 3)).foreach(_ =>
+            Thread.sleep(60 * 1000))
+        } catch {
+          case _: Throwable =>
+          // swallow everything
+        }
+      }
+    }
+    t.start()
+    Thread.sleep(20 * 1000)

Review Comment:
   then you can remove `Thread.sleep(20 * 1000)` to save the UT time.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067968447


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   could you cover it likes SparkUtilsSuite?
   
   by checking the runningStages is not empty
   
   it is necessary because we use reflection, need to confirm its compatibility across different spark versions



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2887916542

   i removed some tests from the PR as they are pretty flaky in github CI even tho they have been running internally for months without issues , and I cannot reproduce the failures in my laptop
   
   the current failures not really related to my PR


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2098308433


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -86,13 +76,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
 
   test("celeborn spark integration test - unregister shuffle with throwsFetchFailure disabled") {
     if (Spark3OrNewer) {
-      val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
-      val sparkSession = SparkSession.builder()
-        .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
-        .config("spark.sql.shuffle.partitions", 2)
-        .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
-        .config("spark.celeborn.client.spark.stageRerun.enabled", "false")

Review Comment:
   Some UT has special config, for this UT, it is `spark.celeborn.client.spark.stageRerun.enabled=true`.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2062835069


##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -4750,6 +4753,23 @@ object CelebornConf extends Logging {
       .booleanConf
       .createWithDefault(true)
 
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE: ConfigEntry[Boolean] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffle")
+      .categories("client")
+      .version("0.6.0")
+      .doc("whether to clean those disk space occupied by shuffles which cannot be fetched")
+      .booleanConf
+      .createWithDefault(false)
+
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE_INTERVAL: ConfigEntry[Long] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffleIntervalMs")

Review Comment:
   ```
   celeborn.client.spark.fetch.cleanFailedShuffleInterval
   ```
   
   



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2062847650


##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -4750,6 +4753,23 @@ object CelebornConf extends Logging {
       .booleanConf
       .createWithDefault(true)
 
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE: ConfigEntry[Boolean] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffle")
+      .categories("client")
+      .version("0.6.0")
+      .doc("whether to clean those disk space occupied by shuffles which cannot be fetched")
+      .booleanConf
+      .createWithDefault(false)
+
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE_INTERVAL: ConfigEntry[Long] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffleIntervalMs")
+      .categories("client")
+      .version("0.6.0")
+      .doc("the interval to clean the failed-to-fetch shuffle files, only valid when" +
+        s" ${CLIENT_FETCH_CLEAN_FAILED_SHUFFLE.key} is enabled")
+      .longConf

Review Comment:
   sure, updated



##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -4750,6 +4753,23 @@ object CelebornConf extends Logging {
       .booleanConf
       .createWithDefault(true)
 
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE: ConfigEntry[Boolean] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffle")
+      .categories("client")
+      .version("0.6.0")
+      .doc("whether to clean those disk space occupied by shuffles which cannot be fetched")
+      .booleanConf
+      .createWithDefault(false)
+
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE_INTERVAL: ConfigEntry[Long] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffleIntervalMs")

Review Comment:
   updated



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2843614387

   And `eventually` method is very helpful to fix the flaky tests.
   
   


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2843463956

   Test failure: https://github.com/apache/celeborn/actions/runs/14764090095/job/41451517521?pr=3109 
   ```
   [info] - celeborn spark integration test - (M-1 dep with single level lineage) the single failed shuffle file is cleaned up correctly *** FAILED ***
   [info]   java.lang.IllegalStateException: the storage checking status failed,true NULL
   [info]   at org.apache.celeborn.tests.spark.fetch_failure.FetchFailureDiskCleanBase.checkStorageValidation(FetchFailureDiskCleanBase.scala:149)
   [info]   at org.apache.celeborn.tests.spark.fetch_failure.FetchFailureDiskCleanBase.checkStorageValidation$(FetchFailureDiskCleanBase.scala:143)
   [info]   at org.apache.celeborn.tests.spark.CelebornFetchFailureDiskCleanSuite.checkStorageValidation(CelebornFetchFailureDiskCleanSuite.scala:26)
   [info]   at org.apache.celeborn.tests.spark.CelebornFetchFailureDiskCleanSuite.$anonfun$new$9(CelebornFetchFailureDiskCleanSuite.scala:106)
   [info]   at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
   [info]   at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
   [info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
   [info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
   [info]   at org.scalatest.Transformer.apply(Transformer.scala:20)
   [info]   at org.scalatest.funsuite.AnyFunSuiteLike$$anon$1.apply(AnyFunSuiteLike.scala:226)
   [info]   at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
   [info]   at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
   [info]   at org.scalatest.funsuite.AnyFunSuite.withFixture(AnyFunSuite.scala:1564)
   [info]   at org.scalatest.funsuite.AnyFunSuiteLike.invokeWithFixture$1(AnyFunSuiteLike.scala:224)
   [info]   at org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTest$1(AnyFunSuiteLike.scala:236)
   [info]   at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
   [info]   at org.scalatest.funsuite.AnyFunSuiteLike.runTest(AnyFunSuiteLike.scala:236)
   [info]   at org.scalatest.funsuite.AnyFunSuiteLike.runTest$(AnyFunSuiteLike.scala:218)
   ```


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2846294575

   What I meant was, we can simplify the code to not need to deal with running stage, etc.
   I have not validated/tested it - but this is along the lines of what I was thinking: https://github.com/mridulm/celeborn/commit/d060c293b07af806d42656142eeff3c5984b0806
   
   (Note, this is just to illustrate the idea)


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "FMX (via GitHub)" <gi...@apache.org>.
FMX commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2041315127


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()

Review Comment:
   We have a misunderstanding here, I mean that you should use ConcurrentHashMap.newKeySet[Int] as the value type of the ConcurrentHashMap. This could remove the synchronization block.
   
   `new ConcurrentHashMap[Int,ConcurrentHashMap[Int,Boolean]]`
   



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()

Review Comment:
   Ditto.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2098295069


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -86,13 +76,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
 
   test("celeborn spark integration test - unregister shuffle with throwsFetchFailure disabled") {
     if (Spark3OrNewer) {
-      val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
-      val sparkSession = SparkSession.builder()
-        .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
-        .config("spark.sql.shuffle.partitions", 2)
-        .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
-        .config("spark.celeborn.client.spark.stageRerun.enabled", "false")

Review Comment:
   The UT is broken. @CodingCat 



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045886798


##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java:
##########
@@ -165,6 +178,19 @@ private void initializeLifecycleManager(String appId) {
             lifecycleManager.registerInvalidatedBroadcastCallback(
                 shuffleId -> SparkUtils.invalidateSerializedGetReducerFileGroupResponse(shuffleId));
           }
+          if (lifecycleManager.conf().clientFetchCleanFailedShuffle()) {

Review Comment:
   oops, some merge error, fixed



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067623743


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   for being safe, I converted to the exact type 



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045886674


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())

Review Comment:
   ah, as mentioned at https://github.com/apache/celeborn/pull/3109#discussion_r2045872620, I found I still need an explicit lock over this HashSet, so ConcurrentHashSet may not help here



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067586645


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   https://github.com/apache/spark/blob/54eb1a2f863bd7d8706c5c9a568895adb026c78d/core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala#L29
   
   https://github.com/apache/spark/blob/54eb1a2f863bd7d8706c5c9a568895adb026c78d/core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala#L166C46-L166C53
   
   Here the `runningStages` type is `scala.collection.mutable.HashSet` instead of `java.util.HashSet`, would it be a problem?



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067586645


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   https://github.com/apache/spark/blob/54eb1a2f863bd7d8706c5c9a568895adb026c78d/core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala#L29
   
   https://github.com/apache/spark/blob/54eb1a2f863bd7d8706c5c9a568895adb026c78d/core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala#L166C46-L166C53
   
   Here the `runningStages` type is `scala.collection.mutable.HashSet`, would it be a problem?



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2840457495

   Left some comments in https://github.com/CodingCat/incubator-celeborn/pull/1
   


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069205894


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFailedDiskCleanUtils.scala:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.tests.spark
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+
+import org.apache.celeborn.common.protocol.ShuffleMode
+import org.apache.celeborn.spark.FailedShuffleCleaner
+
+class CelebornFailedDiskCleanUtils extends SparkTestBase {
+  test("test correctness of RunningStageManager") {
+    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
+    val sparkSession = SparkSession.builder()
+      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
+      .config("spark.sql.shuffle.partitions", 2)
+      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
+      .config("spark.celeborn.client.spark.fetch.throwsFetchFailure", "true")
+      .config(
+        "spark.shuffle.manager",
+        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
+      .getOrCreate()
+    val t = new Thread {
+      override def run(): Unit = {
+        try {
+          sparkSession.sparkContext.parallelize(List(1, 2, 3)).foreach(_ =>
+            Thread.sleep(60 * 1000))
+        } catch {
+          case _: Throwable =>
+          // swallow everything
+        }
+      }
+    }
+    t.start()
+    Thread.sleep(20 * 1000)

Review Comment:
   ```
   eventually(timeout(20.seconds), interval(0.milliseconds))  {
     ...
   }
   
   sparkSession.sparkContext.cancelAllJobs()
   
   t.interrupt()
   ```
   
   



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2843635270

   > > the current failed test probably is just the spark job somehow runs slower than expected in this case
   > 
   > Could you try to enhance it to prevent it became a flaky test after merged?
   > 
   > And the current error info is hard to read.
   
   sure, will follow up on this


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2868957324

   the major issue of the test is that somehow it keeps falling into heap OOM or long GC leading to spark job too slow, I tried to increase spark.driver.memory but the issue still there


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045885759


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(appShuffleIdentifier: String): Unit = {

Review Comment:
   I used method at https://github.com/apache/celeborn/pull/3109/files#diff-b7440adf323f1a6c564d55c9c18a414c0a1a2039b5babf1657172c6d0c68c17fR116 to achieve this



##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java:
##########
@@ -606,4 +608,22 @@ public static void invalidateSerializedGetReducerFileGroupResponse(Integer shuff
           return null;
         });
   }
+
+  public static void addWriterShuffleIdsToBeCleaned(
+      LifecycleManager lifecycleManager, String appShuffleIdentifier) {
+    FailedShuffleCleaner.setLifecycleManager(lifecycleManager);
+    FailedShuffleCleaner.addShuffleIdToBeCleaned(appShuffleIdentifier);
+  }
+
+  public static void addShuffleIdRefCount(

Review Comment:
   renamed



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045879584


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {

Review Comment:
   the reason is that, spark-it refers to FailedShuffleCleaner, if we move it to spark-3, spark-it won't compile against spark-2...



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067967131


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   because the code in this class is not covered by UT



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2098387212


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -86,13 +76,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
 
   test("celeborn spark integration test - unregister shuffle with throwsFetchFailure disabled") {

Review Comment:
   The current abstraction of `createSparkSession` is not generic and hard to extend.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2094520600


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/fetch/failure/FetchFailureTestBase.scala:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.tests.spark.fetch.failure
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+
+import org.apache.celeborn.common.protocol.ShuffleMode
+import org.apache.celeborn.tests.spark.SparkTestBase
+
+private[tests] trait FetchFailureTestBase extends SparkTestBase {
+
+  def createSparkSession(
+      overrideShuffleMgr: Boolean = true,
+      enableFailedShuffleCleaner: Boolean = false,
+      enableCustomizedRunningStageMgr: Boolean = false): SparkSession = {
+    val sparkConf = new SparkConf().setAppName({
+      if (!enableFailedShuffleCleaner) {
+        "fetch-failure"
+      } else {
+        "fetch-failure-failed-shuffle-clean"
+      }
+    }).setMaster("local[*]")
+    var baseBuilder = SparkSession.builder()
+      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
+      .config("spark.sql.shuffle.partitions", 2)
+      .config("spark.driver.memory", "4g")
+      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
+      .config("spark.celeborn.shuffle.enabled", "true")
+      .config("spark.celeborn.client.shuffle.expired.checkInterval", "1s")
+      .config("spark.kryoserializer.buffer.max", "2047m")
+      .config("spark.celeborn.client.spark.fetch.throwsFetchFailure", "true")
+
+    baseBuilder =
+      if (overrideShuffleMgr) {
+        baseBuilder.config(
+          "spark.shuffle.manager",
+          "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
+      } else {
+        baseBuilder
+      }
+    baseBuilder =
+      if (enableFailedShuffleCleaner) {
+        baseBuilder.config("spark.celeborn.client.spark.fetch.cleanFailedShuffle", "true")
+      } else {
+        baseBuilder
+      }
+
+    baseBuilder =
+      if (enableCustomizedRunningStageMgr) {
+        baseBuilder.config(
+          "spark.celeborn.client.spark.fetch.cleanFailedShuffle" +
+            ".runningStageManagerImpl",
+          "org.apache.celeborn.tests.spark.fetch_failure.TestRunningStageManager")

Review Comment:
   seems not used anymore



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069055890


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   I added a specific test for this method
   
   but I think this method was actually covered already, I instrumented the method with System.out.println() , I can see those were printed ... still not sure why it didn't fail



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069714952


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import scala.collection.JavaConverters;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField id_FIELD =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+  private static final DynFields.UnboundField runningStages_FIELD =
+      DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      return new HashSet<>(
+          JavaConverters.asJavaCollectionConverter(
+                  (scala.collection.mutable.HashSet<?>)
+                      runningStages_FIELD.bind(dagScheduler).get())
+              .asJavaCollection());

Review Comment:
   `DAGScheduler` is not designed to be used directly - but from within the event loop.
   Accessing any of its state/data structures outside of the event loop is unsafe.



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)

Review Comment:
   Use `CelebornConf` from `LifeCycleManager` instead of `System.getProperty`



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069321077


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFailedDiskCleanUtils.scala:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.tests.spark
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+
+import org.apache.celeborn.common.protocol.ShuffleMode
+import org.apache.celeborn.spark.FailedShuffleCleaner
+
+class CelebornFailedDiskCleanUtils extends SparkTestBase {
+  test("test correctness of RunningStageManager") {
+    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
+    val sparkSession = SparkSession.builder()
+      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
+      .config("spark.sql.shuffle.partitions", 2)
+      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
+      .config("spark.celeborn.client.spark.fetch.throwsFetchFailure", "true")
+      .config(
+        "spark.shuffle.manager",
+        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
+      .getOrCreate()
+    val t = new Thread {
+      override def run(): Unit = {
+        try {
+          sparkSession.sparkContext.parallelize(List(1, 2, 3)).foreach(_ =>
+            Thread.sleep(60 * 1000))
+        } catch {
+          case _: Throwable =>
+          // swallow everything
+        }
+      }
+    }
+    t.start()
+    Thread.sleep(20 * 1000)

Review Comment:
   updated



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2843998679

   I meant, why check for running stages, etc - we know it is going to fail- always abandon/delete ?


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "RexXiong (via GitHub)" <gi...@apache.org>.
RexXiong commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2829803094

   Thanks @CodingCat  I left some comments, please take a look when you have time.


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2840435609

   @turboFei thanks for the review! anything else I need to address?


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2844097622

   > Given this applies to indeterminate stages (and not determinate stages), in the scenario presented where stage 0 is indeterminate - we must recompute stage 2 when stage 1 suffers from a fetch failure : else the data fetched for stage 1, when stage 0.1 runs - will no longer be consistent with what was already fetched for stage 2.
   > 
   > A variant of this is discussed here: [apache/spark#50630](https://github.com/apache/spark/pull/50630) (unfortunately a long discussion).
   > 
   > Spark 4.1 will end up enforcing this for its own shuffle - for Apache Celeborn, we will need to do something similar (I have not brought this up, as the PR is not yet merged to Apache Spark :) )
   > 
   > Do let me know if I am misunderstanding the scenario !
   
   I think you are right, great insight!
   
   I just added the code to handle indeterministic cases as well as the test


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067601381


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   good catch, I am pretty surprised that it didn't fail.....



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2847409495

   > What I meant was, we can simplify the code to not need to deal with running stage, etc.
   > 
   > I have not validated/tested it - but this is along the lines of what I was thinking: https://github.com/mridulm/celeborn/commit/d060c293b07af806d42656142eeff3c5984b0806
   > 
   > 
   > 
   > (Note, this is just to illustrate the idea ... unfortunately I dont have bandwidth to complete it, so wanted to share it to help convey my idea better)
   
   i am not sure if it is the right direction to go, we already know for determinant stages we should not fail/restart certain stages in some scenario, why we fallback to a compromised solution?
   
   for indeterminate ones, since in 4.1 it will be aligned with the current version of PR, the PR just makes it future proof 


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2098382847


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/fetch/failure/FetchFailureTestBase.scala:
##########
@@ -57,7 +58,7 @@ private[tests] trait FetchFailureTestBase extends SparkTestBase {
       if (enableFailedShuffleCleaner) {
         baseBuilder.config("spark.celeborn.client.spark.fetch.cleanFailedShuffle", "true")
       } else {
-        baseBuilder
+        baseBuilder.config("spark.celeborn.client.spark.stageRerun.enabled", "false")

Review Comment:
   it is not generic



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2895671223

   @turboFei I think now the code is in a better shape and test also seems stablized


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045876063


##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java:
##########
@@ -150,13 +150,26 @@ private void initializeLifecycleManager(String appId) {
 
             lifecycleManager.registerShuffleTrackerCallback(
                 shuffleId -> SparkUtils.unregisterAllMapOutput(mapOutputTracker, shuffleId));
-
             if (celebornConf.clientAdaptiveOptimizeSkewedPartitionReadEnabled()) {
               lifecycleManager.registerCelebornSkewShuffleCheckCallback(
                   SparkUtils::isCelebornSkewShuffleOrChildShuffle);
             }
           }
 
+          if (lifecycleManager.conf().clientFetchCleanFailedShuffle()) {

Review Comment:
   oops, some merge error, fixed



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "RexXiong (via GitHub)" <gi...@apache.org>.
RexXiong commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2041361661


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())

Review Comment:
   should be ConcurrentSet?



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045878339


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {

Review Comment:
   hmm, the reset is mainly for testing at this moment, since it reinitializes the thread pool , it might be a bit weird if we call it in non-test code?



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2045872620


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()

Review Comment:
   actually I found I still need an explicit lock there , e.g. https://github.com/apache/celeborn/pull/3109/files#diff-b7440adf323f1a6c564d55c9c18a414c0a1a2039b5babf1657172c6d0c68c17fR144-R157 operations here cannot be thread safe only with ConcurrentHashMap.KeyView, 



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "FMX (via GitHub)" <gi...@apache.org>.
FMX closed pull request #3109: [CELEBORN-1896] delete data from failed to fetch shuffles
URL: https://github.com/apache/celeborn/pull/3109


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2098308433


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -86,13 +76,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
 
   test("celeborn spark integration test - unregister shuffle with throwsFetchFailure disabled") {
     if (Spark3OrNewer) {
-      val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
-      val sparkSession = SparkSession.builder()
-        .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
-        .config("spark.sql.shuffle.partitions", 2)
-        .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
-        .config("spark.celeborn.client.spark.stageRerun.enabled", "false")

Review Comment:
   Some UT has special config, for this UT, it is `spark.celeborn.client.spark.stageRerun.enabled=false`.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "RexXiong (via GitHub)" <gi...@apache.org>.
RexXiong commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2041320904


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {

Review Comment:
   FailedShuffleCleaner should reset when sparkShuffleManager call `stop`



##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java:
##########
@@ -150,13 +150,26 @@ private void initializeLifecycleManager(String appId) {
 
             lifecycleManager.registerShuffleTrackerCallback(
                 shuffleId -> SparkUtils.unregisterAllMapOutput(mapOutputTracker, shuffleId));
-
             if (celebornConf.clientAdaptiveOptimizeSkewedPartitionReadEnabled()) {
               lifecycleManager.registerCelebornSkewShuffleCheckCallback(
                   SparkUtils::isCelebornSkewShuffleOrChildShuffle);
             }
           }
 
+          if (lifecycleManager.conf().clientFetchCleanFailedShuffle()) {

Review Comment:
   Duplicate of lines 181-193.



##########
client-spark/common/src/main/scala/org/apache/spark/scheduler/RunningStageManager.scala:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.spark.scheduler

Review Comment:
   Is the package org.apache.spark.scheduler truly necessary in Celeborn?



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {

Review Comment:
   It seems that FailedShuffleCleaner is only used for Spark 3. Why did we place this in the common module?



##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java:
##########
@@ -606,4 +608,22 @@ public static void invalidateSerializedGetReducerFileGroupResponse(Integer shuff
           return null;
         });
   }
+
+  public static void addWriterShuffleIdsToBeCleaned(
+      LifecycleManager lifecycleManager, String appShuffleIdentifier) {
+    FailedShuffleCleaner.setLifecycleManager(lifecycleManager);
+    FailedShuffleCleaner.addShuffleIdToBeCleaned(appShuffleIdentifier);
+  }
+
+  public static void addShuffleIdRefCount(

Review Comment:
   Better rename addShuffleIdRefCount to addShuffleIdReferringStage?



##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java:
##########
@@ -150,13 +150,26 @@ private void initializeLifecycleManager(String appId) {
 
             lifecycleManager.registerShuffleTrackerCallback(
                 shuffleId -> SparkUtils.unregisterAllMapOutput(mapOutputTracker, shuffleId));
-
             if (celebornConf.clientAdaptiveOptimizeSkewedPartitionReadEnabled()) {
               lifecycleManager.registerCelebornSkewShuffleCheckCallback(
                   SparkUtils::isCelebornSkewShuffleOrChildShuffle);
             }
           }
 
+          if (lifecycleManager.conf().clientFetchCleanFailedShuffle()) {
+            lifecycleManager.registerValidateCelebornShuffleIdForCleanCallback(

Review Comment:
   Have you tested the behavior when Celeborn stage rerun is disabled? It seems like the current implementation only takes effect when stage rerun is enabled. So should we enable this only stage rerun enabled?



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(appShuffleIdentifier: String): Unit = {

Review Comment:
   I think daemon thread should check appShuffleIdentifier periodically to ensure timely cleanup of shuffles when conditions are met. Additionally, the appShuffleIdentifier should be cleaned up when the app shuffle expires.



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')

Review Comment:
   Can we put this together with SparkUtils.appShuffleIdentifier



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2064850564


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private final Field idField;
+
+  public RunningStageManagerImpl()
+      throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
+    Class<?> stageClass = Class.forName("org.apache.spark.scheduler.Stage");
+    idField = stageClass.getDeclaredField("id");
+    idField.setAccessible(true);

Review Comment:
   Could you use the `DynFields`, likes: https://github.com/apache/celeborn/blob/a2110568f279c2714600b31e05708b7cb76e9936/client-spark/spark-2/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java#L213-L214



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.spark
+
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.shuffle.celeborn.{RunningStageManagerImpl, SparkCommonUtils}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    val Array(_, stageId, _) = SparkCommonUtils.decodeAppShuffleIdentifier(appShuffleIdentifier)
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int])
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean =
+    lock.synchronized {
+      val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+        celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+      if (ret) {
+        logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+      }
+      ret
+    }
+
+  def addShuffleIdToBeCleaned(appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = SparkCommonUtils.decodeAppShuffleIdentifier(
+      appShuffleIdentifier)
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (_, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    val firstSet = lifecycleManager.compareAndSet(null, ref)
+    if (firstSet) {
+      cleanerThreadPool.scheduleWithFixedDelay(
+        new Runnable {
+          override def run(): Unit = {
+            val allShuffleIds = new util.ArrayList[Int]
+            shufflesToBeCleand.drainTo(allShuffleIds)
+            allShuffleIds.asScala.foreach { shuffleId =>
+              if (!cleanedShuffleIds.contains(shuffleId)) {
+                lifecycleManager.get().unregisterShuffle(shuffleId)
+                logInfo(
+                  s"sent unregister shuffle request for shuffle $shuffleId (celeborn shuffle id)")
+                cleanedShuffleIds += shuffleId
+              }

Review Comment:
   It is better to catch exception in case the scheduler task exit due to unexpected exception.



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.spark
+
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.shuffle.celeborn.{RunningStageManagerImpl, SparkCommonUtils}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    val Array(_, stageId, _) = SparkCommonUtils.decodeAppShuffleIdentifier(appShuffleIdentifier)
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int])
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean =
+    lock.synchronized {
+      val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+        celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+      if (ret) {
+        logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+      }
+      ret
+    }
+
+  def addShuffleIdToBeCleaned(appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = SparkCommonUtils.decodeAppShuffleIdentifier(
+      appShuffleIdentifier)
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (_, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    val firstSet = lifecycleManager.compareAndSet(null, ref)
+    if (firstSet) {
+      cleanerThreadPool.scheduleWithFixedDelay(
+        new Runnable {
+          override def run(): Unit = {
+            val allShuffleIds = new util.ArrayList[Int]
+            shufflesToBeCleand.drainTo(allShuffleIds)
+            allShuffleIds.asScala.foreach { shuffleId =>
+              if (!cleanedShuffleIds.contains(shuffleId)) {
+                lifecycleManager.get().unregisterShuffle(shuffleId)
+                logInfo(
+                  s"sent unregister shuffle request for shuffle $shuffleId (celeborn shuffle id)")
+                cleanedShuffleIds += shuffleId
+              }
+            }
+          }
+        },
+        cleanInterval,
+        cleanInterval,
+        TimeUnit.MILLISECONDS)
+    }
+  }
+
+  def removeCleanedShuffleId(celebornShuffleId: Int): Unit = {
+    cleanedShuffleIds.remove(celebornShuffleId)
+  }
+
+  private def noRunningDownstreamStage(celebornShuffleId: Int): Boolean = lock.synchronized {
+    val allReferringStageIds = celebornShuffleIdToReferringStages.get(celebornShuffleId)
+    require(allReferringStageIds != null, s"no stage referring to shuffle $celebornShuffleId")
+    val ret =
+      allReferringStageIds.count(stageId => runningStageManager.isRunningStage(stageId)) == 0
+    if (ret) {
+      logInfo(s"no running downstream stages refers to $celebornShuffleId")
+    } else {
+      logInfo(
+        s"there is more than one running downstream stage referring to shuffle $celebornShuffleId," +
+          s" ignore it for cleanup ")
+    }
+    ret
+  }
+
+  private var cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+    "failedShuffleCleanerThreadPool")

Review Comment:
   Seems it would always launch the pool even the feature is not enabled 



##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private final Field idField;
+
+  public RunningStageManagerImpl()
+      throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
+    Class<?> stageClass = Class.forName("org.apache.spark.scheduler.Stage");
+    idField = stageClass.getDeclaredField("id");
+    idField.setAccessible(true);

Review Comment:
   And it can be static.



##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private final Field idField;
+
+  public RunningStageManagerImpl()
+      throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
+    Class<?> stageClass = Class.forName("org.apache.spark.scheduler.Stage");
+    idField = stageClass.getDeclaredField("id");
+    idField.setAccessible(true);
+  }
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      Class<?> dagSchedulerClz = SparkContext$.MODULE$.getActive().get().dagScheduler().getClass();
+      Field runningStagesField = dagSchedulerClz.getDeclaredField("runningStages");

Review Comment:
   `DynFields` 



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.spark
+
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.shuffle.celeborn.{RunningStageManagerImpl, SparkCommonUtils}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(

Review Comment:
   I think you should not create a new pool on reset.
   
   You can create the cleanerThreadPool inside `setLifecycleManager`.



##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java:
##########
@@ -150,13 +151,34 @@ private void initializeLifecycleManager(String appId) {
 
             lifecycleManager.registerShuffleTrackerCallback(
                 shuffleId -> SparkUtils.unregisterAllMapOutput(mapOutputTracker, shuffleId));
-

Review Comment:
   nit: unnecessary change



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2847743762

   @CodingCat:
   > we already know for determinant stages we should not fail/restart certain stages in some scenario
   
   We are not failing/restarting for determinate stages - only for indeterminate stages.
   We dont need to do that for determinate stages for any scenario - shuffle can be reused across all cases.


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067968447


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   could you cover it likes SparkUtilsSuite?



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069205894


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFailedDiskCleanUtils.scala:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.tests.spark
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+
+import org.apache.celeborn.common.protocol.ShuffleMode
+import org.apache.celeborn.spark.FailedShuffleCleaner
+
+class CelebornFailedDiskCleanUtils extends SparkTestBase {
+  test("test correctness of RunningStageManager") {
+    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
+    val sparkSession = SparkSession.builder()
+      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
+      .config("spark.sql.shuffle.partitions", 2)
+      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
+      .config("spark.celeborn.client.spark.fetch.throwsFetchFailure", "true")
+      .config(
+        "spark.shuffle.manager",
+        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
+      .getOrCreate()
+    val t = new Thread {
+      override def run(): Unit = {
+        try {
+          sparkSession.sparkContext.parallelize(List(1, 2, 3)).foreach(_ =>
+            Thread.sleep(60 * 1000))
+        } catch {
+          case _: Throwable =>
+          // swallow everything
+        }
+      }
+    }
+    t.start()
+    Thread.sleep(20 * 1000)

Review Comment:
   ```
   eventually(timeout(20.seconds), interval(100.milliseconds))  {
     ...
   }
   
   sparkSession.sparkContext.cancelAllJobs()
   
   t.interrupt()
   
   sparkSession.stop()
   ```
   
   



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "RexXiong (via GitHub)" <gi...@apache.org>.
RexXiong commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2051914847


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private lazy val cleanInterval =
+    lifecycleManager.get().conf.clientFetchCleanFailedShuffleIntervalMS
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+    cleanerThreadPool.shutdownNow()
+    cleanerThreadPool = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
+      "failedShuffleCleanerThreadPool")
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')

Review Comment:
   Could we try to move to SparkCommonUtils?



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {

Review Comment:
   As far as I know, the SparkContext may be recreated. Therefore, Celeborn should be reset accordingly.



##########
client-spark/common/src/main/scala/org/apache/spark/scheduler/RunningStageManager.scala:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.spark.scheduler
+
+import org.apache.spark.SparkContext
+
+trait RunningStageManager {
+  def isRunningStage(stageId: Int): Boolean
+}
+
+class RunningStageManagerImpl extends RunningStageManager {
+  private def dagScheduler = SparkContext.getActive.get.dagScheduler
+  override def isRunningStage(stageId: Int): Boolean = {
+    dagScheduler.runningStages.map(_.id).contains(stageId)

Review Comment:
   How about use reflect to get the value of `runningStages`? IMO we would better not name a package from other project.  See `SparkCommonUtils`



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2819557754

   @RexXiong I addressed all comments, please let me know about any further suggestions


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2062834788


##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -4750,6 +4753,23 @@ object CelebornConf extends Logging {
       .booleanConf
       .createWithDefault(true)
 
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE: ConfigEntry[Boolean] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffle")
+      .categories("client")
+      .version("0.6.0")
+      .doc("whether to clean those disk space occupied by shuffles which cannot be fetched")
+      .booleanConf
+      .createWithDefault(false)
+
+  val CLIENT_FETCH_CLEAN_FAILED_SHUFFLE_INTERVAL: ConfigEntry[Long] =
+    buildConf("celeborn.client.spark.fetch.cleanFailedShuffleIntervalMs")
+      .categories("client")
+      .version("0.6.0")
+      .doc("the interval to clean the failed-to-fetch shuffle files, only valid when" +
+        s" ${CLIENT_FETCH_CLEAN_FAILED_SHUFFLE.key} is enabled")
+      .longConf

Review Comment:
   ```  
       .timeConf(TimeUnit.MILLISECONDS)
       .createWithDefaultString("1s")
   ```



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2052722189


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue, TimeUnit}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.util.ThreadUtils
+
+private[celeborn] object FailedShuffleCleaner extends Logging {

Review Comment:
   sure, added



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2067968447


##########
client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/RunningStageManagerImpl.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.spark.shuffle.celeborn;
+
+import java.util.HashSet;
+
+import org.apache.spark.SparkContext$;
+import org.apache.spark.scheduler.DAGScheduler;
+import org.apache.spark.scheduler.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.reflect.DynFields;
+import org.apache.celeborn.spark.RunningStageManager;
+
+public class RunningStageManagerImpl implements RunningStageManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(RunningStageManagerImpl.class);
+  private static final DynFields.UnboundField idField =
+      DynFields.builder().hiddenImpl(Stage.class, "id").build();
+
+  private HashSet<?> runningStages() {
+    try {
+      DAGScheduler dagScheduler = SparkContext$.MODULE$.getActive().get().dagScheduler();
+      DynFields.UnboundField runningStagesField =
+          DynFields.builder().hiddenImpl(DAGScheduler.class, "runningStages").build();
+      return (HashSet<?>) runningStagesField.bind(dagScheduler).get();

Review Comment:
   could you cover it likes SparkUtilsSuite?
   
   by checking the runningStages is not empty
   
   it is necessary because we use reflection.



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2069205894


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFailedDiskCleanUtils.scala:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.tests.spark
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+
+import org.apache.celeborn.common.protocol.ShuffleMode
+import org.apache.celeborn.spark.FailedShuffleCleaner
+
+class CelebornFailedDiskCleanUtils extends SparkTestBase {
+  test("test correctness of RunningStageManager") {
+    val sparkConf = new SparkConf().setAppName("rss-demo").setMaster("local[2,3]")
+    val sparkSession = SparkSession.builder()
+      .config(updateSparkConf(sparkConf, ShuffleMode.HASH))
+      .config("spark.sql.shuffle.partitions", 2)
+      .config("spark.celeborn.shuffle.forceFallback.partition.enabled", false)
+      .config("spark.celeborn.client.spark.fetch.throwsFetchFailure", "true")
+      .config(
+        "spark.shuffle.manager",
+        "org.apache.spark.shuffle.celeborn.TestCelebornShuffleManager")
+      .getOrCreate()
+    val t = new Thread {
+      override def run(): Unit = {
+        try {
+          sparkSession.sparkContext.parallelize(List(1, 2, 3)).foreach(_ =>
+            Thread.sleep(60 * 1000))
+        } catch {
+          case _: Throwable =>
+          // swallow everything
+        }
+      }
+    }
+    t.start()
+    Thread.sleep(20 * 1000)

Review Comment:
   ```
   eventually(timeout(20.seconds), interval(0.milliseconds))  {
     ...
   }
   
   sparkSession.sparkContext.cancelAllJobs()
   
   t.interrupt()
   
   sparkSession.stop()
   ```
   
   



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2843496171

   > RunningStageManager UT
   
   we are already doing that with ` FailedShuffleCleaner.reset()` in beforeEach
   
   the current failed test probably is just the spark job somehow runs slower than expected in this case
   
   looking at the logs, right after the test is marked as failed, the storage status actually goes into the expected status
   
   ![image](https://github.com/user-attachments/assets/84d0e861-45a9-4ff5-be12-e074baab4d3a)
   


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2843869828

   > Took a quick look.
   > 
   > I am missing some context here - why not simply delete shuffle when `handleGetShuffleIdForApp` determines we need to return a new shuffle id and clean up/abandon existing ?
   
   that's what this PR is doing 
   
   https://github.com/apache/celeborn/pull/3109/files#diff-0e4daa1d278b0e4653b662aad00ac5b2b0198587163c3f1508cb049f54f33736R940-R941 ?


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "mridulm (via GitHub)" <gi...@apache.org>.
mridulm commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2844021535

   Given this applies to indeterminate stages (and not determinate stages), in the scenario presented where stage 0 is indeterminate - we must recompute stage 2 when stage 1 suffers from a fetch failure : else the data fetched for stage 1, when stage 0.1 runs - will no longer be consistent with what was already fetched for stage 2.
   
   A variant of this is discussed here: https://github.com/apache/spark/pull/50630


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2855937384

   > @CodingCat:
   > 
   > > we already know for determinant stages we should not fail/restart certain stages in some scenario
   > 
   > We are not failing/restarting for determinate stages - only for indeterminate stages. We dont need to do that for determinate stages - shuffle can be reused across all cases.
   > 
   > Please do let me know if I am missing something/scenarios ! You have been looking into this for Celeborn in this PR much longer than me :-)
   
   Hi, @mridulm I think what you said makes sense, I simplified the code but still keeps the basic structure like keeping shuffleCleaner in spark modules, etc. 
   
   the reason is that I think it won't leak the Spark-specific assumption like the format of appShuffleIdentifier to LifecycleManager layer,  


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2709047880

   ## [Codecov](https://app.codecov.io/gh/apache/celeborn/pull/3109?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `85.71429%` with `1 line` in your changes missing coverage. Please review.
   > Project coverage is 32.62%. Comparing base [(`3a83ac7`)](https://app.codecov.io/gh/apache/celeborn/commit/3a83ac769335bbd37bfbb056e7735d3788c4a2c7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`1246b4e`)](https://app.codecov.io/gh/apache/celeborn/commit/1246b4e9063c7b1860e16de6476a12ee38d0d753?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 4 commits behind head on main.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/celeborn/pull/3109?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...cala/org/apache/celeborn/common/CelebornConf.scala](https://app.codecov.io/gh/apache/celeborn/pull/3109?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fceleborn%2Fcommon%2FCelebornConf.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvY2VsZWJvcm4vY29tbW9uL0NlbGVib3JuQ29uZi5zY2FsYQ==) | 85.72% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/celeborn/pull/3109?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@            Coverage Diff             @@
   ##             main    #3109      +/-   ##
   ==========================================
   + Coverage   32.58%   32.62%   +0.04%     
   ==========================================
     Files         340      340              
     Lines       20390    20405      +15     
     Branches     1820     1820              
   ==========================================
   + Hits         6642     6655      +13     
   - Misses      13376    13378       +2     
     Partials      372      372              
   ```
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/celeborn/pull/3109?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   <details><summary>🚀 New features to boost your workflow: </summary>
   
   - ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - 📦 [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2029185150


##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(
+      celebornShuffleId: Int,
+      appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = appShuffleIdentifier.split('-')
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (pastAppShuffleIdentifier, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          val Array(_, stageId, attemptId) = pastAppShuffleIdentifier.split('-')
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    lifecycleManager.compareAndSet(null, ref)
+  }
+
+  private def noRunningDownstreamStage(shuffleId: Int): Boolean = {
+    val allReferringStageIds = celebornShuffleIdToReferringStages.get(shuffleId)
+    require(allReferringStageIds != null, s"no stage referring to shuffle $shuffleId")
+    val ret =
+      allReferringStageIds.count(stageId => runningStageManager.isRunningStage(stageId)) == 0
+    if (ret) {
+      logInfo(s"no running downstream stages refers to $shuffleId")
+    } else {
+      logInfo(s"there is more than one running downstream stage referring to shuffle $shuffleId," +
+        s" ignore it for cleanup ")
+    }
+    ret
+  }
+
+  private val cleanerThread = new Thread() {

Review Comment:
   updated



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]

Review Comment:
   the reason is that shufflesToBeCleand may contain duplicate ids when there are multiple retries for the same applications shuffle id, I just avoid sending duplicate unregister messages 
   
   I have added the clean up logic for cleanedShuffleIds



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()

Review Comment:
   I think I still need a map instead of a set?



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()

Review Comment:
   same here, I think I still need a map instead of a set?



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(
+      celebornShuffleId: Int,
+      appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = appShuffleIdentifier.split('-')
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (pastAppShuffleIdentifier, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          val Array(_, stageId, attemptId) = pastAppShuffleIdentifier.split('-')
+          shufflesToBeCleand.put(celebornShuffleId)
+        }
+      }
+    }
+  }
+
+  private def committedSuccessfully(celebornShuffleId: Int): Boolean = {
+    val ret = !lifecycleManager.get().commitManager.getCommitHandler(celebornShuffleId)
+      .isStageDataLost(celebornShuffleId)
+    if (!ret) {
+      logInfo(s"shuffle $celebornShuffleId is failed to commit, adding for cleaning up")
+    }
+    ret
+  }
+
+  def setLifecycleManager(ref: LifecycleManager): Unit = {
+    lifecycleManager.compareAndSet(null, ref)
+  }
+
+  private def noRunningDownstreamStage(shuffleId: Int): Boolean = {

Review Comment:
   oh, yes, fixed



##########
client-spark/common/src/main/scala/org/apache/celeborn/spark/FailedShuffleCleaner.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.spark
+import java.util
+import java.util.concurrent.{ConcurrentHashMap, LinkedBlockingQueue}
+import java.util.concurrent.atomic.AtomicReference
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.scheduler.{RunningStageManager, RunningStageManagerImpl}
+
+import org.apache.celeborn.client.LifecycleManager
+import org.apache.celeborn.common.internal.Logging
+
+private[celeborn] object FailedShuffleCleaner extends Logging {
+
+  private val lifecycleManager = new AtomicReference[LifecycleManager](null)
+  // in celeborn ids
+  private val shufflesToBeCleand = new LinkedBlockingQueue[Int]()
+  private val cleanedShuffleIds = new mutable.HashSet[Int]
+  // celeborn shuffle id to stage id referred to it
+  private[celeborn] val celebornShuffleIdToReferringStages =
+    new ConcurrentHashMap[Int, mutable.HashSet[Int]]()
+
+  private val lock = new Object
+  val RUNNING_STAGE_CHECKER_CLASS = "CELEBORN_TEST_RUNNING_STAGE_CHECKER_IMPL"
+
+  private[celeborn] var runningStageManager: RunningStageManager = buildRunningStageChecker()
+
+  // for testing
+  private def buildRunningStageChecker(): RunningStageManager = {
+    if (System.getProperty(RUNNING_STAGE_CHECKER_CLASS) == null) {
+      new RunningStageManagerImpl
+    } else {
+      val className = System.getProperty(RUNNING_STAGE_CHECKER_CLASS)
+      val claz = Class.forName(className)
+      claz.getDeclaredConstructor().newInstance().asInstanceOf[RunningStageManager]
+    }
+  }
+
+  // for test
+  def reset(): Unit = {
+    lifecycleManager.set(null)
+    shufflesToBeCleand.clear()
+    cleanedShuffleIds.clear()
+    celebornShuffleIdToReferringStages.clear()
+    runningStageManager = buildRunningStageChecker()
+  }
+
+  def addShuffleIdReferringStage(celebornShuffleId: Int, appShuffleIdentifier: String): Unit = {
+    // this is only implemented/tested with Spark for now
+    val Array(_, stageId, _) = appShuffleIdentifier.split('-')
+    celebornShuffleIdToReferringStages.putIfAbsent(celebornShuffleId, new mutable.HashSet[Int]())
+    lock.synchronized {
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).add(stageId.toInt)
+    }
+  }
+
+  private def onlyCurrentStageReferred(celebornShuffleId: Int, stageId: Int): Boolean = {
+    val ret = celebornShuffleIdToReferringStages.get(celebornShuffleId).size == 1 &&
+      celebornShuffleIdToReferringStages.get(celebornShuffleId).contains(stageId)
+    if (ret) {
+      logInfo(s"only stage $stageId refers to shuffle $celebornShuffleId, adding for clean up")
+    }
+    ret
+  }
+
+  def addShuffleIdToBeCleaned(
+      celebornShuffleId: Int,
+      appShuffleIdentifier: String): Unit = {
+    val Array(appShuffleId, stageId, _) = appShuffleIdentifier.split('-')
+    lifecycleManager.get().getShuffleIdMapping.get(appShuffleId.toInt).foreach {
+      case (pastAppShuffleIdentifier, (celebornShuffleId, _)) => {
+        if (!celebornShuffleIdToReferringStages.containsKey(celebornShuffleId)
+          || onlyCurrentStageReferred(celebornShuffleId, stageId.toInt)
+          || noRunningDownstreamStage(celebornShuffleId)
+          || !committedSuccessfully(celebornShuffleId)) {
+          val Array(_, stageId, attemptId) = pastAppShuffleIdentifier.split('-')

Review Comment:
   removed



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "FMX (via GitHub)" <gi...@apache.org>.
FMX commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2041353296


##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java:
##########
@@ -606,4 +608,22 @@ public static void invalidateSerializedGetReducerFileGroupResponse(Integer shuff
           return null;
         });
   }
+
+  public static void addWriterShuffleIdsToBeCleaned(
+      LifecycleManager lifecycleManager, String appShuffleIdentifier) {
+    FailedShuffleCleaner.setLifecycleManager(lifecycleManager);
+    FailedShuffleCleaner.addShuffleIdToBeCleaned(appShuffleIdentifier);
+  }
+
+  public static void addShuffleIdRefCount(
+      LifecycleManager lifecycleManager, int celebornShuffeId, String appShuffleIdentifier) {

Review Comment:
   Here is a typo. celebornShuffeId --> celebornShuffleId



##########
client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java:
##########
@@ -165,6 +178,19 @@ private void initializeLifecycleManager(String appId) {
             lifecycleManager.registerInvalidatedBroadcastCallback(
                 shuffleId -> SparkUtils.invalidateSerializedGetReducerFileGroupResponse(shuffleId));
           }
+          if (lifecycleManager.conf().clientFetchCleanFailedShuffle()) {

Review Comment:
   These lines are duplicates of lines 159~172. 



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "CodingCat (via GitHub)" <gi...@apache.org>.
CodingCat commented on PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#issuecomment-2863418339

   @mridulm do you mind taking another look? thank you!


-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CELEBORN-1896] delete data from failed to fetch shuffles [celeborn]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #3109:
URL: https://github.com/apache/celeborn/pull/3109#discussion_r2098386029


##########
tests/spark-it/src/test/scala/org/apache/celeborn/tests/spark/CelebornFetchFailureSuite.scala:
##########
@@ -86,13 +76,7 @@ class CelebornFetchFailureSuite extends AnyFunSuite
 
   test("celeborn spark integration test - unregister shuffle with throwsFetchFailure disabled") {

Review Comment:
   It is special here, please see the UT name,
   
   ```
   test("celeborn spark integration test - unregister shuffle with throwsFetchFailure disabled")
   ```
   
   



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org