Skip to content

Commit 29aa099

Browse files
committed
Fixed line length issues.
1 parent 9e47b5b commit 29aa099

File tree

2 files changed

+43
-26
lines changed

2 files changed

+43
-26
lines changed

streaming/src/main/scala/org/apache/spark/streaming/rdd/WriteAheadLogBackedBlockRDD.scala

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,47 @@ class WriteAheadLogBackedBlockRDDPartition(
4141

4242

4343
/**
44-
* This class represents a special case of the BlockRDD where the data blocks in the block manager are also
45-
* backed by segments in write ahead logs. For reading the data, this RDD first looks up the blocks by their ids
46-
* in the block manager. If it does not find them, it looks up the corresponding file segment.
44+
* This class represents a special case of the BlockRDD where the data blocks in
45+
* the block manager are also backed by segments in write ahead logs. For reading
46+
* the data, this RDD first looks up the blocks by their ids in the block manager.
47+
* If it does not find them, it looks up the corresponding file segment.
4748
*
4849
* @param sc SparkContext
49-
* @param hadoopConfiguration Hadoop configuration
50+
* @param hadoopConfig Hadoop configuration
5051
* @param blockIds Ids of the blocks that contains this RDD's data
5152
* @param segments Segments in write ahead logs that contain this RDD's data
52-
* @param storeInBlockManager Whether to store in the block manager after reading from the log segment
53-
* @param storageLevel storage level to store when storing in block manager (applicable when storeInBlockManager = true)
53+
* @param storeInBlockManager Whether to store in the block manager after reading from the segment
54+
* @param storageLevel storage level to store when storing in block manager
55+
* (applicable when storeInBlockManager = true)
5456
*/
5557
private[streaming]
5658
class WriteAheadLogBackedBlockRDD[T: ClassTag](
5759
@transient sc: SparkContext,
58-
@transient hadoopConfiguration: Configuration,
60+
@transient hadoopConfig: Configuration,
5961
@transient override val blockIds: Array[BlockId],
6062
@transient val segments: Array[WriteAheadLogFileSegment],
6163
val storeInBlockManager: Boolean,
6264
val storageLevel: StorageLevel
6365
) extends BlockRDD[T](sc, blockIds) {
6466

65-
require(blockIds.length == segments.length,
66-
s"Number of block ids (${blockIds.length}) must be the same as number of segments (${segments.length}})!")
67+
require(
68+
blockIds.length == segments.length,
69+
s"Number of block ids (${blockIds.length}) must be " +
70+
s"the same as number of segments (${segments.length}})!")
6771

6872
// Hadoop configuration is not serializable, so broadcast it as a serializable.
69-
private val broadcastedHadoopConf = new SerializableWritable(hadoopConfiguration)
73+
private val broadcastedHadoopConf = new SerializableWritable(hadoopConfig)
7074

7175
override def getPartitions: Array[Partition] = {
7276
assertValid()
73-
Array.tabulate(blockIds.size){ i => new WriteAheadLogBackedBlockRDDPartition(i, blockIds(i), segments(i)) }
77+
Array.tabulate(blockIds.size) { i =>
78+
new WriteAheadLogBackedBlockRDDPartition(i, blockIds(i), segments(i)) }
7479
}
7580

7681
/**
77-
* Gets the partition data by getting the corresponding block from the block manager. If the block does not
78-
* exist, then the data is read from the corresponding segment in write ahead log files.
82+
* Gets the partition data by getting the corresponding block from the block manager.
83+
* If the block does not exist, then the data is read from the corresponding segment
84+
* in write ahead log files.
7985
*/
8086
override def compute(split: Partition, context: TaskContext): Iterator[T] = {
8187
assertValid()
@@ -86,31 +92,32 @@ class WriteAheadLogBackedBlockRDD[T: ClassTag](
8692
blockManager.get(blockId) match {
8793
case Some(block) => // Data is in Block Manager
8894
val iterator = block.data.asInstanceOf[Iterator[T]]
89-
logDebug(s"Read partition data of RDD $this from block manager, block $blockId")
95+
logDebug(s"Read partition data of $this from block manager, block $blockId")
9096
iterator
9197
case None => // Data not found in Block Manager, grab it from write ahead log file
9298
val reader = new WriteAheadLogRandomReader(partition.segment.path, hadoopConf)
9399
val dataRead = reader.read(partition.segment)
94100
reader.close()
95-
logInfo(s"Read partition data of RDD $this from write ahead log, segment ${partition.segment}")
101+
logInfo(s"Read partition data of $this from write ahead log, segment ${partition.segment}")
96102
if (storeInBlockManager) {
97103
blockManager.putBytes(blockId, dataRead, storageLevel)
98-
logDebug(s"Stored partition data of RDD $this into block manager with level $storageLevel")
104+
logDebug(s"Stored partition data of $this into block manager with level $storageLevel")
99105
dataRead.rewind()
100106
}
101107
blockManager.dataDeserialize(blockId, dataRead).asInstanceOf[Iterator[T]]
102108
}
103109
}
104110

105111
/**
106-
* Get the preferred location of the partition. This returns the locations of the block if it is present in the
107-
* block manager, else it returns the location of the corresponding segment in HDFS.
112+
* Get the preferred location of the partition. This returns the locations of the block
113+
* if it is present in the block manager, else it returns the location of the
114+
* corresponding segment in HDFS.
108115
*/
109116
override def getPreferredLocations(split: Partition): Seq[String] = {
110117
val partition = split.asInstanceOf[WriteAheadLogBackedBlockRDDPartition]
111118
val blockLocations = getBlockIdLocations().get(partition.blockId)
112119
lazy val segmentLocations = HdfsUtils.getBlockLocations(
113-
partition.segment.path, partition.segment.offset, partition.segment.length, hadoopConfiguration)
120+
partition.segment.path, partition.segment.offset, partition.segment.length, hadoopConfig)
114121
blockLocations.orElse(segmentLocations).getOrElse(Seq.empty)
115122
}
116123
}

streaming/src/test/scala/org/apache/spark/streaming/rdd/WriteAheadLogBackedBlockRDDSuite.scala

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,19 @@ class WriteAheadLogBackedBlockRDDSuite extends FunSuite with BeforeAndAfterAll {
7171
}
7272

7373
/**
74-
* Test the WriteAheadLogBackedRDD, by writing some partitions of the data to Block Manager and the rest
75-
* to a WriteAheadLog, and then reading reading it all back using the RDD.
76-
* It can also test if the partitions that were read from the log were again stored in block manager.
74+
* Test the WriteAheadLogBackedRDD, by writing some partitions of the data to block manager
75+
* and the rest to a write ahead log, and then reading reading it all back using the RDD.
76+
* It can also test if the partitions that were read from the log were again stored in
77+
* block manager.
7778
* @param numPartitionssInBM Number of partitions to write to the Block Manager
7879
* @param numPartitionsInWAL Number of partitions to write to the Write Ahead Log
7980
* @param testStoreInBM Test whether blocks read from log are stored back into block manager
8081
*/
81-
private def testRDD(numPartitionssInBM: Int, numPartitionsInWAL: Int, testStoreInBM: Boolean = false) {
82+
private def testRDD(
83+
numPartitionssInBM: Int,
84+
numPartitionsInWAL: Int,
85+
testStoreInBM: Boolean = false
86+
) {
8287
val numBlocks = numPartitionssInBM + numPartitionsInWAL
8388
val data = Seq.tabulate(numBlocks) { _ => Seq.fill(10) { scala.util.Random.nextString(50) } }
8489

@@ -104,11 +109,13 @@ class WriteAheadLogBackedBlockRDDSuite extends FunSuite with BeforeAndAfterAll {
104109

105110
// Make sure that the right `numPartitionsInWAL` blocks are in write ahead logs, and other are not
106111
require(
107-
segments.takeRight(numPartitionsInWAL).forall(s => new File(s.path.stripPrefix("file://")).exists()),
112+
segments.takeRight(numPartitionsInWAL).forall(s =>
113+
new File(s.path.stripPrefix("file://")).exists()),
108114
"Expected blocks not in write ahead log"
109115
)
110116
require(
111-
segments.take(numPartitionssInBM).forall(s => !new File(s.path.stripPrefix("file://")).exists()),
117+
segments.take(numPartitionssInBM).forall(s =>
118+
!new File(s.path.stripPrefix("file://")).exists()),
112119
"Unexpected blocks in write ahead log"
113120
)
114121

@@ -128,7 +135,10 @@ class WriteAheadLogBackedBlockRDDSuite extends FunSuite with BeforeAndAfterAll {
128135
}
129136
}
130137

131-
private def writeLogSegments(blockData: Seq[Seq[String]], blockIds: Seq[BlockId]): Seq[WriteAheadLogFileSegment] = {
138+
private def writeLogSegments(
139+
blockData: Seq[Seq[String]],
140+
blockIds: Seq[BlockId]
141+
): Seq[WriteAheadLogFileSegment] = {
132142
require(blockData.size === blockIds.size)
133143
val writer = new WriteAheadLogWriter(new File(dir, Random.nextString(10)).toString, hadoopConf)
134144
val segments = blockData.zip(blockIds).map { case (data, id) =>

0 commit comments

Comments
 (0)