Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.io.IOException
import java.util.UUID
import scala.collection.mutable.Stack
import scala.util.Random
import scala.util.control.NonFatal

/**
* Implementation of parallel connected components algorithm using randomized contraction, based
Expand Down Expand Up @@ -89,6 +90,19 @@ private[graphframes] object RandomizedContraction extends Logging with Serializa

def tableName(iter: Int): String = s"${checkpointDir}/ccreps-${iter}"

def cleanupCheckpointDir(): Unit = {
try {
val checkpointPath = new Path(checkpointDir)
val fs = checkpointPath.getFileSystem(sc.hadoopConfiguration)
if (fs.exists(checkpointPath)) {
val _ = fs.delete(checkpointPath, true)
}
} catch {
case NonFatal(e) =>
logWarn(s"Failed to clean up checkpoint directory $checkpointDir: ${e.getMessage}")
}
}

val graph = if (isGraphPrepared) {
inputGraph
} else {
Expand Down Expand Up @@ -281,16 +295,13 @@ private[graphframes] object RandomizedContraction extends Logging with Serializa
outputComponents.count()

// clean-up
val chDirPath = new Path(checkpointDir)
val fs = chDirPath.getFileSystem(sc.hadoopConfiguration)
if (fs.exists(chDirPath)) {
fs.delete(chDirPath, true)
}
cleanupCheckpointDir()

outputComponents
} finally {
// to be 100% sure;
edges.unpersist()
cleanupCheckpointDir()
val dereg = functionRegistry.dropFunction(FunctionIdentifier("_axpb"))
if (!dereg) {
logWarn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,36 @@ class RandomizedContractionSuite extends SparkFunSuite with GraphFrameTestSparkC
assertFunctionRegistryClean()
}

test("RandomizedContraction: cleans up checkpoint files after failure") {
val graph = Graphs.chain(3L)
val checkpointRoot = new org.apache.hadoop.fs.Path(spark.sparkContext.getCheckpointDir.get)

intercept[ArithmeticException] {
RandomizedContraction
.run(
inputGraph = graph,
useLabelsAsComponents = false,
intermediateStorageLevel = StorageLevel.MEMORY_AND_DISK,
useLocalCheckpoints = true,
checkpointInterval = 0,
isGraphPrepared = false)
.count()
}

val fs = checkpointRoot.getFileSystem(spark.sparkContext.hadoopConfiguration)
val remainingCheckpointDirs =
if (fs.exists(checkpointRoot)) {
fs
.listStatus(checkpointRoot)
.map(_.getPath.getName)
.filter(_.startsWith("randomized-contraction-"))
} else {
Array.empty[String]
}
assert(remainingCheckpointDirs.isEmpty)
assertFunctionRegistryClean()
}

test("RandomizedContraction: no memory leaks") {
val priorCached = spark.sparkContext.getPersistentRDDs

Expand Down
Loading