Skip to content

Commit 493f978

Browse files
committed
Send StreamingListenerBatchSubmitted when JobSet is submitted; fix StreamingListenerBatchStarted.batchInfo.processingStartTime; fix a typo
1 parent 8d2a36c commit 493f978

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

streaming/src/main/scala/org/apache/spark/streaming/scheduler/JobScheduler.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class JobScheduler(val ssc: StreamingContext) extends Logging {
105105
if (jobSet.jobs.isEmpty) {
106106
logInfo("No jobs added for time " + jobSet.time)
107107
} else {
108+
listenerBus.post(StreamingListenerBatchSubmitted(jobSet.toBatchInfo))
108109
jobSets.put(jobSet.time, jobSet)
109110
jobSet.jobs.foreach(job => jobExecutor.execute(new JobHandler(job)))
110111
logInfo("Added jobs for time " + jobSet.time)
@@ -135,9 +136,13 @@ class JobScheduler(val ssc: StreamingContext) extends Logging {
135136
private def handleJobStart(job: Job) {
136137
val jobSet = jobSets.get(job.time)
137138
if (!jobSet.hasStarted) {
139+
jobSet.handleJobStart(job)
140+
// "StreamingListenerBatchStarted" should be posted after calling "handleJobStart" to get the
141+
// correct "jobSet.processingStartTime".
138142
listenerBus.post(StreamingListenerBatchStarted(jobSet.toBatchInfo))
143+
} else {
144+
jobSet.handleJobStart(job)
139145
}
140-
jobSet.handleJobStart(job)
141146
logInfo("Starting job " + job.id + " from job set of time " + jobSet.time)
142147
}
143148

streaming/src/main/scala/org/apache/spark/streaming/ui/StreamingJobProgressListener.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private[streaming] class StreamingJobProgressListener(ssc: StreamingContext)
3333

3434
private val waitingBatchInfos = new HashMap[Time, BatchInfo]
3535
private val runningBatchInfos = new HashMap[Time, BatchInfo]
36-
private val completedaBatchInfos = new Queue[BatchInfo]
36+
private val completedBatchInfos = new Queue[BatchInfo]
3737
private val batchInfoLimit = ssc.conf.getInt("spark.streaming.ui.retainedBatches", 100)
3838
private var totalCompletedBatches = 0L
3939
private var totalReceivedRecords = 0L
@@ -62,7 +62,7 @@ private[streaming] class StreamingJobProgressListener(ssc: StreamingContext)
6262

6363
override def onBatchSubmitted(batchSubmitted: StreamingListenerBatchSubmitted): Unit = {
6464
synchronized {
65-
runningBatchInfos(batchSubmitted.batchInfo.batchTime) = batchSubmitted.batchInfo
65+
waitingBatchInfos(batchSubmitted.batchInfo.batchTime) = batchSubmitted.batchInfo
6666
}
6767
}
6868

@@ -79,8 +79,8 @@ private[streaming] class StreamingJobProgressListener(ssc: StreamingContext)
7979
synchronized {
8080
waitingBatchInfos.remove(batchCompleted.batchInfo.batchTime)
8181
runningBatchInfos.remove(batchCompleted.batchInfo.batchTime)
82-
completedaBatchInfos.enqueue(batchCompleted.batchInfo)
83-
if (completedaBatchInfos.size > batchInfoLimit) completedaBatchInfos.dequeue()
82+
completedBatchInfos.enqueue(batchCompleted.batchInfo)
83+
if (completedBatchInfos.size > batchInfoLimit) completedBatchInfos.dequeue()
8484
totalCompletedBatches += 1L
8585

8686
batchCompleted.batchInfo.receivedBlockInfo.foreach { case (_, infos) =>
@@ -118,7 +118,7 @@ private[streaming] class StreamingJobProgressListener(ssc: StreamingContext)
118118
}
119119

120120
def retainedCompletedBatches: Seq[BatchInfo] = synchronized {
121-
completedaBatchInfos.toSeq
121+
completedBatchInfos.toSeq
122122
}
123123

124124
def processingDelayDistribution: Option[Distribution] = synchronized {
@@ -165,7 +165,7 @@ private[streaming] class StreamingJobProgressListener(ssc: StreamingContext)
165165
}
166166

167167
def lastCompletedBatch: Option[BatchInfo] = {
168-
completedaBatchInfos.sortBy(_.batchTime)(Time.ordering).lastOption
168+
completedBatchInfos.sortBy(_.batchTime)(Time.ordering).lastOption
169169
}
170170

171171
def lastReceivedBatch: Option[BatchInfo] = {
@@ -174,10 +174,10 @@ private[streaming] class StreamingJobProgressListener(ssc: StreamingContext)
174174

175175
private def retainedBatches: Seq[BatchInfo] = synchronized {
176176
(waitingBatchInfos.values.toSeq ++
177-
runningBatchInfos.values.toSeq ++ completedaBatchInfos).sortBy(_.batchTime)(Time.ordering)
177+
runningBatchInfos.values.toSeq ++ completedBatchInfos).sortBy(_.batchTime)(Time.ordering)
178178
}
179179

180180
private def extractDistribution(getMetric: BatchInfo => Option[Long]): Option[Distribution] = {
181-
Distribution(completedaBatchInfos.flatMap(getMetric(_)).map(_.toDouble))
181+
Distribution(completedBatchInfos.flatMap(getMetric(_)).map(_.toDouble))
182182
}
183183
}

0 commit comments

Comments
 (0)