aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/org/apache/spark/Accumulable.scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/scala/org/apache/spark/Accumulable.scala')
-rw-r--r--core/src/main/scala/org/apache/spark/Accumulable.scala10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/src/main/scala/org/apache/spark/Accumulable.scala b/core/src/main/scala/org/apache/spark/Accumulable.scala
index 5c6761eb76..812145aaee 100644
--- a/core/src/main/scala/org/apache/spark/Accumulable.scala
+++ b/core/src/main/scala/org/apache/spark/Accumulable.scala
@@ -110,7 +110,13 @@ class Accumulable[R, T] private (
/**
* Access the accumulator's current value; only allowed on driver.
*/
- def value: R = newAcc.value
+ def value: R = {
+ if (newAcc.isAtDriverSide) {
+ newAcc.value
+ } else {
+ throw new UnsupportedOperationException("Can't read accumulator value in task")
+ }
+ }
/**
* Get the current value of this accumulator from within a task.
@@ -121,7 +127,7 @@ class Accumulable[R, T] private (
* The typical use of this method is to directly mutate the local value, eg., to add
* an element to a Set.
*/
- def localValue: R = newAcc.localValue
+ def localValue: R = newAcc.value
/**
* Set the accumulator's value; only allowed on driver.