Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/11436#discussion_r54648520
--- Diff: core/src/main/scala/org/apache/spark/rdd/RDD.scala ---
@@ -315,6 +315,34 @@ abstract class RDD[T: ClassTag](
}
/**
+ * Gets or computes an RDD partition. Used by RDD.iterator() when an RDD
is cached.
+ */
+ private[spark] def getOrCompute(partition: Partition, context:
TaskContext): Iterator[T] = {
+ val blockId = RDDBlockId(id, partition.index)
+ var readCachedBlock = true
+ SparkEnv.get.blockManager.getOrElseUpdate(blockId, storageLevel, () =>
{
+ readCachedBlock = false
+ computeOrReadCheckpoint(partition, context)
+ }) match {
+ case Left(blockResult) =>
+ if (readCachedBlock) {
+ val existingMetrics =
context.taskMetrics().registerInputMetrics(blockResult.readMethod)
+ existingMetrics.incBytesReadInternal(blockResult.bytes)
+ new InterruptibleIterator[T](context,
blockResult.data.asInstanceOf[Iterator[T]]) {
+ override def next(): T = {
+ existingMetrics.incRecordsReadInternal(1)
+ delegate.next()
--- End diff --
crazy idea: what if we push all of this metrics code into
`getOrElseUpdate`? Then we don't need the complicated left or right signature
anymore and we can contain all the complexity within `BlockManager` itself. We
might need to pass in `TaskContext` but I think it's pretty doable to make
`getOrElseUpdate` return an `Iterator[T]`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]