juliuszsompolski commented on code in PR #54007:
URL: https://github.com/apache/spark/pull/54007#discussion_r2735975093


##########
core/src/main/scala/org/apache/spark/util/LazyTry.scala:
##########
@@ -45,17 +45,21 @@ import scala.util.Try
 private[spark] class LazyTry[T](initialize: => T) extends Serializable {
   private lazy val tryT: Try[T] = Utils.doTryWithCallerStacktrace { initialize 
}
 
+  // Track whether the lazy val has been materialized or not.
+  @volatile private var materialized: Boolean = false
+
   /**
    * Get the lazy value. If the initialization block threw an exception, it 
will be re-thrown here.
    * The exception will be re-thrown with the current caller's stacktrace.
-   * An exception with stack trace from when the exception was first thrown 
can be accessed with
-   * ```
-   * ex.getSuppressed.find { e =>
-   *   e.getMessage == 
org.apache.spark.util.Utils.TRY_WITH_CALLER_STACKTRACE_FULL_STACKTRACE
-   * }
-   * ```
+   *
+   * On the first access, no suppressed exception is added. On subsequent 
accesses, the original
+   * stacktrace is added as a suppressed exception to help with debugging.
    */
-  def get: T = Utils.getTryWithCallerStacktrace(tryT)
+  def get: T = {
+    val isFirstAccess = !materialized
+    materialized = true
+    Utils.getTryWithCallerStacktrace(tryT, isFirstAccess)

Review Comment:
   nit: I don't think it matters much as there are some atomicity problems with 
resetting the trace anyway, but maybe use AtomicBoolean and just call 
`Utils.getTryWithCallerStacktrace(tryT, !materialized.getAndSet(true))`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to