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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
