You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by srowen <gi...@git.apache.org> on 2017/05/17 10:05:15 UTC

[GitHub] spark pull request #17936: [SPARK-20638][Core]Optimize the CartesianRDD to r...

Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17936#discussion_r116959739
  
    --- Diff: core/src/main/scala/org/apache/spark/rdd/CartesianRDD.scala ---
    @@ -71,9 +72,85 @@ class CartesianRDD[T: ClassTag, U: ClassTag](
       }
     
       override def compute(split: Partition, context: TaskContext): Iterator[(T, U)] = {
    +    val blockManager = SparkEnv.get.blockManager
         val currSplit = split.asInstanceOf[CartesianPartition]
    -    for (x <- rdd1.iterator(currSplit.s1, context);
    -         y <- rdd2.iterator(currSplit.s2, context)) yield (x, y)
    +    val blockId2 = RDDBlockId(rdd2.id, currSplit.s2.index)
    +    var cachedInLocal = false
    +    var holdReadLock = false
    +
    +    // Try to get data from the local, otherwise it will be cached to the local.
    +    def getOrElseCache(
    +        rdd: RDD[U],
    +        partition: Partition,
    +        context: TaskContext,
    +        level: StorageLevel): Iterator[U] = {
    +      getLocalValues() match {
    +        case Some(result) =>
    +          return result
    +        case None => // do nothing
    +      }
    +
    +      val iterator = rdd.iterator(partition, context)
    +      // Keep read lock, because next we need read it. And don't tell master.
    +      blockManager.putIterator[U](blockId2, iterator, level, false, true) match {
    +        case true =>
    --- End diff --
    
    BTW I think match is confusing overkill for booleans. Just use if-else


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org