Packages

t

org.apache.spark.util

LastAttemptAccumulator

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
Linear Supertypes
Logging, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LastAttemptAccumulator
  2. Logging
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. implicit class LogStringContext extends AnyRef
    Definition Classes
    Logging

Abstract Value Members

  1. 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
  2. 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
  3. 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
  4. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def MDC(key: LogKey, value: Any): MDC
    Attributes
    protected
    Definition Classes
    Logging
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. 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
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  11. def getDirectDriverValue: Option[OUT]

    Visible for testing.

  12. def getHighestRDDId: Option[Int]

    Visible for testing

  13. def getNumRDDs: Int

    Visible for testing

  14. def getValid: Boolean

    Visible for testing

  15. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  16. def initializeLastAttemptAccumulator()(implicit ct: ClassTag[PARTIAL]): Unit
  17. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  18. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  21. val lastAttemptAccumulatorInitialized: Boolean
    Attributes
    protected
    Annotations
    @transient()
  22. val lastAttemptAccumulatorInvalid: Boolean
    Attributes
    protected
    Annotations
    @transient()
  23. 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.

  24. 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.

  25. 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.

  26. 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.

  27. 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.

  28. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  29. def logAccumulatorState: LogEntry

    Log entry to log debug information about the internal state of the accumulator.

  30. def logBasedOnLevel(level: Level)(f: => MessageWithContext): Unit
    Attributes
    protected
    Definition Classes
    Logging
  31. def logDebug(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  32. def logDebug(entry: LogEntry, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  33. def logDebug(entry: LogEntry): Unit
    Attributes
    protected
    Definition Classes
    Logging
  34. def logDebug(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  35. def logError(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  36. def logError(entry: LogEntry, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  37. def logError(entry: LogEntry): Unit
    Attributes
    protected
    Definition Classes
    Logging
  38. def logError(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  39. def logInfo(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  40. def logInfo(entry: LogEntry, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  41. def logInfo(entry: LogEntry): Unit
    Attributes
    protected
    Definition Classes
    Logging
  42. def logInfo(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  43. def logKeyAccumulatorState: LogKey
    Attributes
    protected
  44. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  45. def logTrace(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  46. def logTrace(entry: LogEntry, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  47. def logTrace(entry: LogEntry): Unit
    Attributes
    protected
    Definition Classes
    Logging
  48. def logTrace(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  49. def logWarning(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  50. def logWarning(entry: LogEntry, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  51. def logWarning(entry: LogEntry): Unit
    Attributes
    protected
    Definition Classes
    Logging
  52. def logWarning(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  53. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  54. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  55. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  56. 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.

  57. 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 add and set methods of any AccumulatorV2 subclass supporting last attempt metrics to set what the value of the metric is after the operation.

    Attributes
    protected
  58. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  59. def toString(): String
    Definition Classes
    AnyRef → Any
  60. def unexpectedLastAttemptMetricOperation(invalidate: Boolean, reason: String, exception: Option[Throwable] = None): Unit
    Attributes
    protected
  61. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  62. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  63. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  64. def withLogContext(context: Map[String, String])(body: => Unit): Unit
    Attributes
    protected
    Definition Classes
    Logging

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from Logging

Inherited from AnyRef

Inherited from Any

Ungrouped