Skip to content

Commit 5ae4f6e

Browse files
committed
getting name should not fail if accumulator is garbage collected
1 parent 771abeb commit 5ae4f6e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

core/src/main/scala/org/apache/spark/util/AccumulatorV2.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ abstract class AccumulatorV2[IN, OUT] extends Serializable {
8484
* Returns the name of this accumulator, can only be called after registration.
8585
*/
8686
final def name: Option[String] = {
87+
assertMetadataNotNull()
88+
8789
if (atDriverSide) {
88-
AccumulatorContext.get(id).flatMap(_.metadata.name)
90+
metadata.name.orElse(AccumulatorContext.get(id).flatMap(_.metadata.name))
8991
} else {
90-
assertMetadataNotNull()
9192
metadata.name
9293
}
9394
}
@@ -165,9 +166,7 @@ abstract class AccumulatorV2[IN, OUT] extends Serializable {
165166
}
166167
val copyAcc = copyAndReset()
167168
assert(copyAcc.isZero, "copyAndReset must return a zero value copy")
168-
val isInternalAcc =
169-
(name.isDefined && name.get.startsWith(InternalAccumulator.METRICS_PREFIX)) ||
170-
getClass.getSimpleName == "SQLMetric"
169+
val isInternalAcc = name.isDefined && name.get.startsWith(InternalAccumulator.METRICS_PREFIX)
171170
if (isInternalAcc) {
172171
// Do not serialize the name of internal accumulator and send it to executor.
173172
copyAcc.metadata = metadata.copy(name = None)

0 commit comments

Comments
 (0)