trait LastAttemptAccumulator[IN, OUT, PARTIAL] extends Logging
A trait that can be mixed into a subclass of AccumulatorV2 to track the "logical" value of the "last attempt" of the execution using the accumulator - aggregated from the last attempts of any Task that calculated some RDD partitions and used this accumulator, and discarding any values coming from earlier attempts that have been recomputed. If the accumulator is used by multiple RDDs, the last attempt value is tracked separately for each, and can be retrieved for each or all of them separately, see lastAttemptValueForX methods. If the accumulator is used directly on the Spark Driver using AccumulatorV2#add, that value is considered the last attempt value. If the accumulator was both used in Tasks and updated directly on the driver, it can't determine what should be considered the last attempt, and lastAttemptValueForX methods will return None.
Contract for driver-only updates: A driver-side value (set via AccumulatorV2#add on the driver, outside any Task) is only returned by methods that do not narrow by RDD, namely lastAttemptValueForAllRDDs and lastAttemptValueForHighestRDDId. Methods that narrow to specific RDDs or RDD scopes (lastAttemptValueForRDDId, lastAttemptValueForRDDIds, lastAttemptValueForRDDScopes) return the zero value when a driver-only value is present, because a driver-side update cannot be attributed to any particular RDD or scope.
LastAttemptAccumulator is not reset by the AccumulatorV2#reset method implementation, and its state is not copied by the AccumulatorV2#copy method implementation, and it should not be serialized to the Executors. The internal state should only be initialized by the initializeLastAttemptAccumulator method on the "main" instance of the accumulator, that was created and registered with AccumulatorContext with AccumulatorV2#register. All the interfaces of LastAttemptAccumulator: mergeLastAttempt (used only by DAGScheduler) and lastAttemptValueForX, logAccumulatorState (used by the using code) should only be invoked on that instance, on the Spark Driver.
The LastAttemptAccumulator is not thread-safe. mergeLastAttempt should only be used by DAGScheduler, by the scheduler thread. Retrieving the value using lastAttemptValueForXXX while it is concurrently updated (execution is running) can produce some inconsistencies, but should not crash. If an RDD using the LastAttemptAccumulator is used concurrently by multiple actions that all try to recompute it, it may produce unexpected results and the semantics of what is "last attempt" becomes ambiguous. This should not be done in practice, and will likely result in more unexpected behaviours in Spark.
Implementations must implement partialMergeVal and partialMerge methods operating on PARTIAL type. In regular AccumulatorV2 implementations, the AccumulatorV2 object itself holds the intermediate value of the accumulator, and AccumulatorV2#merge method is used to merge these objects together. LastAttemptAccumulator needs to keep track of partial values of every partition of every RDD that used the accumulator, and holding a full AccumulatorV2 object for each would have a high overhead. Therefore, an implementation should be able to return PARTIAL value from partialMergeVal that represents an intermediate mergeable value, and a partialMerge method that can merge that value into the accumulator. Implementations must also implement an isMergeable method that checks if the other AccumulatorV2 is of a compatible type to be merged with this using partialMergeVal. In regular AccumulatorV2 implementations, this check is normally done inside the AccumulatorV2#merge method, which is not used here.
If an implementation is used to keep user data in the accumulator, it should override accumulatorStoresUserData to return true, to ensure correct structured logging annotation. Otherwise it should override it to false.
- Self Type
- LastAttemptAccumulator[IN, OUT, PARTIAL] with AccumulatorV2[IN, OUT]
- Source
- LastAttemptAccumulator.scala
- Alphabetic
- By Inheritance
- LastAttemptAccumulator
- Logging
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- implicit class LogStringContext extends AnyRef
- Definition Classes
- Logging
Abstract Value Members
- abstract def accumulatorStoresUserData: Boolean
Accumulator subclasses where metric values can contain user data (for example, maximum of processed values, observable metrics) as opposed to system measurements (for example, count of processed rows) should return true to ensure correct structured logging annotation.
Accumulator subclasses where metric values can contain user data (for example, maximum of processed values, observable metrics) as opposed to system measurements (for example, count of processed rows) should return true to ensure correct structured logging annotation.
- Attributes
- protected
- abstract def isMergeable(other: AccumulatorV2[_, _]): Boolean
Check if the other accumulator is mergeable with this one.
Check if the other accumulator is mergeable with this one.
- Attributes
- protected
- abstract def partialMerge(otherVal: PARTIAL): Unit
Merge together partial values of PARTIAL type returned by partialMergeVal.
Merge together partial values of PARTIAL type returned by partialMergeVal.
- Attributes
- protected
- abstract def partialMergeVal: PARTIAL
Return intermediate value of PARTIAL type that can be merged together by partialMerge.
Return intermediate value of PARTIAL type that can be merged together by partialMerge.
- Attributes
- protected
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def MDC(key: LogKey, value: Any): MDC
- Attributes
- protected
- Definition Classes
- Logging
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def assertValid(): Unit
Set of assertions that should always hold for a valid LastAttemptAccumulator.
Set of assertions that should always hold for a valid LastAttemptAccumulator.
- Attributes
- protected
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def getDirectDriverValue: Option[OUT]
Visible for testing.
- def getHighestRDDId: Option[Int]
Visible for testing
- def getNumRDDs: Int
Visible for testing
- def getValid: Boolean
Visible for testing
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def initializeLastAttemptAccumulator()(implicit ct: ClassTag[PARTIAL]): Unit
- def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
- Attributes
- protected
- Definition Classes
- Logging
- def initializeLogIfNecessary(isInterpreter: Boolean): Unit
- Attributes
- protected
- Definition Classes
- Logging
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isTraceEnabled(): Boolean
- Attributes
- protected
- Definition Classes
- Logging
- val lastAttemptAccumulatorInitialized: Boolean
- Attributes
- protected
- Annotations
- @transient()
- val lastAttemptAccumulatorInvalid: Boolean
- Attributes
- protected
- Annotations
- @transient()
- def lastAttemptValueForAllRDDs(): Option[OUT]
Returns the last attempt value of this accumulator, aggregated from all RDDs that ever returned any values for it.
Returns the last attempt value of this accumulator, aggregated from all RDDs that ever returned any values for it.
If the metric was used directly on the driver, and was not used in any RDD execution, the driver value will be used instead.
Should be used only on the Spark Driver, on the instance of LastAttemptAccumulator that was created and registered in AccumulatorContext by AccumulatorV2#register.
- returns
None if the last attempt value cannot be established, Some(value) otherwise.
- def lastAttemptValueForHighestRDDId(): Option[OUT]
Returns the last attempt value of this accumulator, aggregated from the RDD with the highest id that ever returned any values for it.
Returns the last attempt value of this accumulator, aggregated from the RDD with the highest id that ever returned any values for it.
If the metric was used directly on the driver, and was not used in any RDD execution, the driver value will be used instead.
Should be used only on the Spark Driver, on the instance of LastAttemptAccumulator that was created and registered in AccumulatorContext by AccumulatorV2#register.
- returns
None if the last attempt value cannot be established, Some(value) otherwise.
- def lastAttemptValueForRDDId(rddId: Int): Option[OUT]
Returns the last attempt value of this accumulator, aggregated from a specific RDD.
Returns the last attempt value of this accumulator, aggregated from a specific RDD.
Should be used only on the Spark Driver, on the instance of LastAttemptAccumulator that was created and registered in AccumulatorContext by AccumulatorV2#register.
- returns
None if the last attempt value cannot be established, Some(value) otherwise.
- def lastAttemptValueForRDDIds(rddIds: Seq[Int]): Option[OUT]
Returns the last attempt value of this accumulator, aggregated from a set of RDDs.
Returns the last attempt value of this accumulator, aggregated from a set of RDDs.
Should be used only on the Spark Driver, on the instance of LastAttemptAccumulator that was created and registered in AccumulatorContext by AccumulatorV2#register.
- returns
None if the last attempt value cannot be established, Some(value) otherwise.
- def lastAttemptValueForRDDScopes(rddScopeIds: Seq[String]): Option[OUT]
Returns the last attempt value of this accumulator, aggregated from RDDs with given scope ids.
Returns the last attempt value of this accumulator, aggregated from RDDs with given scope ids.
Should be used only on the Spark Driver, on the instance of LastAttemptAccumulator that was created and registered in AccumulatorContext by AccumulatorV2#register.
- returns
None if the last attempt value cannot be established, Some(value) otherwise.
- def log: Logger
- Attributes
- protected
- Definition Classes
- Logging
- def logAccumulatorState: LogEntry
Log entry to log debug information about the internal state of the accumulator.
- def logBasedOnLevel(level: Level)(f: => MessageWithContext): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logDebug(msg: => String, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logDebug(entry: LogEntry, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logDebug(entry: LogEntry): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logDebug(msg: => String): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logError(msg: => String, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logError(entry: LogEntry, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logError(entry: LogEntry): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logError(msg: => String): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logInfo(msg: => String, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logInfo(entry: LogEntry, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logInfo(entry: LogEntry): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logInfo(msg: => String): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logKeyAccumulatorState: LogKey
- Attributes
- protected
- def logName: String
- Attributes
- protected
- Definition Classes
- Logging
- def logTrace(msg: => String, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logTrace(entry: LogEntry, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logTrace(entry: LogEntry): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logTrace(msg: => String): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logWarning(msg: => String, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logWarning(entry: LogEntry, throwable: Throwable): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logWarning(entry: LogEntry): Unit
- Attributes
- protected
- Definition Classes
- Logging
- def logWarning(msg: => String): Unit
- Attributes
- protected
- Definition Classes
- Logging
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- def resetLastAttemptAccumulator(): Unit
Reset the state of the last attempt accumulator, discarding all the past attempts, and making it valid again if it was invalidated.
- def setValueIfOnDriverSide(value: OUT): Unit
Check if the value is set on the driver side, not from within a task.
Check if the value is set on the driver side, not from within a task. This must be called from
addandsetmethods of any AccumulatorV2 subclass supporting last attempt metrics to set what thevalueof the metric is after the operation.- Attributes
- protected
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unexpectedLastAttemptMetricOperation(invalidate: Boolean, reason: String, exception: Option[Throwable] = None): Unit
- Attributes
- protected
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def withLogContext(context: Map[String, String])(body: => Unit): Unit
- Attributes
- protected
- Definition Classes
- Logging
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)