You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by cloud-fan <gi...@git.apache.org> on 2018/10/08 17:27:28 UTC

[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

GitHub user cloud-fan opened a pull request:

    https://github.com/apache/spark/pull/22674

    [SPARK-25680][SQL] SQL execution listener shouldn't happen on execution thread

    ## What changes were proposed in this pull request?
    
    The SQL execution listener framework was created from scratch(see https://github.com/apache/spark/pull/9078). It didn't leverage what we already have in the spark listener framework, and one major problem is, the listener runs on the spark execution thread, which means a bad listener can block spark's query processing.
    
    This PR re-implements the SQL execution listener framework. Now `ExecutionListenerManager` is just a normal spark listener, which watches the `SparkListenerSQLExecutionEnd` events and post events to the 
    SQL execution listeners.
    
    ## How was this patch tested?
    
    existing tests.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/cloud-fan/spark listener

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/22674.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #22674
    
----
commit 1701f3b9df78babef60d3f0cad12a332e3f24ec8
Author: Wenchen Fan <we...@...>
Date:   2018-10-08T17:18:44Z

    SQL execution listener shouldn't happen on execution thread

----


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97200 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97200/testReport)** for PR 22674 at commit [`a25524b`](https://github.com/apache/spark/commit/a25524b36c2fe85d3ee443e3bd0c6e7b447085fe).
     * This patch **fails MiMa tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97251 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97251/testReport)** for PR 22674 at commit [`3ffa536`](https://github.com/apache/spark/commit/3ffa536f3c29f6655843a4d45c215393f51e23c9).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223886858
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,74 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    -
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +// The `session` is used to indicate which session carries this listener manager, and we only
    +// catch SQL executions which are launched by the same session.
    +// The `loadExtensions` flag is used to indicate whether we should load the pre-defined,
    +// user-specified listeners during construction. We should not do it when cloning this listener
    +// manager, as we will copy all listeners to the cloned listener manager.
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    +  extends SparkListener with Logging {
    +
    +  private[this] val listeners = new CopyOnWriteArrayList[QueryExecutionListener]
    +
    +  if (loadExtensions) {
    +    val conf = session.sparkContext.conf
         conf.get(QUERY_EXECUTION_LISTENERS).foreach { classNames =>
           Utils.loadExtensions(classOf[QueryExecutionListener], classNames, conf).foreach(register)
         }
       }
     
    +  session.sparkContext.listenerBus.addToSharedQueue(this)
    +
       /**
        * Registers the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def register(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners += listener
    +  def register(listener: QueryExecutionListener): Unit = {
    +    listeners.add(listener)
       }
     
       /**
        * Unregisters the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def unregister(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners -= listener
    +  def unregister(listener: QueryExecutionListener): Unit = {
    +    listeners.remove(listener)
       }
     
       /**
        * Removes all the registered [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def clear(): Unit = writeLock {
    +  def clear(): Unit = {
         listeners.clear()
       }
     
       /**
        * Get an identical copy of this listener manager.
        */
    -  @DeveloperApi
    -  override def clone(): ExecutionListenerManager = writeLock {
    -    val newListenerManager = new ExecutionListenerManager
    -    listeners.foreach(newListenerManager.register)
    +  private[sql] def clone(session: SparkSession): ExecutionListenerManager = {
    +    val newListenerManager = new ExecutionListenerManager(session, loadExtensions = false)
    +    listeners.iterator().asScala.foreach(newListenerManager.register)
         newListenerManager
       }
     
    -  private[sql] def onSuccess(funcName: String, qe: QueryExecution, duration: Long): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onSuccess(funcName, qe, duration)
    +  override def onOtherEvent(event: SparkListenerEvent): Unit = event match {
    +    case e: SparkListenerSQLExecutionEnd if shouldCatchEvent(e) =>
    +      val funcName = e.executionName.get
    +      e.executionFailure match {
    +        case Some(ex) =>
    +          listeners.iterator().asScala.foreach(_.onFailure(funcName, e.qe, ex))
    --- End diff --
    
    This is a bit of high level thought, you could consider making the calling event queue responsible for the dispatch of these events. That way you can leverage any improvement to the underlying event bus.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97161 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97161/testReport)** for PR 22674 at commit [`642ddd3`](https://github.com/apache/spark/commit/642ddd321dd4aa196329308ba16195b8bf35a4bf).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97140 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97140/testReport)** for PR 22674 at commit [`a456226`](https://github.com/apache/spark/commit/a4562264c45c24a88f4d508c2d34d4e7aed50631).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97269/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97122 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97122/testReport)** for PR 22674 at commit [`1701f3b`](https://github.com/apache/spark/commit/1701f3b9df78babef60d3f0cad12a332e3f24ec8).
     * This patch **fails MiMa tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3822/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97161/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97291 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97291/testReport)** for PR 22674 at commit [`6e3a345`](https://github.com/apache/spark/commit/6e3a345dd2cfc8071efdacf2a37677a588e00b6d).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224007732
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala ---
    @@ -3356,21 +3356,11 @@ class Dataset[T] private[sql](
        * user-registered callback functions.
        */
       private def withAction[U](name: String, qe: QueryExecution)(action: SparkPlan => U) = {
    -    try {
    -      qe.executedPlan.foreach { plan =>
    -        plan.resetMetrics()
    -      }
    -      val start = System.nanoTime()
    -      val result = SQLExecution.withNewExecutionId(sparkSession, qe) {
    -        action(qe.executedPlan)
    -      }
    -      val end = System.nanoTime()
    -      sparkSession.listenerManager.onSuccess(name, qe, end - start)
    -      result
    -    } catch {
    -      case e: Exception =>
    -        sparkSession.listenerManager.onFailure(name, qe, e)
    -        throw e
    +    qe.executedPlan.foreach { plan =>
    --- End diff --
    
    I don't think `resetMetrics` can throw exception...


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97200 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97200/testReport)** for PR 22674 at commit [`a25524b`](https://github.com/apache/spark/commit/a25524b36c2fe85d3ee443e3bd0c6e7b447085fe).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by dongjoon-hyun <gi...@git.apache.org>.
Github user dongjoon-hyun commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223450058
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,70 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    +  extends SparkListener with Logging {
     
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +  private[this] val listeners = new CopyOnWriteArrayList[QueryExecutionListener]
    +
    +  if (loadExtensions) {
    +    val conf = session.sparkContext.conf
         conf.get(QUERY_EXECUTION_LISTENERS).foreach { classNames =>
           Utils.loadExtensions(classOf[QueryExecutionListener], classNames, conf).foreach(register)
         }
       }
     
    +  session.sparkContext.listenerBus.addToSharedQueue(this)
    +
       /**
        * Registers the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def register(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners += listener
    +  def register(listener: QueryExecutionListener): Unit = {
    +    listeners.add(listener)
       }
     
       /**
        * Unregisters the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def unregister(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners -= listener
    +  def unregister(listener: QueryExecutionListener): Unit = {
    +    listeners.remove(listener)
       }
     
       /**
        * Removes all the registered [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def clear(): Unit = writeLock {
    +  def clear(): Unit = {
         listeners.clear()
       }
     
       /**
        * Get an identical copy of this listener manager.
        */
       @DeveloperApi
    -  override def clone(): ExecutionListenerManager = writeLock {
    -    val newListenerManager = new ExecutionListenerManager
    -    listeners.foreach(newListenerManager.register)
    +  def clone(session: SparkSession): ExecutionListenerManager = {
    --- End diff --
    
    Could you add MiMa exclusion rule?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97231/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97161 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97161/testReport)** for PR 22674 at commit [`642ddd3`](https://github.com/apache/spark/commit/642ddd321dd4aa196329308ba16195b8bf35a4bf).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3891/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3880/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3897/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by brkyvz <gi...@git.apache.org>.
Github user brkyvz commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    I would just up the timeout in that suite. Now that we're pushing a bunch more stuff to the LiveListenerBus, it may not be draining quickly enough. On slow jenkins' it could likely cause flakiness.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97159 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97159/testReport)** for PR 22674 at commit [`436197b`](https://github.com/apache/spark/commit/436197b4a395323a5ea26d194389d1c0c41cb578).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by jiangxb1987 <gi...@git.apache.org>.
Github user jiangxb1987 commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    LGTM, do you have any other concerns @hvanhovell @brkyvz @dongjoon-hyun ?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3853/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97269 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97269/testReport)** for PR 22674 at commit [`b3e546d`](https://github.com/apache/spark/commit/b3e546df4d7c0f9e55b108ebef2bc0cb54b9efec).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3810/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224071116
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala ---
    @@ -3356,21 +3356,11 @@ class Dataset[T] private[sql](
        * user-registered callback functions.
        */
       private def withAction[U](name: String, qe: QueryExecution)(action: SparkPlan => U) = {
    -    try {
    -      qe.executedPlan.foreach { plan =>
    -        plan.resetMetrics()
    -      }
    -      val start = System.nanoTime()
    -      val result = SQLExecution.withNewExecutionId(sparkSession, qe) {
    -        action(qe.executedPlan)
    -      }
    -      val end = System.nanoTime()
    -      sparkSession.listenerManager.onSuccess(name, qe, end - start)
    -      result
    -    } catch {
    -      case e: Exception =>
    -        sparkSession.listenerManager.onFailure(name, qe, e)
    -        throw e
    +    qe.executedPlan.foreach { plan =>
    --- End diff --
    
    ah i see your point here


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    I couldn't reproduce it locally, let me try again


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97251/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97397 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97397/testReport)** for PR 22674 at commit [`c42b499`](https://github.com/apache/spark/commit/c42b4999d79447d12f9bd751e13a1083dd451648).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97291 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97291/testReport)** for PR 22674 at commit [`6e3a345`](https://github.com/apache/spark/commit/6e3a345dd2cfc8071efdacf2a37677a588e00b6d).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97122 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97122/testReport)** for PR 22674 at commit [`1701f3b`](https://github.com/apache/spark/commit/1701f3b9df78babef60d3f0cad12a332e3f24ec8).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97122/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3813/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3799/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224012183
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,74 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    -
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +// The `session` is used to indicate which session carries this listener manager, and we only
    +// catch SQL executions which are launched by the same session.
    +// The `loadExtensions` flag is used to indicate whether we should load the pre-defined,
    +// user-specified listeners during construction. We should not do it when cloning this listener
    +// manager, as we will copy all listeners to the cloned listener manager.
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    +  extends SparkListener with Logging {
    +
    +  private[this] val listeners = new CopyOnWriteArrayList[QueryExecutionListener]
    +
    +  if (loadExtensions) {
    +    val conf = session.sparkContext.conf
         conf.get(QUERY_EXECUTION_LISTENERS).foreach { classNames =>
           Utils.loadExtensions(classOf[QueryExecutionListener], classNames, conf).foreach(register)
         }
       }
     
    +  session.sparkContext.listenerBus.addToSharedQueue(this)
    +
       /**
        * Registers the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def register(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners += listener
    +  def register(listener: QueryExecutionListener): Unit = {
    +    listeners.add(listener)
       }
     
       /**
        * Unregisters the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def unregister(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners -= listener
    +  def unregister(listener: QueryExecutionListener): Unit = {
    +    listeners.remove(listener)
       }
     
       /**
        * Removes all the registered [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def clear(): Unit = writeLock {
    +  def clear(): Unit = {
         listeners.clear()
       }
     
       /**
        * Get an identical copy of this listener manager.
        */
    -  @DeveloperApi
    -  override def clone(): ExecutionListenerManager = writeLock {
    -    val newListenerManager = new ExecutionListenerManager
    -    listeners.foreach(newListenerManager.register)
    +  private[sql] def clone(session: SparkSession): ExecutionListenerManager = {
    +    val newListenerManager = new ExecutionListenerManager(session, loadExtensions = false)
    +    listeners.iterator().asScala.foreach(newListenerManager.register)
         newListenerManager
       }
     
    -  private[sql] def onSuccess(funcName: String, qe: QueryExecution, duration: Long): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onSuccess(funcName, qe, duration)
    +  override def onOtherEvent(event: SparkListenerEvent): Unit = event match {
    +    case e: SparkListenerSQLExecutionEnd if shouldCatchEvent(e) =>
    +      val funcName = e.executionName.get
    +      e.executionFailure match {
    +        case Some(ex) =>
    +          listeners.iterator().asScala.foreach(_.onFailure(funcName, e.qe, ex))
    +        case _ =>
    +          listeners.iterator().asScala.foreach(_.onSuccess(funcName, e.qe, e.duration))
           }
    -    }
    -  }
     
    -  private[sql] def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onFailure(funcName, qe, exception)
    -      }
    -    }
    +    case _ => // Ignore
       }
     
    -  private[this] val listeners = ListBuffer.empty[QueryExecutionListener]
    -
    -  /** A lock to prevent updating the list of listeners while we are traversing through them. */
    -  private[this] val lock = new ReentrantReadWriteLock()
    -
    -  private def withErrorHandling(f: QueryExecutionListener => Unit): Unit = {
    -    for (listener <- listeners) {
    -      try {
    -        f(listener)
    -      } catch {
    -        case NonFatal(e) => logWarning("Error executing query execution listener", e)
    -      }
    -    }
    -  }
    -
    -  /** Acquires a read lock on the cache for the duration of `f`. */
    -  private def readLock[A](f: => A): A = {
    -    val rl = lock.readLock()
    -    rl.lock()
    -    try f finally {
    -      rl.unlock()
    -    }
    -  }
    -
    -  /** Acquires a write lock on the cache for the duration of `f`. */
    -  private def writeLock[A](f: => A): A = {
    -    val wl = lock.writeLock()
    -    wl.lock()
    -    try f finally {
    -      wl.unlock()
    -    }
    +  private def shouldCatchEvent(e: SparkListenerSQLExecutionEnd): Boolean = {
    +    // Only catch SQL execution with a name, and triggered by the same spark session that this
    --- End diff --
    
    @brkyvz thanks for the information! It seems the `StreamingQueryListener` framework picks the same idea but the implementation is better. I'll update my PR accordingly.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/22674


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97123 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97123/testReport)** for PR 22674 at commit [`28f64d0`](https://github.com/apache/spark/commit/28f64d0cda41c1effad8c96690c220431afdf6fa).
     * This patch **fails MiMa tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223873662
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,74 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    -
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +// The `session` is used to indicate which session carries this listener manager, and we only
    --- End diff --
    
    Why is this not a class doc?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3989/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97159 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97159/testReport)** for PR 22674 at commit [`436197b`](https://github.com/apache/spark/commit/436197b4a395323a5ea26d194389d1c0c41cb578).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3824/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97145 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97145/testReport)** for PR 22674 at commit [`436197b`](https://github.com/apache/spark/commit/436197b4a395323a5ea26d194389d1c0c41cb578).
     * This patch **fails due to an unknown error code, -9**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97123 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97123/testReport)** for PR 22674 at commit [`28f64d0`](https://github.com/apache/spark/commit/28f64d0cda41c1effad8c96690c220431afdf6fa).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    retest this please


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97397 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97397/testReport)** for PR 22674 at commit [`c42b499`](https://github.com/apache/spark/commit/c42b4999d79447d12f9bd751e13a1083dd451648).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97123/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97140 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97140/testReport)** for PR 22674 at commit [`a456226`](https://github.com/apache/spark/commit/a4562264c45c24a88f4d508c2d34d4e7aed50631).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by brkyvz <gi...@git.apache.org>.
Github user brkyvz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224000809
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SQLExecution.scala ---
    @@ -71,14 +72,35 @@ object SQLExecution {
           val callSite = sc.getCallSite()
     
           withSQLConfPropagated(sparkSession) {
    -        sc.listenerBus.post(SparkListenerSQLExecutionStart(
    -          executionId, callSite.shortForm, callSite.longForm, queryExecution.toString,
    -          SparkPlanInfo.fromSparkPlan(queryExecution.executedPlan), System.currentTimeMillis()))
    +        var ex: Option[Exception] = None
    +        val startTime = System.currentTimeMillis()
             try {
    +          sc.listenerBus.post(SparkListenerSQLExecutionStart(
    +            executionId = executionId,
    +            description = callSite.shortForm,
    +            details = callSite.longForm,
    +            physicalPlanDescription = queryExecution.toString,
    +            // `queryExecution.executedPlan` triggers query planning. If it fails, the exception
    +            // will be caught and reported in the `SparkListenerSQLExecutionEnd`
    +            sparkPlanInfo = SparkPlanInfo.fromSparkPlan(queryExecution.executedPlan),
    +            time = startTime))
               body
    +        } catch {
    +          case e: Exception =>
    +            ex = Some(e)
    +            throw e
             } finally {
    -          sc.listenerBus.post(SparkListenerSQLExecutionEnd(
    -            executionId, System.currentTimeMillis()))
    +          val endTime = System.currentTimeMillis()
    +          val event = SparkListenerSQLExecutionEnd(executionId, endTime)
    +          // Currently only `Dataset.withAction` and `DataFrameWriter.runCommand` specify the `name`
    +          // parameter. The `ExecutionListenerManager` only watches SQL executions with name. We
    +          // can specify the execution name in more places in the future, so that
    +          // `QueryExecutionListener` can track more cases.
    +          event.executionName = name
    +          event.duration = endTime - startTime
    --- End diff --
    
    duration used to be reported in nanos. Now it's millis. I would still report it as nanos if possible.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97140/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97203 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97203/testReport)** for PR 22674 at commit [`3ffa536`](https://github.com/apache/spark/commit/3ffa536f3c29f6655843a4d45c215393f51e23c9).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3852/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by brkyvz <gi...@git.apache.org>.
Github user brkyvz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224006828
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,74 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    -
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +// The `session` is used to indicate which session carries this listener manager, and we only
    +// catch SQL executions which are launched by the same session.
    +// The `loadExtensions` flag is used to indicate whether we should load the pre-defined,
    +// user-specified listeners during construction. We should not do it when cloning this listener
    +// manager, as we will copy all listeners to the cloned listener manager.
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    +  extends SparkListener with Logging {
    +
    +  private[this] val listeners = new CopyOnWriteArrayList[QueryExecutionListener]
    +
    +  if (loadExtensions) {
    +    val conf = session.sparkContext.conf
         conf.get(QUERY_EXECUTION_LISTENERS).foreach { classNames =>
           Utils.loadExtensions(classOf[QueryExecutionListener], classNames, conf).foreach(register)
         }
       }
     
    +  session.sparkContext.listenerBus.addToSharedQueue(this)
    +
       /**
        * Registers the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def register(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners += listener
    +  def register(listener: QueryExecutionListener): Unit = {
    +    listeners.add(listener)
       }
     
       /**
        * Unregisters the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def unregister(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners -= listener
    +  def unregister(listener: QueryExecutionListener): Unit = {
    +    listeners.remove(listener)
       }
     
       /**
        * Removes all the registered [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def clear(): Unit = writeLock {
    +  def clear(): Unit = {
         listeners.clear()
       }
     
       /**
        * Get an identical copy of this listener manager.
        */
    -  @DeveloperApi
    -  override def clone(): ExecutionListenerManager = writeLock {
    -    val newListenerManager = new ExecutionListenerManager
    -    listeners.foreach(newListenerManager.register)
    +  private[sql] def clone(session: SparkSession): ExecutionListenerManager = {
    +    val newListenerManager = new ExecutionListenerManager(session, loadExtensions = false)
    +    listeners.iterator().asScala.foreach(newListenerManager.register)
         newListenerManager
       }
     
    -  private[sql] def onSuccess(funcName: String, qe: QueryExecution, duration: Long): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onSuccess(funcName, qe, duration)
    +  override def onOtherEvent(event: SparkListenerEvent): Unit = event match {
    +    case e: SparkListenerSQLExecutionEnd if shouldCatchEvent(e) =>
    +      val funcName = e.executionName.get
    +      e.executionFailure match {
    +        case Some(ex) =>
    +          listeners.iterator().asScala.foreach(_.onFailure(funcName, e.qe, ex))
    +        case _ =>
    +          listeners.iterator().asScala.foreach(_.onSuccess(funcName, e.qe, e.duration))
           }
    -    }
    -  }
     
    -  private[sql] def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onFailure(funcName, qe, exception)
    -      }
    -    }
    +    case _ => // Ignore
       }
     
    -  private[this] val listeners = ListBuffer.empty[QueryExecutionListener]
    -
    -  /** A lock to prevent updating the list of listeners while we are traversing through them. */
    -  private[this] val lock = new ReentrantReadWriteLock()
    -
    -  private def withErrorHandling(f: QueryExecutionListener => Unit): Unit = {
    -    for (listener <- listeners) {
    -      try {
    -        f(listener)
    -      } catch {
    -        case NonFatal(e) => logWarning("Error executing query execution listener", e)
    -      }
    -    }
    -  }
    -
    -  /** Acquires a read lock on the cache for the duration of `f`. */
    -  private def readLock[A](f: => A): A = {
    -    val rl = lock.readLock()
    -    rl.lock()
    -    try f finally {
    -      rl.unlock()
    -    }
    -  }
    -
    -  /** Acquires a write lock on the cache for the duration of `f`. */
    -  private def writeLock[A](f: => A): A = {
    -    val wl = lock.writeLock()
    -    wl.lock()
    -    try f finally {
    -      wl.unlock()
    -    }
    +  private def shouldCatchEvent(e: SparkListenerSQLExecutionEnd): Boolean = {
    +    // Only catch SQL execution with a name, and triggered by the same spark session that this
    --- End diff --
    
    we had the same problem in the StreamingQueryListener. You can check how we solved it in `StreamExecution`. Since each SparkSession will have its own ExecutionListenerManager, you may be able to only have the proper ExecutionListenerManager deal with its own messages.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224008348
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SQLExecution.scala ---
    @@ -71,14 +72,35 @@ object SQLExecution {
           val callSite = sc.getCallSite()
     
           withSQLConfPropagated(sparkSession) {
    -        sc.listenerBus.post(SparkListenerSQLExecutionStart(
    -          executionId, callSite.shortForm, callSite.longForm, queryExecution.toString,
    -          SparkPlanInfo.fromSparkPlan(queryExecution.executedPlan), System.currentTimeMillis()))
    +        var ex: Option[Exception] = None
    +        val startTime = System.currentTimeMillis()
             try {
    +          sc.listenerBus.post(SparkListenerSQLExecutionStart(
    +            executionId = executionId,
    +            description = callSite.shortForm,
    +            details = callSite.longForm,
    +            physicalPlanDescription = queryExecution.toString,
    +            // `queryExecution.executedPlan` triggers query planning. If it fails, the exception
    +            // will be caught and reported in the `SparkListenerSQLExecutionEnd`
    +            sparkPlanInfo = SparkPlanInfo.fromSparkPlan(queryExecution.executedPlan),
    +            time = startTime))
               body
    +        } catch {
    +          case e: Exception =>
    +            ex = Some(e)
    +            throw e
             } finally {
    -          sc.listenerBus.post(SparkListenerSQLExecutionEnd(
    -            executionId, System.currentTimeMillis()))
    +          val endTime = System.currentTimeMillis()
    +          val event = SparkListenerSQLExecutionEnd(executionId, endTime)
    +          // Currently only `Dataset.withAction` and `DataFrameWriter.runCommand` specify the `name`
    +          // parameter. The `ExecutionListenerManager` only watches SQL executions with name. We
    +          // can specify the execution name in more places in the future, so that
    +          // `QueryExecutionListener` can track more cases.
    +          event.executionName = name
    +          event.duration = endTime - startTime
    --- End diff --
    
    ah good catch!


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3869/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97277 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97277/testReport)** for PR 22674 at commit [`0bfc240`](https://github.com/apache/spark/commit/0bfc2408a5941d7da8d93582668ba77a7394ac66).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by brkyvz <gi...@git.apache.org>.
Github user brkyvz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224013755
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala ---
    @@ -3356,21 +3356,11 @@ class Dataset[T] private[sql](
        * user-registered callback functions.
        */
       private def withAction[U](name: String, qe: QueryExecution)(action: SparkPlan => U) = {
    -    try {
    -      qe.executedPlan.foreach { plan =>
    -        plan.resetMetrics()
    -      }
    -      val start = System.nanoTime()
    -      val result = SQLExecution.withNewExecutionId(sparkSession, qe) {
    -        action(qe.executedPlan)
    -      }
    -      val end = System.nanoTime()
    -      sparkSession.listenerManager.onSuccess(name, qe, end - start)
    -      result
    -    } catch {
    -      case e: Exception =>
    -        sparkSession.listenerManager.onFailure(name, qe, e)
    -        throw e
    +    qe.executedPlan.foreach { plan =>
    --- End diff --
    
    can't executedPlan throw an exception? I thought it can if the original spark plan failed?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97159/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97277/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97203/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97397/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223910145
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,74 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    -
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +// The `session` is used to indicate which session carries this listener manager, and we only
    --- End diff --
    
    The constructor is private, so we should not make it visible in the class doc


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97203 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97203/testReport)** for PR 22674 at commit [`3ffa536`](https://github.com/apache/spark/commit/3ffa536f3c29f6655843a4d45c215393f51e23c9).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97145/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223873406
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLListener.scala ---
    @@ -39,7 +39,14 @@ case class SparkListenerSQLExecutionStart(
     
     @DeveloperApi
     case class SparkListenerSQLExecutionEnd(executionId: Long, time: Long)
    -  extends SparkListenerEvent
    +  extends SparkListenerEvent {
    +
    +  @JsonIgnore private[sql] var executionName: Option[String] = None
    --- End diff --
    
    Why do we want to be backwards compatible here? SHS?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97251 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97251/testReport)** for PR 22674 at commit [`3ffa536`](https://github.com/apache/spark/commit/3ffa536f3c29f6655843a4d45c215393f51e23c9).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by jiangxb1987 <gi...@git.apache.org>.
Github user jiangxb1987 commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    retest this please


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3800/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223910082
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLListener.scala ---
    @@ -39,7 +39,14 @@ case class SparkListenerSQLExecutionStart(
     
     @DeveloperApi
     case class SparkListenerSQLExecutionEnd(executionId: Long, time: Long)
    -  extends SparkListenerEvent
    +  extends SparkListenerEvent {
    +
    +  @JsonIgnore private[sql] var executionName: Option[String] = None
    --- End diff --
    
    that said, a developer can write a spark listener and catch this event.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97145 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97145/testReport)** for PR 22674 at commit [`436197b`](https://github.com/apache/spark/commit/436197b4a395323a5ea26d194389d1c0c41cb578).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by jiangxb1987 <gi...@git.apache.org>.
Github user jiangxb1987 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223729445
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,69 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    --- End diff --
    
    nit: we shall add param comments.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223885742
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,74 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    -
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +// The `session` is used to indicate which session carries this listener manager, and we only
    +// catch SQL executions which are launched by the same session.
    +// The `loadExtensions` flag is used to indicate whether we should load the pre-defined,
    +// user-specified listeners during construction. We should not do it when cloning this listener
    +// manager, as we will copy all listeners to the cloned listener manager.
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    +  extends SparkListener with Logging {
    +
    +  private[this] val listeners = new CopyOnWriteArrayList[QueryExecutionListener]
    +
    +  if (loadExtensions) {
    +    val conf = session.sparkContext.conf
         conf.get(QUERY_EXECUTION_LISTENERS).foreach { classNames =>
           Utils.loadExtensions(classOf[QueryExecutionListener], classNames, conf).foreach(register)
         }
       }
     
    +  session.sparkContext.listenerBus.addToSharedQueue(this)
    +
       /**
        * Registers the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def register(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners += listener
    +  def register(listener: QueryExecutionListener): Unit = {
    +    listeners.add(listener)
       }
     
       /**
        * Unregisters the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def unregister(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners -= listener
    +  def unregister(listener: QueryExecutionListener): Unit = {
    +    listeners.remove(listener)
       }
     
       /**
        * Removes all the registered [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def clear(): Unit = writeLock {
    +  def clear(): Unit = {
         listeners.clear()
       }
     
       /**
        * Get an identical copy of this listener manager.
        */
    -  @DeveloperApi
    -  override def clone(): ExecutionListenerManager = writeLock {
    -    val newListenerManager = new ExecutionListenerManager
    -    listeners.foreach(newListenerManager.register)
    +  private[sql] def clone(session: SparkSession): ExecutionListenerManager = {
    +    val newListenerManager = new ExecutionListenerManager(session, loadExtensions = false)
    +    listeners.iterator().asScala.foreach(newListenerManager.register)
         newListenerManager
       }
     
    -  private[sql] def onSuccess(funcName: String, qe: QueryExecution, duration: Long): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onSuccess(funcName, qe, duration)
    +  override def onOtherEvent(event: SparkListenerEvent): Unit = event match {
    +    case e: SparkListenerSQLExecutionEnd if shouldCatchEvent(e) =>
    +      val funcName = e.executionName.get
    +      e.executionFailure match {
    +        case Some(ex) =>
    +          listeners.iterator().asScala.foreach(_.onFailure(funcName, e.qe, ex))
    +        case _ =>
    +          listeners.iterator().asScala.foreach(_.onSuccess(funcName, e.qe, e.duration))
           }
    -    }
    -  }
     
    -  private[sql] def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onFailure(funcName, qe, exception)
    -      }
    -    }
    +    case _ => // Ignore
       }
     
    -  private[this] val listeners = ListBuffer.empty[QueryExecutionListener]
    -
    -  /** A lock to prevent updating the list of listeners while we are traversing through them. */
    -  private[this] val lock = new ReentrantReadWriteLock()
    -
    -  private def withErrorHandling(f: QueryExecutionListener => Unit): Unit = {
    -    for (listener <- listeners) {
    -      try {
    -        f(listener)
    -      } catch {
    -        case NonFatal(e) => logWarning("Error executing query execution listener", e)
    -      }
    -    }
    -  }
    -
    -  /** Acquires a read lock on the cache for the duration of `f`. */
    -  private def readLock[A](f: => A): A = {
    -    val rl = lock.readLock()
    -    rl.lock()
    -    try f finally {
    -      rl.unlock()
    -    }
    -  }
    -
    -  /** Acquires a write lock on the cache for the duration of `f`. */
    -  private def writeLock[A](f: => A): A = {
    -    val wl = lock.writeLock()
    -    wl.lock()
    -    try f finally {
    -      wl.unlock()
    -    }
    +  private def shouldCatchEvent(e: SparkListenerSQLExecutionEnd): Boolean = {
    +    // Only catch SQL execution with a name, and triggered by the same spark session that this
    --- End diff --
    
    So this is what bugs me. You are adding separation between the SparkSession and its listeners, to undo that here. It seems like a bit of a hassle to go through because you basically need async execution.



---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    cc @gatorsmile @brkyvz 


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    hmm, seems it failed at the same test.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97231 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97231/testReport)** for PR 22674 at commit [`3ffa536`](https://github.com/apache/spark/commit/3ffa536f3c29f6655843a4d45c215393f51e23c9).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by brkyvz <gi...@git.apache.org>.
Github user brkyvz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224000145
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala ---
    @@ -3356,21 +3356,11 @@ class Dataset[T] private[sql](
        * user-registered callback functions.
        */
       private def withAction[U](name: String, qe: QueryExecution)(action: SparkPlan => U) = {
    -    try {
    -      qe.executedPlan.foreach { plan =>
    -        plan.resetMetrics()
    -      }
    -      val start = System.nanoTime()
    -      val result = SQLExecution.withNewExecutionId(sparkSession, qe) {
    -        action(qe.executedPlan)
    -      }
    -      val end = System.nanoTime()
    -      sparkSession.listenerManager.onSuccess(name, qe, end - start)
    -      result
    -    } catch {
    -      case e: Exception =>
    -        sparkSession.listenerManager.onFailure(name, qe, e)
    -        throw e
    +    qe.executedPlan.foreach { plan =>
    --- End diff --
    
    can this throw an exception? Imagine if `df.count()` threw an exception, and then you run it again.
    Won't this be a behavior change in that case?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97277 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97277/testReport)** for PR 22674 at commit [`0bfc240`](https://github.com/apache/spark/commit/0bfc2408a5941d7da8d93582668ba77a7394ac66).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97291/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97269 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97269/testReport)** for PR 22674 at commit [`b3e546d`](https://github.com/apache/spark/commit/b3e546df4d7c0f9e55b108ebef2bc0cb54b9efec).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    since there is no objection, I'm merging it to master, thanks!


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by brkyvz <gi...@git.apache.org>.
Github user brkyvz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224755348
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLListener.scala ---
    @@ -39,7 +39,22 @@ case class SparkListenerSQLExecutionStart(
     
     @DeveloperApi
     case class SparkListenerSQLExecutionEnd(executionId: Long, time: Long)
    -  extends SparkListenerEvent
    +  extends SparkListenerEvent {
    +
    +  // The name of the execution, e.g. `df.collect` will trigger a SQL execution with name "collect".
    +  @JsonIgnore private[sql] var executionName: Option[String] = None
    +
    +  // The following 3 fields are only accessed when `executionName` is defined.
    +
    +  // The duration of the SQL execution, in nanoseconds.
    +  @JsonIgnore private[sql] var duration: Long = 0L
    --- End diff --
    
    did you verify that the JsonIgnore annotation actually works? For some reason, I actually needed to annotate the class as
    ```scala
    @JsonIgnoreProperties(Array("a", b", "c"))
    class SomeClass {
      @JsonProperty("a") val a: ...
      @JsonProperty("b") val a: ...
    }
    ```
    
    the reason being Json4s understands that API better. I believe we use Json4s for all of these events


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223911185
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,74 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    -
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +// The `session` is used to indicate which session carries this listener manager, and we only
    +// catch SQL executions which are launched by the same session.
    +// The `loadExtensions` flag is used to indicate whether we should load the pre-defined,
    +// user-specified listeners during construction. We should not do it when cloning this listener
    +// manager, as we will copy all listeners to the cloned listener manager.
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    +  extends SparkListener with Logging {
    +
    +  private[this] val listeners = new CopyOnWriteArrayList[QueryExecutionListener]
    +
    +  if (loadExtensions) {
    +    val conf = session.sparkContext.conf
         conf.get(QUERY_EXECUTION_LISTENERS).foreach { classNames =>
           Utils.loadExtensions(classOf[QueryExecutionListener], classNames, conf).foreach(register)
         }
       }
     
    +  session.sparkContext.listenerBus.addToSharedQueue(this)
    +
       /**
        * Registers the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def register(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners += listener
    +  def register(listener: QueryExecutionListener): Unit = {
    +    listeners.add(listener)
       }
     
       /**
        * Unregisters the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def unregister(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners -= listener
    +  def unregister(listener: QueryExecutionListener): Unit = {
    +    listeners.remove(listener)
       }
     
       /**
        * Removes all the registered [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def clear(): Unit = writeLock {
    +  def clear(): Unit = {
         listeners.clear()
       }
     
       /**
        * Get an identical copy of this listener manager.
        */
    -  @DeveloperApi
    -  override def clone(): ExecutionListenerManager = writeLock {
    -    val newListenerManager = new ExecutionListenerManager
    -    listeners.foreach(newListenerManager.register)
    +  private[sql] def clone(session: SparkSession): ExecutionListenerManager = {
    +    val newListenerManager = new ExecutionListenerManager(session, loadExtensions = false)
    +    listeners.iterator().asScala.foreach(newListenerManager.register)
         newListenerManager
       }
     
    -  private[sql] def onSuccess(funcName: String, qe: QueryExecution, duration: Long): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onSuccess(funcName, qe, duration)
    +  override def onOtherEvent(event: SparkListenerEvent): Unit = event match {
    +    case e: SparkListenerSQLExecutionEnd if shouldCatchEvent(e) =>
    +      val funcName = e.executionName.get
    +      e.executionFailure match {
    +        case Some(ex) =>
    +          listeners.iterator().asScala.foreach(_.onFailure(funcName, e.qe, ex))
    +        case _ =>
    +          listeners.iterator().asScala.foreach(_.onSuccess(funcName, e.qe, e.duration))
           }
    -    }
    -  }
     
    -  private[sql] def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onFailure(funcName, qe, exception)
    -      }
    -    }
    +    case _ => // Ignore
       }
     
    -  private[this] val listeners = ListBuffer.empty[QueryExecutionListener]
    -
    -  /** A lock to prevent updating the list of listeners while we are traversing through them. */
    -  private[this] val lock = new ReentrantReadWriteLock()
    -
    -  private def withErrorHandling(f: QueryExecutionListener => Unit): Unit = {
    -    for (listener <- listeners) {
    -      try {
    -        f(listener)
    -      } catch {
    -        case NonFatal(e) => logWarning("Error executing query execution listener", e)
    -      }
    -    }
    -  }
    -
    -  /** Acquires a read lock on the cache for the duration of `f`. */
    -  private def readLock[A](f: => A): A = {
    -    val rl = lock.readLock()
    -    rl.lock()
    -    try f finally {
    -      rl.unlock()
    -    }
    -  }
    -
    -  /** Acquires a write lock on the cache for the duration of `f`. */
    -  private def writeLock[A](f: => A): A = {
    -    val wl = lock.writeLock()
    -    wl.lock()
    -    try f finally {
    -      wl.unlock()
    -    }
    +  private def shouldCatchEvent(e: SparkListenerSQLExecutionEnd): Boolean = {
    +    // Only catch SQL execution with a name, and triggered by the same spark session that this
    --- End diff --
    
    yea. Assuming we have many spark sessions, running queries at the same time. Each session sends query execution events to the central event bus, and sets up a listener to watch its own query execution events, asynchronously.
    
    To make it work, the most straightforward way is to carry the session identifier in the events, and the listener only watch events with the expected session identifier.
    
    Maybe a better way is to introduce session in the Spark core, so the listener framework can dispatch events w.r.t. session automatically. But that's a lot of work.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r224756886
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLListener.scala ---
    @@ -39,7 +39,22 @@ case class SparkListenerSQLExecutionStart(
     
     @DeveloperApi
     case class SparkListenerSQLExecutionEnd(executionId: Long, time: Long)
    -  extends SparkListenerEvent
    +  extends SparkListenerEvent {
    +
    +  // The name of the execution, e.g. `df.collect` will trigger a SQL execution with name "collect".
    +  @JsonIgnore private[sql] var executionName: Option[String] = None
    +
    +  // The following 3 fields are only accessed when `executionName` is defined.
    +
    +  // The duration of the SQL execution, in nanoseconds.
    +  @JsonIgnore private[sql] var duration: Long = 0L
    --- End diff --
    
    There is a test to verify it: https://github.com/apache/spark/pull/22674/files#diff-6fa1d00d1cb20554dda238f2a3bc3ecbR55
    
    I also used `@JsonIgnoreProperties` before, when these fields are case class fields. It seems we don't need `@JsonIgnoreProperties` when they are private `var`s.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223910477
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,74 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    -
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +// The `session` is used to indicate which session carries this listener manager, and we only
    +// catch SQL executions which are launched by the same session.
    +// The `loadExtensions` flag is used to indicate whether we should load the pre-defined,
    +// user-specified listeners during construction. We should not do it when cloning this listener
    +// manager, as we will copy all listeners to the cloned listener manager.
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    +  extends SparkListener with Logging {
    +
    +  private[this] val listeners = new CopyOnWriteArrayList[QueryExecutionListener]
    +
    +  if (loadExtensions) {
    +    val conf = session.sparkContext.conf
         conf.get(QUERY_EXECUTION_LISTENERS).foreach { classNames =>
           Utils.loadExtensions(classOf[QueryExecutionListener], classNames, conf).foreach(register)
         }
       }
     
    +  session.sparkContext.listenerBus.addToSharedQueue(this)
    +
       /**
        * Registers the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def register(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners += listener
    +  def register(listener: QueryExecutionListener): Unit = {
    +    listeners.add(listener)
       }
     
       /**
        * Unregisters the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def unregister(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners -= listener
    +  def unregister(listener: QueryExecutionListener): Unit = {
    +    listeners.remove(listener)
       }
     
       /**
        * Removes all the registered [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def clear(): Unit = writeLock {
    +  def clear(): Unit = {
         listeners.clear()
       }
     
       /**
        * Get an identical copy of this listener manager.
        */
    -  @DeveloperApi
    -  override def clone(): ExecutionListenerManager = writeLock {
    -    val newListenerManager = new ExecutionListenerManager
    -    listeners.foreach(newListenerManager.register)
    +  private[sql] def clone(session: SparkSession): ExecutionListenerManager = {
    +    val newListenerManager = new ExecutionListenerManager(session, loadExtensions = false)
    +    listeners.iterator().asScala.foreach(newListenerManager.register)
         newListenerManager
       }
     
    -  private[sql] def onSuccess(funcName: String, qe: QueryExecution, duration: Long): Unit = {
    -    readLock {
    -      withErrorHandling { listener =>
    -        listener.onSuccess(funcName, qe, duration)
    +  override def onOtherEvent(event: SparkListenerEvent): Unit = event match {
    +    case e: SparkListenerSQLExecutionEnd if shouldCatchEvent(e) =>
    +      val funcName = e.executionName.get
    +      e.executionFailure match {
    +        case Some(ex) =>
    +          listeners.iterator().asScala.foreach(_.onFailure(funcName, e.qe, ex))
    --- End diff --
    
    `ExecutionListenerManager` is already a listener, which is running in a separated thread, receiving events from `LiveListenerBus`


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223443736
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/util/QueryExecutionListener.scala ---
    @@ -75,95 +76,70 @@ trait QueryExecutionListener {
      */
     @Experimental
     @InterfaceStability.Evolving
    -class ExecutionListenerManager private extends Logging {
    +class ExecutionListenerManager private[sql](session: SparkSession, loadExtensions: Boolean)
    +  extends SparkListener with Logging {
     
    -  private[sql] def this(conf: SparkConf) = {
    -    this()
    +  private[this] val listeners = new CopyOnWriteArrayList[QueryExecutionListener]
    +
    +  if (loadExtensions) {
    +    val conf = session.sparkContext.conf
         conf.get(QUERY_EXECUTION_LISTENERS).foreach { classNames =>
           Utils.loadExtensions(classOf[QueryExecutionListener], classNames, conf).foreach(register)
         }
       }
     
    +  session.sparkContext.listenerBus.addToSharedQueue(this)
    +
       /**
        * Registers the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def register(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners += listener
    +  def register(listener: QueryExecutionListener): Unit = {
    +    listeners.add(listener)
       }
     
       /**
        * Unregisters the specified [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def unregister(listener: QueryExecutionListener): Unit = writeLock {
    -    listeners -= listener
    +  def unregister(listener: QueryExecutionListener): Unit = {
    +    listeners.remove(listener)
       }
     
       /**
        * Removes all the registered [[QueryExecutionListener]].
        */
       @DeveloperApi
    -  def clear(): Unit = writeLock {
    +  def clear(): Unit = {
         listeners.clear()
       }
     
       /**
        * Get an identical copy of this listener manager.
        */
       @DeveloperApi
    -  override def clone(): ExecutionListenerManager = writeLock {
    -    val newListenerManager = new ExecutionListenerManager
    -    listeners.foreach(newListenerManager.register)
    +  def clone(session: SparkSession): ExecutionListenerManager = {
    --- End diff --
    
    I don't know why this method is public at the first place... I have to break it here.
    



---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223443327
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLListener.scala ---
    @@ -39,7 +39,14 @@ case class SparkListenerSQLExecutionStart(
     
     @DeveloperApi
     case class SparkListenerSQLExecutionEnd(executionId: Long, time: Long)
    -  extends SparkListenerEvent
    +  extends SparkListenerEvent {
    +
    +  @JsonIgnore private[sql] var executionName: Option[String] = None
    --- End diff --
    
    For backward compatibility, I make these new fields `var`.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/97200/
    Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    retest this please


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    **[Test build #97231 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/97231/testReport)** for PR 22674 at commit [`3ffa536`](https://github.com/apache/spark/commit/3ffa536f3c29f6655843a4d45c215393f51e23c9).


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/testing-k8s-prb-make-spark-distribution-unified/3910/
    Test PASSed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #22674: [SPARK-25680][SQL] SQL execution listener shouldn...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22674#discussion_r223910028
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLListener.scala ---
    @@ -39,7 +39,14 @@ case class SparkListenerSQLExecutionStart(
     
     @DeveloperApi
     case class SparkListenerSQLExecutionEnd(executionId: Long, time: Long)
    -  extends SparkListenerEvent
    +  extends SparkListenerEvent {
    +
    +  @JsonIgnore private[sql] var executionName: Option[String] = None
    --- End diff --
    
    It's a developer api, which is public. The backward compatibility is not that strong, compared to end-user public APIs, but we should still keep them unchanged if not too hard.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #22674: [SPARK-25680][SQL] SQL execution listener shouldn't happ...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/22674
  
    Merged build finished. Test FAILed.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org