You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by tdas <gi...@git.apache.org> on 2015/12/01 01:59:21 UTC

[GitHub] spark pull request: [SPARK-11932][STREAMING] Partition previous Tr...

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

    https://github.com/apache/spark/pull/9988#discussion_r46227935
  
    --- Diff: streaming/src/main/scala/org/apache/spark/streaming/dstream/TrackStateDStream.scala ---
    @@ -132,22 +132,39 @@ class InternalTrackStateDStream[K: ClassTag, V: ClassTag, S: ClassTag, E: ClassT
       /** Method that generates a RDD for the given time */
       override def compute(validTime: Time): Option[RDD[TrackStateRDDRecord[K, S, E]]] = {
         // Get the previous state or create a new empty state RDD
    -    val prevStateRDD = getOrCompute(validTime - slideDuration).getOrElse {
    -      TrackStateRDD.createFromPairRDD[K, V, S, E](
    -        spec.getInitialStateRDD().getOrElse(new EmptyRDD[(K, S)](ssc.sparkContext)),
    -        partitioner, validTime
    -      )
    +    val prevStateRDD = getOrCompute(validTime - slideDuration) match {
    +      case Some(rdd) =>
    +        if (rdd.partitioner != Some(partitioner)) {
    +          // If the RDD is not partitioned the right way, let us repartition it using the
    +          // partition index as the key. This is to ensure that state RDD is always partitioned
    +          // before creating another state RDD using it
    +          val kvRDD = rdd.mapPartitions { iter =>
    +            iter.map { x => (TaskContext.get().partitionId(), x)}
    +          }
    +          kvRDD.partitionBy(partitioner).mapPartitions(iter => iter.map { _._2 },
    +            preservesPartitioning = true)
    +        } else {
    +          rdd
    +        }
    +      case None =>
    +        TrackStateRDD.createFromPairRDD[K, V, S, E](
    +          spec.getInitialStateRDD().getOrElse(new EmptyRDD[(K, S)](ssc.sparkContext)),
    +          partitioner, validTime
    --- End diff --
    
    Done.


---
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