Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-17816] [Core] [Branch-2.0] Fix ConcurrentModificationException issue in BlockStatusesAccumulator #15425

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 2 additions & 40 deletions core/src/main/scala/org/apache/spark/executor/TaskMetrics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.spark.executor

import java.util.{ArrayList, Collections}

import scala.collection.JavaConverters._
import scala.collection.mutable.{ArrayBuffer, LinkedHashMap}

Expand All @@ -27,7 +25,7 @@ import org.apache.spark.annotation.DeveloperApi
import org.apache.spark.internal.Logging
import org.apache.spark.scheduler.AccumulableInfo
import org.apache.spark.storage.{BlockId, BlockStatus}
import org.apache.spark.util.{AccumulatorContext, AccumulatorMetadata, AccumulatorV2, LongAccumulator}
import org.apache.spark.util._


/**
Expand All @@ -54,7 +52,7 @@ class TaskMetrics private[spark] () extends Serializable {
private val _memoryBytesSpilled = new LongAccumulator
private val _diskBytesSpilled = new LongAccumulator
private val _peakExecutionMemory = new LongAccumulator
private val _updatedBlockStatuses = new BlockStatusesAccumulator
private val _updatedBlockStatuses = new CollectionAccumulator[(BlockId, BlockStatus)]

/**
* Time taken on the executor to deserialize this task.
Expand Down Expand Up @@ -305,39 +303,3 @@ private[spark] object TaskMetrics extends Logging {
tm
}
}


private[spark] class BlockStatusesAccumulator
extends AccumulatorV2[(BlockId, BlockStatus), java.util.List[(BlockId, BlockStatus)]] {
private val _seq = Collections.synchronizedList(new ArrayList[(BlockId, BlockStatus)]())

override def isZero(): Boolean = _seq.isEmpty

override def copyAndReset(): BlockStatusesAccumulator = new BlockStatusesAccumulator

override def copy(): BlockStatusesAccumulator = {
val newAcc = new BlockStatusesAccumulator
newAcc._seq.addAll(_seq)
newAcc
}

override def reset(): Unit = _seq.clear()

override def add(v: (BlockId, BlockStatus)): Unit = _seq.add(v)

override def merge(
other: AccumulatorV2[(BlockId, BlockStatus), java.util.List[(BlockId, BlockStatus)]]): Unit = {
other match {
case o: BlockStatusesAccumulator => _seq.addAll(o.value)
case _ => throw new UnsupportedOperationException(
s"Cannot merge ${this.getClass.getName} with ${other.getClass.getName}")
}
}

override def value: java.util.List[(BlockId, BlockStatus)] = _seq

def setValue(newValue: java.util.List[(BlockId, BlockStatus)]): Unit = {
_seq.clear()
_seq.addAll(newValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ class CollectionAccumulator[T] extends AccumulatorV2[T, java.util.List[T]] {

override def copy(): CollectionAccumulator[T] = {
val newAcc = new CollectionAccumulator[T]
newAcc._list.addAll(_list)
_list.synchronized {
newAcc._list.addAll(_list)
}
newAcc
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private[spark] object JsonProtocol {
("Getting Result Time" -> taskInfo.gettingResultTime) ~
("Finish Time" -> taskInfo.finishTime) ~
("Failed" -> taskInfo.failed) ~
("Accumulables" -> JArray(taskInfo.accumulables.map(accumulableInfoToJson).toList))
("Accumulables" -> JArray(taskInfo.accumulables.toList.map(accumulableInfoToJson)))
}

def accumulableInfoToJson(accumulableInfo: AccumulableInfo): JValue = {
Expand Down