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

    https://github.com/apache/spark/pull/2931#discussion_r19573363
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/rdd/WriteAheadLogBackedBlockRDD.scala
 ---
    @@ -0,0 +1,124 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.spark.streaming.rdd
    +
    +import scala.reflect.ClassTag
    +
    +import org.apache.hadoop.conf.Configuration
    +
    +import org.apache.spark._
    +import org.apache.spark.rdd.BlockRDD
    +import org.apache.spark.storage.{BlockId, StorageLevel}
    +import org.apache.spark.streaming.util.{HdfsUtils, 
WriteAheadLogFileSegment, WriteAheadLogRandomReader}
    +
    +/**
    + * Partition class for 
[[org.apache.spark.streaming.rdd.WriteAheadLogBackedBlockRDD]].
    + * It contains information about the id of the blocks having this 
partition's data and
    + * the segment of the write ahead log that backs the partition.
    + * @param index index of the partition
    + * @param blockId id of the block having the partition data
    + * @param segment segment of the write ahead log having the partition data
    + */
    +private[streaming]
    +class WriteAheadLogBackedBlockRDDPartition(
    +    val index: Int,
    +    val blockId: BlockId,
    +    val segment: WriteAheadLogFileSegment
    +  ) extends Partition
    +
    +
    +/**
    + * This class represents a special case of the BlockRDD where the data 
blocks in
    + * the block manager are also backed by segments in write ahead logs. For 
reading
    + * the data, this RDD first looks up the blocks by their ids in the block 
manager.
    + * If it does not find them, it looks up the corresponding file segment.
    + *
    + * @param sc SparkContext
    + * @param hadoopConfig Hadoop configuration
    + * @param blockIds Ids of the blocks that contains this RDD's data
    + * @param segments Segments in write ahead logs that contain this RDD's 
data
    + * @param storeInBlockManager Whether to store in the block manager after 
reading from the segment
    + * @param storageLevel storage level to store when storing in block manager
    + *                     (applicable when storeInBlockManager = true)
    + */
    +private[streaming]
    +class WriteAheadLogBackedBlockRDD[T: ClassTag](
    +    @transient sc: SparkContext,
    +    @transient hadoopConfig: Configuration,
    +    @transient override val blockIds: Array[BlockId],
    +    @transient val segments: Array[WriteAheadLogFileSegment],
    +    val storeInBlockManager: Boolean,
    +    val storageLevel: StorageLevel
    +  ) extends BlockRDD[T](sc, blockIds) {
    +
    +  require(
    +    blockIds.length == segments.length,
    +    s"Number of block ids (${blockIds.length}) must be " +
    +      s"the same as number of segments (${segments.length}})!")
    +
    +  // Hadoop configuration is not serializable, so broadcast it as a 
serializable.
    +  private val broadcastedHadoopConf = new 
SerializableWritable(hadoopConfig)
    +
    +  override def getPartitions: Array[Partition] = {
    +    assertValid()
    +    Array.tabulate(blockIds.size) { i =>
    --- End diff --
    
    and here
    ```scala
    Array.tabulate(blockIds.size) { i =>
      new WriteAheadLogBackedBlockRDDPartition(i, blockIds(i), segments(i))
    }
    ```


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

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

Reply via email to