@@ -113,10 +113,10 @@ class SQLAppStatusListener(
113
113
// Record the accumulator IDs and metric types for the stages of this job, so that the code
114
114
// that keeps track of the metrics knows which accumulators to look at.
115
115
val accumIdsAndType = exec.metricAccumulatorIdToMetricType
116
- if (accumIdsAndType.nonEmpty) {
116
+ if (accumIdsAndType.asScala. nonEmpty) {
117
117
event.stageInfos.foreach { stage =>
118
118
stageMetrics.put(stage.stageId, new LiveStageMetrics (stage.stageId, 0 ,
119
- stage.numTasks, accumIdsAndType))
119
+ stage.numTasks, accumIdsAndType.asScala ))
120
120
}
121
121
}
122
122
@@ -207,12 +207,12 @@ class SQLAppStatusListener(
207
207
private def aggregateMetrics (exec : LiveExecutionData ): Map [Long , String ] = {
208
208
val accumIds = exec.metrics.map(_.accumulatorId).toSet
209
209
210
- val metricAggregationMap = new mutable. HashMap [String , (Array [Long ], Array [Long ]) => String ]()
210
+ val metricAggregationMap = new ConcurrentHashMap [String , (Array [Long ], Array [Long ]) => String ]()
211
211
val metricAggregationMethods = exec.metrics.map { m =>
212
212
val optClassName = CustomMetrics .parseV2CustomMetricType(m.metricType)
213
213
val metricAggMethod = optClassName.map { className =>
214
214
if (metricAggregationMap.contains(className)) {
215
- metricAggregationMap(className)
215
+ metricAggregationMap.get (className)
216
216
} else {
217
217
// Try to initiate custom metric object
218
218
try {
@@ -247,41 +247,42 @@ class SQLAppStatusListener(
247
247
248
248
val maxMetrics = liveStageMetrics.flatMap(_.maxMetricValues())
249
249
250
- val allMetrics = new mutable. HashMap [Long , Array [Long ]]()
250
+ val allMetrics = new ConcurrentHashMap [Long , Array [Long ]]()
251
251
252
- val maxMetricsFromAllStages = new mutable. HashMap [Long , Array [Long ]]()
252
+ val maxMetricsFromAllStages = new ConcurrentHashMap [Long , Array [Long ]]()
253
253
254
254
taskMetrics.filter(m => accumIds.contains(m._1)).foreach { case (id, values) =>
255
- val prev = allMetrics.getOrElse (id, null )
255
+ val prev = allMetrics.getOrDefault (id, null )
256
256
val updated = if (prev != null ) {
257
257
prev ++ values
258
258
} else {
259
259
values
260
260
}
261
- allMetrics(id) = updated
261
+ allMetrics.put (id, updated)
262
262
}
263
263
264
264
// Find the max for each metric id between all stages.
265
265
val validMaxMetrics = maxMetrics.filter(m => accumIds.contains(m._1))
266
266
validMaxMetrics.foreach { case (id, value, taskId, stageId, attemptId) =>
267
- val updated = maxMetricsFromAllStages.getOrElse(id, Array (value, stageId, attemptId, taskId))
267
+ val updated = maxMetricsFromAllStages
268
+ .getOrDefault(id, Array (value, stageId, attemptId, taskId))
268
269
if (value > updated(0 )) {
269
270
updated(0 ) = value
270
271
updated(1 ) = stageId
271
272
updated(2 ) = attemptId
272
273
updated(3 ) = taskId
273
274
}
274
- maxMetricsFromAllStages(id) = updated
275
+ maxMetricsFromAllStages.put (id, updated)
275
276
}
276
277
277
278
exec.driverAccumUpdates.foreach { case (id, value) =>
278
279
if (accumIds.contains(id)) {
279
- val prev = allMetrics.getOrElse (id, null )
280
+ val prev = allMetrics.getOrDefault (id, null )
280
281
val updated = if (prev != null ) {
281
282
// If the driver updates same metrics as tasks and has higher value then remove
282
283
// that entry from maxMetricsFromAllStage. This would make stringValue function default
283
284
// to "driver" that would be displayed on UI.
284
- if (maxMetricsFromAllStages.contains(id) && value > maxMetricsFromAllStages(id)(0 )) {
285
+ if (maxMetricsFromAllStages.contains(id) && value > maxMetricsFromAllStages.get (id)(0 )) {
285
286
maxMetricsFromAllStages.remove(id)
286
287
}
287
288
val _copy = Arrays .copyOf(prev, prev.length + 1 )
@@ -290,11 +291,11 @@ class SQLAppStatusListener(
290
291
} else {
291
292
Array (value)
292
293
}
293
- allMetrics(id) = updated
294
+ allMetrics.put (id, updated)
294
295
}
295
296
}
296
297
297
- val aggregatedMetrics = allMetrics.map { case (id, values) =>
298
+ val aggregatedMetrics = allMetrics.asScala. map { case (id, values) =>
298
299
id -> metricAggregationMethods(id)(values, maxMetricsFromAllStages.getOrElse(id,
299
300
Array .empty[Long ]))
300
301
}.toMap
@@ -496,7 +497,7 @@ private class LiveExecutionData(val executionId: Long) extends LiveEntity {
496
497
// This mapping is shared across all LiveStageMetrics instances associated with
497
498
// this LiveExecutionData, helping to reduce memory overhead by avoiding waste
498
499
// from separate immutable maps with largely overlapping sets of entries.
499
- val metricAccumulatorIdToMetricType = new mutable. HashMap [Long , String ]()
500
+ val metricAccumulatorIdToMetricType = new ConcurrentHashMap [Long , String ]()
500
501
var submissionTime = - 1L
501
502
var completionTime : Option [Date ] = None
502
503
var errorMessage : Option [String ] = None
0 commit comments