You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by lw-lin <gi...@git.apache.org> on 2016/06/15 14:31:05 UTC

[GitHub] spark pull request #13685: [SPARK-15963][CORE] Catch `TaskKilledException` c...

GitHub user lw-lin opened a pull request:

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

    [SPARK-15963][CORE] Catch `TaskKilledException` correctly in Executor.TaskRunner

    ## What changes were proposed in this pull request?
    
    Currently in [Executor.TaskRunner](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/executor/Executor.scala#L362), we:
    ``` scala
    try {...}
    catch {
      case _: TaskKilledException | _: InterruptedException if task.killed =>
      ...
    }
    ```
    What we intended was:
    - `TaskKilledException` **OR** **(**`InterruptedException` **AND** `task.killed`**)**
    
    But fact is:
    - **(**`TaskKilledException` **OR** `InterruptedException`**)** **AND** `task.killed`
    
    As a consequence, sometimes we can not catch `TaskKilledException` and will incorrectly report our task status as `FAILED` (which should really be `KILLED`).
    
    This patch fixes this.
    
    ## How was this patch tested?
    
    This should be easy to reason (also we don't have any test case for TaskRunner yet?)
    


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

    $ git pull https://github.com/lw-lin/spark fix-task-killed

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

    https://github.com/apache/spark/pull/13685.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 #13685
    
----
commit 777959e6a6b9a2e21a32aec6b0bd6850d6513474
Author: Liwei Lin <lw...@gmail.com>
Date:   2016-06-15T14:09:22Z

    Break the case killed and interrupted into two

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #13685: [SPARK-15963][CORE] Catch `TaskKilledException` c...

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

    https://github.com/apache/spark/pull/13685#discussion_r68095488
  
    --- Diff: core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala ---
    @@ -0,0 +1,123 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.executor
    +
    +import java.nio.ByteBuffer
    +import java.util.concurrent.CountDownLatch
    +
    +import scala.collection.mutable.HashMap
    +
    +import org.mockito.Matchers._
    +import org.mockito.Mockito.{mock, when}
    +import org.mockito.invocation.InvocationOnMock
    +import org.mockito.stubbing.Answer
    +
    +import org.apache.spark._
    +import org.apache.spark.TaskState.TaskState
    +import org.apache.spark.memory.MemoryManager
    +import org.apache.spark.rpc.RpcEnv
    +import org.apache.spark.scheduler.{FakeTask, Task}
    +import org.apache.spark.serializer.JavaSerializer
    +
    +class ExecutorSuite extends SparkFunSuite {
    +
    +  test("SPARK-15963: Catch `TaskKilledException` correctly in Executor.TaskRunner") {
    +    // mock some objects to make Executor.launchTask() happy
    +    val conf = new SparkConf
    +    val serializer = new JavaSerializer(conf)
    +    val mockEnv = mock(classOf[SparkEnv])
    +    val mockRpcEnv = mock(classOf[RpcEnv])
    +    val mockMemoryManager = mock(classOf[MemoryManager])
    +    when(mockEnv.conf).thenReturn(conf)
    +    when(mockEnv.serializer).thenReturn(serializer)
    +    when(mockEnv.rpcEnv).thenReturn(mockRpcEnv)
    +    when(mockEnv.memoryManager).thenReturn(mockMemoryManager)
    +    when(mockEnv.closureSerializer).thenReturn(serializer)
    +    val serializedTask =
    +      Task.serializeWithDependencies(
    +        new FakeTask(0),
    +        HashMap[String, Long](),
    +        HashMap[String, Long](),
    +        serializer.newInstance())
    +
    +    // the program should run in this order:
    +    // +-----------------------------+----------------------------------------------+
    +    // |      main test thread       |      worker thread                           |
    +    // +-----------------------------+----------------------------------------------+
    +    // |    executor.launchTask()    |                                              |
    +    // |                             | TaskRunner.run() begins                      |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 1st time, #L240 |
    +    // | executor.killAllTasks(true) |                                              |
    +    // |                             |          ...                                 |
    +    // |                             |  task = ser.deserialize   // #L253           |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 2nd time, #L365 |
    +    // |                             |          ...                                 |
    +    // |                             |   TaskRunner.run() ends                      |
    +    // |       check results         |                                              |
    +    // +-----------------------------+----------------------------------------------+
    +
    +    val mockExecutorBackend = mock(classOf[ExecutorBackend])
    +    when(mockExecutorBackend.statusUpdate(any(), any(), any()))
    +      .thenAnswer(new Answer[Unit] {
    +        var firstTime = true
    +        override def answer(invocationOnMock: InvocationOnMock): Unit = {
    +          if (firstTime) {
    +            TestHelper.latch1.countDown()
    +            // here between latch1 and latch2, executor.killAllTasks() is called
    +            TestHelper.latch2.await()
    +            firstTime = false
    +          }
    +          else {
    +            val taskState = invocationOnMock.getArguments()(1).asInstanceOf[TaskState]
    +            // save the returned `taskState` and `testFailedReason` into TestHelper
    +            TestHelper.taskState = taskState
    +            val taskEndReason = invocationOnMock.getArguments()(2).asInstanceOf[ByteBuffer]
    +            TestHelper.testFailedReason = serializer.newInstance().deserialize(taskEndReason)
    +            // let the main test thread to check `taskState` and `testFailedReason`
    +            TestHelper.latch3.countDown()
    +          }
    +        }
    +      })
    +
    +    val executor = new Executor("id", "localhost", mockEnv, userClassPath = Nil, isLocal = true)
    --- End diff --
    
    you should stop the executor in a `finally` block.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #61034 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61034/consoleFull)** for PR 13685 at commit [`fd2638e`](https://github.com/apache/spark/commit/fd2638e29cf52a75f9927e106added67b28a1658).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #60609 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60609/consoleFull)** for PR 13685 at commit [`777959e`](https://github.com/apache/spark/commit/777959e6a6b9a2e21a32aec6b0bd6850d6513474).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #61091 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61091/consoleFull)** for PR 13685 at commit [`7bcc2e5`](https://github.com/apache/spark/commit/7bcc2e51eb66d5fb3dedb033484b5cc290bc2792).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    thanks for the test and explanation @lw-lin !  That is a great walk through and reproduction of the issue, nice use of the latches to trigger it.  :thumbsup: I have only very small comments, otherwise lgtm.
    
    Since the PR description will become the commit msg, can you update it to also include a very small description of the race?  eg. just something like "Before this change, if a task was killed before it was deserialized, it would be marked as FAILED instead of KILLED."
    
    Incidentally, I was actually imagining a different race: if `executor.kill()` marks `taskRunner.killed` [here](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/executor/Executor.scala#L215), but before calling `task.killed()` the worker thread throws the `TaskKilledException` [here](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/executor/Executor.scala#L264).  This change fixes that as well (though the test case doesn't cover it, but that's ok.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #13685: [SPARK-15963][CORE] Catch `TaskKilledException` c...

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

    https://github.com/apache/spark/pull/13685#discussion_r68095832
  
    --- Diff: core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala ---
    @@ -0,0 +1,123 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.executor
    +
    +import java.nio.ByteBuffer
    +import java.util.concurrent.CountDownLatch
    +
    +import scala.collection.mutable.HashMap
    +
    +import org.mockito.Matchers._
    +import org.mockito.Mockito.{mock, when}
    +import org.mockito.invocation.InvocationOnMock
    +import org.mockito.stubbing.Answer
    +
    +import org.apache.spark._
    +import org.apache.spark.TaskState.TaskState
    +import org.apache.spark.memory.MemoryManager
    +import org.apache.spark.rpc.RpcEnv
    +import org.apache.spark.scheduler.{FakeTask, Task}
    +import org.apache.spark.serializer.JavaSerializer
    +
    +class ExecutorSuite extends SparkFunSuite {
    +
    +  test("SPARK-15963: Catch `TaskKilledException` correctly in Executor.TaskRunner") {
    +    // mock some objects to make Executor.launchTask() happy
    +    val conf = new SparkConf
    +    val serializer = new JavaSerializer(conf)
    +    val mockEnv = mock(classOf[SparkEnv])
    +    val mockRpcEnv = mock(classOf[RpcEnv])
    +    val mockMemoryManager = mock(classOf[MemoryManager])
    +    when(mockEnv.conf).thenReturn(conf)
    +    when(mockEnv.serializer).thenReturn(serializer)
    +    when(mockEnv.rpcEnv).thenReturn(mockRpcEnv)
    +    when(mockEnv.memoryManager).thenReturn(mockMemoryManager)
    +    when(mockEnv.closureSerializer).thenReturn(serializer)
    +    val serializedTask =
    +      Task.serializeWithDependencies(
    +        new FakeTask(0),
    +        HashMap[String, Long](),
    +        HashMap[String, Long](),
    +        serializer.newInstance())
    +
    +    // the program should run in this order:
    +    // +-----------------------------+----------------------------------------------+
    +    // |      main test thread       |      worker thread                           |
    +    // +-----------------------------+----------------------------------------------+
    +    // |    executor.launchTask()    |                                              |
    +    // |                             | TaskRunner.run() begins                      |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 1st time, #L240 |
    +    // | executor.killAllTasks(true) |                                              |
    +    // |                             |          ...                                 |
    +    // |                             |  task = ser.deserialize   // #L253           |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 2nd time, #L365 |
    +    // |                             |          ...                                 |
    +    // |                             |   TaskRunner.run() ends                      |
    +    // |       check results         |                                              |
    +    // +-----------------------------+----------------------------------------------+
    +
    +    val mockExecutorBackend = mock(classOf[ExecutorBackend])
    +    when(mockExecutorBackend.statusUpdate(any(), any(), any()))
    +      .thenAnswer(new Answer[Unit] {
    +        var firstTime = true
    +        override def answer(invocationOnMock: InvocationOnMock): Unit = {
    +          if (firstTime) {
    +            TestHelper.latch1.countDown()
    +            // here between latch1 and latch2, executor.killAllTasks() is called
    +            TestHelper.latch2.await()
    +            firstTime = false
    +          }
    +          else {
    +            val taskState = invocationOnMock.getArguments()(1).asInstanceOf[TaskState]
    +            // save the returned `taskState` and `testFailedReason` into TestHelper
    +            TestHelper.taskState = taskState
    +            val taskEndReason = invocationOnMock.getArguments()(2).asInstanceOf[ByteBuffer]
    +            TestHelper.testFailedReason = serializer.newInstance().deserialize(taskEndReason)
    +            // let the main test thread to check `taskState` and `testFailedReason`
    +            TestHelper.latch3.countDown()
    +          }
    +        }
    +      })
    +
    +    val executor = new Executor("id", "localhost", mockEnv, userClassPath = Nil, isLocal = true)
    +    // the task will be launched in a dedicated worker thread
    +    executor.launchTask(mockExecutorBackend, 0, 0, "", serializedTask)
    +
    +    TestHelper.latch1.await()
    +    executor.killAllTasks(true)
    --- End diff --
    
    add a comment above this line, something like:
    ```scala
    // we know the task will be started, but not yet deserialized, because of the latches we use in mockBackend.
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #3107 has finished](https://amplab.cs.berkeley.edu/jenkins/job/NewSparkPullRequestBuilder/3107/consoleFull)** for PR 13685 at commit [`777959e`](https://github.com/apache/spark/commit/777959e6a6b9a2e21a32aec6b0bd6850d6513474).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    I couldn't come up with good syntax to express something like
    ```scala
    case e @ (_: TaskKilledException) | (_: InterruptedException if task.killed) =>
      ...
    ```
    So this patch simply breaks the case into two separate ones.
    
    @kayousterhout @markhamstra @squito, would you mind taking a look? Thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #61087 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61087/consoleFull)** for PR 13685 at commit [`df6b51b`](https://github.com/apache/spark/commit/df6b51bb69510c41b20058d066a847af0b689b3b).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #61034 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61034/consoleFull)** for PR 13685 at commit [`fd2638e`](https://github.com/apache/spark/commit/fd2638e29cf52a75f9927e106added67b28a1658).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `class ExecutorSuite extends SparkFunSuite `


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #13685: [SPARK-15963][CORE] Catch `TaskKilledException` c...

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

    https://github.com/apache/spark/pull/13685#discussion_r68100509
  
    --- Diff: core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala ---
    @@ -0,0 +1,123 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.executor
    +
    +import java.nio.ByteBuffer
    +import java.util.concurrent.CountDownLatch
    +
    +import scala.collection.mutable.HashMap
    +
    +import org.mockito.Matchers._
    +import org.mockito.Mockito.{mock, when}
    +import org.mockito.invocation.InvocationOnMock
    +import org.mockito.stubbing.Answer
    +
    +import org.apache.spark._
    +import org.apache.spark.TaskState.TaskState
    +import org.apache.spark.memory.MemoryManager
    +import org.apache.spark.rpc.RpcEnv
    +import org.apache.spark.scheduler.{FakeTask, Task}
    +import org.apache.spark.serializer.JavaSerializer
    +
    +class ExecutorSuite extends SparkFunSuite {
    +
    +  test("SPARK-15963: Catch `TaskKilledException` correctly in Executor.TaskRunner") {
    +    // mock some objects to make Executor.launchTask() happy
    +    val conf = new SparkConf
    +    val serializer = new JavaSerializer(conf)
    +    val mockEnv = mock(classOf[SparkEnv])
    +    val mockRpcEnv = mock(classOf[RpcEnv])
    +    val mockMemoryManager = mock(classOf[MemoryManager])
    +    when(mockEnv.conf).thenReturn(conf)
    +    when(mockEnv.serializer).thenReturn(serializer)
    +    when(mockEnv.rpcEnv).thenReturn(mockRpcEnv)
    +    when(mockEnv.memoryManager).thenReturn(mockMemoryManager)
    +    when(mockEnv.closureSerializer).thenReturn(serializer)
    +    val serializedTask =
    +      Task.serializeWithDependencies(
    +        new FakeTask(0),
    +        HashMap[String, Long](),
    +        HashMap[String, Long](),
    +        serializer.newInstance())
    +
    +    // the program should run in this order:
    +    // +-----------------------------+----------------------------------------------+
    +    // |      main test thread       |      worker thread                           |
    +    // +-----------------------------+----------------------------------------------+
    +    // |    executor.launchTask()    |                                              |
    +    // |                             | TaskRunner.run() begins                      |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 1st time, #L240 |
    +    // | executor.killAllTasks(true) |                                              |
    +    // |                             |          ...                                 |
    +    // |                             |  task = ser.deserialize   // #L253           |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 2nd time, #L365 |
    +    // |                             |          ...                                 |
    +    // |                             |   TaskRunner.run() ends                      |
    +    // |       check results         |                                              |
    +    // +-----------------------------+----------------------------------------------+
    +
    +    val mockExecutorBackend = mock(classOf[ExecutorBackend])
    +    when(mockExecutorBackend.statusUpdate(any(), any(), any()))
    +      .thenAnswer(new Answer[Unit] {
    +        var firstTime = true
    +        override def answer(invocationOnMock: InvocationOnMock): Unit = {
    +          if (firstTime) {
    +            TestHelper.latch1.countDown()
    +            // here between latch1 and latch2, executor.killAllTasks() is called
    +            TestHelper.latch2.await()
    +            firstTime = false
    +          }
    +          else {
    +            val taskState = invocationOnMock.getArguments()(1).asInstanceOf[TaskState]
    +            // save the returned `taskState` and `testFailedReason` into TestHelper
    +            TestHelper.taskState = taskState
    +            val taskEndReason = invocationOnMock.getArguments()(2).asInstanceOf[ByteBuffer]
    +            TestHelper.testFailedReason = serializer.newInstance().deserialize(taskEndReason)
    +            // let the main test thread to check `taskState` and `testFailedReason`
    +            TestHelper.latch3.countDown()
    +          }
    +        }
    +      })
    +
    +    val executor = new Executor("id", "localhost", mockEnv, userClassPath = Nil, isLocal = true)
    +    // the task will be launched in a dedicated worker thread
    +    executor.launchTask(mockExecutorBackend, 0, 0, "", serializedTask)
    +
    +    TestHelper.latch1.await()
    +    executor.killAllTasks(true)
    +    TestHelper.latch2.countDown()
    +    TestHelper.latch3.await()
    +
    +    // `exception` should be `TaskKilled`; `taskState` should be `KILLED`
    +    assert(TestHelper.testFailedReason === TaskKilled)
    +    assert(TestHelper.taskState === TaskState.KILLED)
    +  }
    +}
    +
    +// Helps to test("SPARK-15963")
    +private object TestHelper {
    --- End diff --
    
    can you rename this to `ExecutorSuiteHelper`?
    
    also, would you mind making this a class instead of an object?  This is a pretty minor point -- the reason is that to flush out flaky tests, I sometimes like to run the tests in a loop:
    
    ```scala
    (0 until 1000).foreach { idx => 
      test(s"... $idx){ ... }
    }
    ```
    
    and that doesn't work this as an object.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #60570 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60570/consoleFull)** for PR 13685 at commit [`777959e`](https://github.com/apache/spark/commit/777959e6a6b9a2e21a32aec6b0bd6850d6513474).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #13685: [SPARK-15963][CORE] Catch `TaskKilledException` c...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    Addressed all comments. @squito would you take another look? Thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #13685: [SPARK-15963][CORE] Catch `TaskKilledException` c...

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

    https://github.com/apache/spark/pull/13685#discussion_r68095421
  
    --- Diff: core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala ---
    @@ -0,0 +1,123 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.executor
    +
    +import java.nio.ByteBuffer
    +import java.util.concurrent.CountDownLatch
    +
    +import scala.collection.mutable.HashMap
    +
    +import org.mockito.Matchers._
    +import org.mockito.Mockito.{mock, when}
    +import org.mockito.invocation.InvocationOnMock
    +import org.mockito.stubbing.Answer
    +
    +import org.apache.spark._
    +import org.apache.spark.TaskState.TaskState
    +import org.apache.spark.memory.MemoryManager
    +import org.apache.spark.rpc.RpcEnv
    +import org.apache.spark.scheduler.{FakeTask, Task}
    +import org.apache.spark.serializer.JavaSerializer
    +
    +class ExecutorSuite extends SparkFunSuite {
    +
    +  test("SPARK-15963: Catch `TaskKilledException` correctly in Executor.TaskRunner") {
    +    // mock some objects to make Executor.launchTask() happy
    +    val conf = new SparkConf
    +    val serializer = new JavaSerializer(conf)
    +    val mockEnv = mock(classOf[SparkEnv])
    +    val mockRpcEnv = mock(classOf[RpcEnv])
    +    val mockMemoryManager = mock(classOf[MemoryManager])
    +    when(mockEnv.conf).thenReturn(conf)
    +    when(mockEnv.serializer).thenReturn(serializer)
    +    when(mockEnv.rpcEnv).thenReturn(mockRpcEnv)
    +    when(mockEnv.memoryManager).thenReturn(mockMemoryManager)
    +    when(mockEnv.closureSerializer).thenReturn(serializer)
    +    val serializedTask =
    +      Task.serializeWithDependencies(
    +        new FakeTask(0),
    +        HashMap[String, Long](),
    +        HashMap[String, Long](),
    +        serializer.newInstance())
    +
    +    // the program should run in this order:
    +    // +-----------------------------+----------------------------------------------+
    +    // |      main test thread       |      worker thread                           |
    +    // +-----------------------------+----------------------------------------------+
    +    // |    executor.launchTask()    |                                              |
    +    // |                             | TaskRunner.run() begins                      |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 1st time, #L240 |
    +    // | executor.killAllTasks(true) |                                              |
    +    // |                             |          ...                                 |
    +    // |                             |  task = ser.deserialize   // #L253           |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 2nd time, #L365 |
    --- End diff --
    
    nit: I'd remove the line numbers -- though that code hasn't changed a lot recently, no guaranatee they won't change and then they'll be misleading.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    merged to master.  Thanks @lw-lin !


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #61091 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61091/consoleFull)** for PR 13685 at commit [`7bcc2e5`](https://github.com/apache/spark/commit/7bcc2e51eb66d5fb3dedb033484b5cc290bc2792).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    Hi @lw-lin .  Your description makes sense, but I'm having trouble seeing how you'd have a `TaskKilledException`, but without setting the task to killed.  Eg., `TaskSchedulerImpl.cancelTasks`, which eventually sends a `KillTask` msg to the Executor, which then calls `Task.kill`.  But this sets `_killed = true`, so it seems like that shouldn't cause any problems.
    
    Is the problem that there is a race in `Executor.kill`, it sets `killed=true` before `task.kill`?  Then this seems like a reasonable explanation, but is also worth a comment explaining that.  And though the change is straightforward, a unit test would be nice -- sorry that there aren't currently any tests for `TaskRunner`, but it would be great if you could add something.  Even if the change is clear, it will help for future maintenance.
    
    Sorry to ask for a few more details, but thanks for reporting this, looks like a good fix!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #61087 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/61087/consoleFull)** for PR 13685 at commit [`df6b51b`](https://github.com/apache/spark/commit/df6b51bb69510c41b20058d066a847af0b689b3b).
     * This patch **fails Scala style tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #60570 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60570/consoleFull)** for PR 13685 at commit [`777959e`](https://github.com/apache/spark/commit/777959e6a6b9a2e21a32aec6b0bd6850d6513474).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    lgtm!  will leave open for a bit to see if anyone else comments.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    LGTM.  Good work!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    Thanks, @squito @markhamstra !


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    Jenkins, retest this please


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    Hi @squito thanks for the comments!
    
    > how you'd have a TaskKilledException, but without setting the task to `killed`
    
    This can be reproduced when, a task gets killed([Executor#L235~L252](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/executor/Executor.scala#L235~L252)) before it can be deserialized([Executor#L253](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/executor/Executor.scala#L253)). Then in [TaskRunner.kill()](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/executor/Executor.scala#L211), `task` is still `null`, so only `taskRunner.killed` is set to `true` but not `task.killed`.
    
    The updated test reproduces this. In the test, we use `mockExecutorBackend` to trigger `executor.killAllTasks(true)` at Executor#L240; the program should run in this order:
    ```
    +-----------------------------+----------------------------------------------+
    |      main test thread       |      worker thread                           |
    +-----------------------------+----------------------------------------------+
    |    executor.launchTask()    |                                              |
    |                             | TaskRunner.run() begins                      |
    |                             |          ...                                 |
    |                             | execBackend.statusUpdate  // 1st time, #L240 |
    | executor.killAllTasks(true) |                                              |
    |                             |          ...                                 |
    |                             |  task = ser.deserialize   // #L253           |
    |                             |          ...                                 |
    |                             | execBackend.statusUpdate  // 2nd time, #L365 |
    |                             |          ...                                 |
    |                             |   TaskRunner.run() ends                      |
    |       check results         |                                              |
    +-----------------------------+----------------------------------------------+
    ```
    
    Then:
    
    <table>
    <tr>
    	<td align="center"><strong></strong></td>
    	<td align="center"><strong>prior to this patch</strong></td>
    	<td align="center"><strong>after this patch</strong></td>
    </tr>
    <tr>
    	<td align="center">testFailedReason</td>
    	<td align="center">ExceptionFailure</td>
    	<td align="center">TaskKilled</td>
    </tr>
    <tr>
    	<td align="center">taskState</td>
    	<td align="center">FAILED</td>
    	<td align="center">KILLED</td>
    </tr>
    </table>


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #3107 has started](https://amplab.cs.berkeley.edu/jenkins/job/NewSparkPullRequestBuilder/3107/consoleFull)** for PR 13685 at commit [`777959e`](https://github.com/apache/spark/commit/777959e6a6b9a2e21a32aec6b0bd6850d6513474).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #13685: [SPARK-15963][CORE] Catch `TaskKilledException` c...

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

    https://github.com/apache/spark/pull/13685#discussion_r68165895
  
    --- Diff: core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala ---
    @@ -0,0 +1,123 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.executor
    +
    +import java.nio.ByteBuffer
    +import java.util.concurrent.CountDownLatch
    +
    +import scala.collection.mutable.HashMap
    +
    +import org.mockito.Matchers._
    +import org.mockito.Mockito.{mock, when}
    +import org.mockito.invocation.InvocationOnMock
    +import org.mockito.stubbing.Answer
    +
    +import org.apache.spark._
    +import org.apache.spark.TaskState.TaskState
    +import org.apache.spark.memory.MemoryManager
    +import org.apache.spark.rpc.RpcEnv
    +import org.apache.spark.scheduler.{FakeTask, Task}
    +import org.apache.spark.serializer.JavaSerializer
    +
    +class ExecutorSuite extends SparkFunSuite {
    +
    +  test("SPARK-15963: Catch `TaskKilledException` correctly in Executor.TaskRunner") {
    +    // mock some objects to make Executor.launchTask() happy
    +    val conf = new SparkConf
    +    val serializer = new JavaSerializer(conf)
    +    val mockEnv = mock(classOf[SparkEnv])
    +    val mockRpcEnv = mock(classOf[RpcEnv])
    +    val mockMemoryManager = mock(classOf[MemoryManager])
    +    when(mockEnv.conf).thenReturn(conf)
    +    when(mockEnv.serializer).thenReturn(serializer)
    +    when(mockEnv.rpcEnv).thenReturn(mockRpcEnv)
    +    when(mockEnv.memoryManager).thenReturn(mockMemoryManager)
    +    when(mockEnv.closureSerializer).thenReturn(serializer)
    +    val serializedTask =
    +      Task.serializeWithDependencies(
    +        new FakeTask(0),
    +        HashMap[String, Long](),
    +        HashMap[String, Long](),
    +        serializer.newInstance())
    +
    +    // the program should run in this order:
    +    // +-----------------------------+----------------------------------------------+
    +    // |      main test thread       |      worker thread                           |
    +    // +-----------------------------+----------------------------------------------+
    +    // |    executor.launchTask()    |                                              |
    +    // |                             | TaskRunner.run() begins                      |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 1st time, #L240 |
    +    // | executor.killAllTasks(true) |                                              |
    +    // |                             |          ...                                 |
    +    // |                             |  task = ser.deserialize   // #L253           |
    +    // |                             |          ...                                 |
    +    // |                             | execBackend.statusUpdate  // 2nd time, #L365 |
    +    // |                             |          ...                                 |
    +    // |                             |   TaskRunner.run() ends                      |
    +    // |       check results         |                                              |
    +    // +-----------------------------+----------------------------------------------+
    +
    +    val mockExecutorBackend = mock(classOf[ExecutorBackend])
    +    when(mockExecutorBackend.statusUpdate(any(), any(), any()))
    +      .thenAnswer(new Answer[Unit] {
    +        var firstTime = true
    +        override def answer(invocationOnMock: InvocationOnMock): Unit = {
    +          if (firstTime) {
    +            TestHelper.latch1.countDown()
    +            // here between latch1 and latch2, executor.killAllTasks() is called
    +            TestHelper.latch2.await()
    +            firstTime = false
    +          }
    +          else {
    +            val taskState = invocationOnMock.getArguments()(1).asInstanceOf[TaskState]
    +            // save the returned `taskState` and `testFailedReason` into TestHelper
    +            TestHelper.taskState = taskState
    +            val taskEndReason = invocationOnMock.getArguments()(2).asInstanceOf[ByteBuffer]
    +            TestHelper.testFailedReason = serializer.newInstance().deserialize(taskEndReason)
    +            // let the main test thread to check `taskState` and `testFailedReason`
    +            TestHelper.latch3.countDown()
    +          }
    +        }
    +      })
    +
    +    val executor = new Executor("id", "localhost", mockEnv, userClassPath = Nil, isLocal = true)
    +    // the task will be launched in a dedicated worker thread
    +    executor.launchTask(mockExecutorBackend, 0, 0, "", serializedTask)
    +
    +    TestHelper.latch1.await()
    +    executor.killAllTasks(true)
    +    TestHelper.latch2.countDown()
    +    TestHelper.latch3.await()
    +
    +    // `exception` should be `TaskKilled`; `taskState` should be `KILLED`
    +    assert(TestHelper.testFailedReason === TaskKilled)
    +    assert(TestHelper.taskState === TaskState.KILLED)
    +  }
    +}
    +
    +// Helps to test("SPARK-15963")
    +private object TestHelper {
    --- End diff --
    
    switched to class and now we can run this in a loop :)
    thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #13685: [SPARK-15963][CORE] Catch `TaskKilledException` c...

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

    https://github.com/apache/spark/pull/13685#discussion_r68095283
  
    --- Diff: core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala ---
    @@ -0,0 +1,123 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.executor
    +
    +import java.nio.ByteBuffer
    +import java.util.concurrent.CountDownLatch
    +
    +import scala.collection.mutable.HashMap
    +
    +import org.mockito.Matchers._
    +import org.mockito.Mockito.{mock, when}
    +import org.mockito.invocation.InvocationOnMock
    +import org.mockito.stubbing.Answer
    +
    +import org.apache.spark._
    +import org.apache.spark.TaskState.TaskState
    +import org.apache.spark.memory.MemoryManager
    +import org.apache.spark.rpc.RpcEnv
    +import org.apache.spark.scheduler.{FakeTask, Task}
    +import org.apache.spark.serializer.JavaSerializer
    +
    +class ExecutorSuite extends SparkFunSuite {
    +
    +  test("SPARK-15963: Catch `TaskKilledException` correctly in Executor.TaskRunner") {
    +    // mock some objects to make Executor.launchTask() happy
    +    val conf = new SparkConf
    +    val serializer = new JavaSerializer(conf)
    +    val mockEnv = mock(classOf[SparkEnv])
    +    val mockRpcEnv = mock(classOf[RpcEnv])
    +    val mockMemoryManager = mock(classOf[MemoryManager])
    +    when(mockEnv.conf).thenReturn(conf)
    +    when(mockEnv.serializer).thenReturn(serializer)
    +    when(mockEnv.rpcEnv).thenReturn(mockRpcEnv)
    +    when(mockEnv.memoryManager).thenReturn(mockMemoryManager)
    +    when(mockEnv.closureSerializer).thenReturn(serializer)
    +    val serializedTask =
    +      Task.serializeWithDependencies(
    +        new FakeTask(0),
    +        HashMap[String, Long](),
    +        HashMap[String, Long](),
    +        serializer.newInstance())
    +
    +    // the program should run in this order:
    --- End diff --
    
    nit: reword to "We use latches to force the program to run in this order:"


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #13685: [SPARK-15963][CORE] Catch `TaskKilledException` correctl...

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

    https://github.com/apache/spark/pull/13685
  
    **[Test build #60609 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60609/consoleFull)** for PR 13685 at commit [`777959e`](https://github.com/apache/spark/commit/777959e6a6b9a2e21a32aec6b0bd6850d6513474).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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