Skip to content

Commit 8ae42e0

Browse files
committed
Try to read from cache instead of checkpoint after checkpointing
1 parent c909ef0 commit 8ae42e0

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

core/src/main/scala/org/apache/spark/CheckpointManager.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class CheckpointManager extends Logging {
3131
/** Keys of RDD partitions that are being checkpointed. */
3232
private val checkpointingRDDPartitions = new mutable.HashSet[RDDBlockId]
3333

34-
/** Gets or computes an RDD partition. Used by RDD.iterator() when an RDD is cached. */
34+
/** Gets or computes an RDD partition. Used by RDD.iterator() when an RDD is about to be
35+
* checkpointed. */
3536
def getOrCompute[T: ClassTag](
3637
rdd: RDD[T],
3738
checkpointData: ReliableRDDCheckpointData[T],
@@ -49,7 +50,7 @@ class CheckpointManager extends Logging {
4950
} else {
5051
// Acquire a lock for loading this partition
5152
// If another thread already holds the lock, wait for it to finish return its results
52-
val checkpoint = acquireLockForPartition[T](key, path, conf, context)
53+
val checkpoint = acquireLockForPartition[T](rdd, partition, key, context)
5354
if (checkpoint.isDefined) {
5455
return new InterruptibleIterator[T](context, checkpoint.get)
5556
}
@@ -61,7 +62,7 @@ class CheckpointManager extends Logging {
6162
val computedValues = rdd.computeOrReadCache(partition, context)
6263
ReliableCheckpointRDD.writeCheckpointFile(
6364
context, computedValues, checkpointData.cpDir, conf, partition.index)
64-
ReliableCheckpointRDD.readCheckpointFile(path, conf, context)
65+
rdd.computeOrReadCache(partition, context)
6566
} finally {
6667
checkpointingRDDPartitions.synchronized {
6768
checkpointingRDDPartitions.remove(key)
@@ -78,8 +79,10 @@ class CheckpointManager extends Logging {
7879
* thread.
7980
*/
8081
private def acquireLockForPartition[T](
81-
id: RDDBlockId, path: Path, conf: Configuration, context: TaskContext): Option[Iterator[T]] =
82-
{
82+
rdd: RDD[T],
83+
partition: Partition,
84+
id: RDDBlockId,
85+
context: TaskContext): Option[Iterator[T]] = {
8386
checkpointingRDDPartitions.synchronized {
8487
if (!checkpointingRDDPartitions.contains(id)) {
8588
// If the partition is free, acquire its lock to compute its value
@@ -94,7 +97,7 @@ class CheckpointManager extends Logging {
9497
logInfo(s"Finished waiting for $id")
9598
}
9699
}
97-
Some(ReliableCheckpointRDD.readCheckpointFile(path, conf, context))
100+
Some(rdd.computeOrReadCache(partition, context))
98101
}
99102

100103
}

core/src/main/scala/org/apache/spark/SparkEnv.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class SparkEnv (
8181
@deprecated("Actor system is no longer supported as of 1.4.0", "1.4.0")
8282
val actorSystem: ActorSystem = _actorSystem
8383

84-
private[spark] val checkpointMananger = new CheckpointManager
84+
private[spark] val checkpointManager = new CheckpointManager
8585

8686
private[spark] var isStopped = false
8787
private val pythonWorkers = mutable.HashMap[(String, Map[String, String]), PythonWorkerFactory]()

core/src/main/scala/org/apache/spark/rdd/RDD.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ abstract class RDD[T: ClassTag](
260260
final def iterator(split: Partition, context: TaskContext): Iterator[T] = {
261261
if (!isCheckpointedAndMaterialized) {
262262
if (checkpointData.exists(_.isInstanceOf[ReliableRDDCheckpointData[T]])) {
263-
return SparkEnv.get.checkpointMananger.getOrCompute(
263+
return SparkEnv.get.checkpointManager.getOrCompute(
264264
this, checkpointData.get.asInstanceOf[ReliableRDDCheckpointData[T]], split, context)
265265
}
266266
}

0 commit comments

Comments
 (0)