You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2018/05/17 10:49:17 UTC
spark git commit: [SPARK-22371][CORE] Return None instead of throwing
an exception when an accumulator is garbage collected.
Repository: spark
Updated Branches:
refs/heads/master 3e66350c2 -> 6c35865d9
[SPARK-22371][CORE] Return None instead of throwing an exception when an accumulator is garbage collected.
## What changes were proposed in this pull request?
There's a period of time when an accumulator has been garbage collected, but hasn't been removed from AccumulatorContext.originals by ContextCleaner. When an update is received for such accumulator it will throw an exception and kill the whole job. This can happen when a stage completes, but there're still running tasks from other attempts, speculation etc. Since AccumulatorContext.get() returns an option we can just return None in such case.
## How was this patch tested?
Unit test.
Author: Artem Rudoy <ar...@gmail.com>
Closes #21114 from artemrd/SPARK-22371.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/6c35865d
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/6c35865d
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/6c35865d
Branch: refs/heads/master
Commit: 6c35865d949a8b46f654cd53c7e5f3288def18d0
Parents: 3e66350
Author: Artem Rudoy <ar...@gmail.com>
Authored: Thu May 17 18:49:46 2018 +0800
Committer: Wenchen Fan <we...@databricks.com>
Committed: Thu May 17 18:49:46 2018 +0800
----------------------------------------------------------------------
.../scala/org/apache/spark/util/AccumulatorV2.scala | 14 +++++++++-----
.../scala/org/apache/spark/AccumulatorSuite.scala | 6 ++----
2 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/6c35865d/core/src/main/scala/org/apache/spark/util/AccumulatorV2.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/org/apache/spark/util/AccumulatorV2.scala b/core/src/main/scala/org/apache/spark/util/AccumulatorV2.scala
index 2bc8495..3b469a6 100644
--- a/core/src/main/scala/org/apache/spark/util/AccumulatorV2.scala
+++ b/core/src/main/scala/org/apache/spark/util/AccumulatorV2.scala
@@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicLong
import org.apache.spark.{InternalAccumulator, SparkContext, TaskContext}
+import org.apache.spark.internal.Logging
import org.apache.spark.scheduler.AccumulableInfo
private[spark] case class AccumulatorMetadata(
@@ -211,7 +212,7 @@ abstract class AccumulatorV2[IN, OUT] extends Serializable {
/**
* An internal class used to track accumulators by Spark itself.
*/
-private[spark] object AccumulatorContext {
+private[spark] object AccumulatorContext extends Logging {
/**
* This global map holds the original accumulator objects that are created on the driver.
@@ -258,13 +259,16 @@ private[spark] object AccumulatorContext {
* Returns the [[AccumulatorV2]] registered with the given ID, if any.
*/
def get(id: Long): Option[AccumulatorV2[_, _]] = {
- Option(originals.get(id)).map { ref =>
- // Since we are storing weak references, we must check whether the underlying data is valid.
+ val ref = originals.get(id)
+ if (ref eq null) {
+ None
+ } else {
+ // Since we are storing weak references, warn when the underlying data is not valid.
val acc = ref.get
if (acc eq null) {
- throw new IllegalStateException(s"Attempted to access garbage collected accumulator $id")
+ logWarning(s"Attempted to access garbage collected accumulator $id")
}
- acc
+ Option(acc)
}
}
http://git-wip-us.apache.org/repos/asf/spark/blob/6c35865d/core/src/test/scala/org/apache/spark/AccumulatorSuite.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/org/apache/spark/AccumulatorSuite.scala b/core/src/test/scala/org/apache/spark/AccumulatorSuite.scala
index 3990ee1..5d0ffd9 100644
--- a/core/src/test/scala/org/apache/spark/AccumulatorSuite.scala
+++ b/core/src/test/scala/org/apache/spark/AccumulatorSuite.scala
@@ -209,10 +209,8 @@ class AccumulatorSuite extends SparkFunSuite with Matchers with LocalSparkContex
System.gc()
assert(ref.get.isEmpty)
- // Getting a garbage collected accum should throw error
- intercept[IllegalStateException] {
- AccumulatorContext.get(accId)
- }
+ // Getting a garbage collected accum should return None.
+ assert(AccumulatorContext.get(accId).isEmpty)
// Getting a normal accumulator. Note: this has to be separate because referencing an
// accumulator above in an `assert` would keep it from being garbage collected.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org