17
17
package org .apache .spark .streaming .kinesis
18
18
19
19
import java .util .UUID
20
+ import java .util .concurrent .ConcurrentHashMap
20
21
21
22
import scala .collection .JavaConverters ._
22
23
import scala .collection .mutable
@@ -124,8 +125,7 @@ private[kinesis] class KinesisReceiver[T](
124
125
private val seqNumRangesInCurrentBlock = new mutable.ArrayBuffer [SequenceNumberRange ]
125
126
126
127
/** Sequence number ranges of data added to each generated block */
127
- private val blockIdToSeqNumRanges = new mutable.HashMap [StreamBlockId , SequenceNumberRanges ]
128
- with mutable.SynchronizedMap [StreamBlockId , SequenceNumberRanges ]
128
+ private val blockIdToSeqNumRanges = new ConcurrentHashMap [StreamBlockId , SequenceNumberRanges ]
129
129
130
130
/**
131
131
* The centralized kinesisCheckpointer that checkpoints based on the given checkpointInterval.
@@ -135,8 +135,8 @@ private[kinesis] class KinesisReceiver[T](
135
135
/**
136
136
* Latest sequence number ranges that have been stored successfully.
137
137
* This is used for checkpointing through KCL */
138
- private val shardIdToLatestStoredSeqNum = new mutable. HashMap [String , String ]
139
- with mutable. SynchronizedMap [ String , String ]
138
+ private val shardIdToLatestStoredSeqNum = new ConcurrentHashMap [String , String ]
139
+
140
140
/**
141
141
* This is called when the KinesisReceiver starts and must be non-blocking.
142
142
* The KCL creates and manages the receiving/processing thread pool through Worker.run().
@@ -222,7 +222,7 @@ private[kinesis] class KinesisReceiver[T](
222
222
223
223
/** Get the latest sequence number for the given shard that can be checkpointed through KCL */
224
224
private [kinesis] def getLatestSeqNumToCheckpoint (shardId : String ): Option [String ] = {
225
- shardIdToLatestStoredSeqNum.get(shardId)
225
+ Option ( shardIdToLatestStoredSeqNum.get(shardId) )
226
226
}
227
227
228
228
/**
@@ -257,15 +257,15 @@ private[kinesis] class KinesisReceiver[T](
257
257
* for next block. Internally, this is synchronized with `rememberAddedRange()`.
258
258
*/
259
259
private def finalizeRangesForCurrentBlock (blockId : StreamBlockId ): Unit = {
260
- blockIdToSeqNumRanges(blockId) = SequenceNumberRanges (seqNumRangesInCurrentBlock.toArray)
260
+ blockIdToSeqNumRanges.put (blockId, SequenceNumberRanges (seqNumRangesInCurrentBlock.toArray) )
261
261
seqNumRangesInCurrentBlock.clear()
262
262
logDebug(s " Generated block $blockId has $blockIdToSeqNumRanges" )
263
263
}
264
264
265
265
/** Store the block along with its associated ranges */
266
266
private def storeBlockWithRanges (
267
267
blockId : StreamBlockId , arrayBuffer : mutable.ArrayBuffer [T ]): Unit = {
268
- val rangesToReportOption = blockIdToSeqNumRanges.remove(blockId)
268
+ val rangesToReportOption = Option ( blockIdToSeqNumRanges.remove(blockId) )
269
269
if (rangesToReportOption.isEmpty) {
270
270
stop(" Error while storing block into Spark, could not find sequence number ranges " +
271
271
s " for block $blockId" )
@@ -294,7 +294,7 @@ private[kinesis] class KinesisReceiver[T](
294
294
// Note that we are doing this sequentially because the array of sequence number ranges
295
295
// is assumed to be
296
296
rangesToReport.ranges.foreach { range =>
297
- shardIdToLatestStoredSeqNum(range.shardId) = range.toSeqNumber
297
+ shardIdToLatestStoredSeqNum.put (range.shardId, range.toSeqNumber)
298
298
}
299
299
}
300
300
0 commit comments