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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to