Github user CodingCat commented on a diff in the pull request:
https://github.com/apache/spark/pull/228#discussion_r10948890
--- Diff: core/src/main/scala/org/apache/spark/Accumulators.scala ---
@@ -43,8 +44,10 @@ class Accumulable[R, T] (
param: AccumulableParam[R, T])
extends Serializable {
- val id = Accumulators.newId
- @transient private var value_ = initialValue // Current value on master
+ val id = Accumulators.nextAccumID.get()
+ Accumulators.nextAccumID.getAndIncrement
--- End diff --
In the original implementation, id is an integer and increased with
synchronized{} guard, just make it as an AtomicLong for convenience. Here the
two lines are get the value and increment
Ah, I think I know why you are confused here, the more straightforward way
seems to be
```
val id = Accumulator.nextAccumID.getAndIncrement
```
I tried that, but I found that the id field will be called for two times
during the initilaization(?) of a task, so for every time, the id is
increased...
I have to get the value when call id but increment in the constructor of
Accumulable
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---