You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by zsxwing <gi...@git.apache.org> on 2016/03/26 00:48:43 UTC

[GitHub] spark pull request: [SPARK-14169][Core]Add UninterruptibleThread

GitHub user zsxwing opened a pull request:

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

    [SPARK-14169][Core]Add UninterruptibleThread

    ## What changes were proposed in this pull request?
    
    Extract the workaround for HADOOP-10622 introduced by #11940 into UninterruptibleThread so that we can test and reuse it.
    
    ## How was this patch tested?
    
    Unit tests

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

    $ git pull https://github.com/zsxwing/spark uninterrupt

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

    https://github.com/apache/spark/pull/11971.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 #11971
    
----
commit 8a65a9d1c23bde0db8877ec11b45f8ef234d5748
Author: Shixiong Zhu <sh...@databricks.com>
Date:   2016-03-25T23:44:07Z

    Add UninterruptibleThread
    
    Extract the workaround for HADOOP-10622 introduced by #11940 into UninterruptibleThread so that we can test and reuse it.

----


---
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: [SPARK-14169][Core]Add UninterruptibleThread

Posted by vanzin <gi...@git.apache.org>.
Github user vanzin commented on the pull request:

    https://github.com/apache/spark/pull/11971#issuecomment-201960142
  
    Yes, my suggestion would make the whole thread uninterruptible. But from the only use case, it seems that would be ok - there are no calls I see that can be interrupted outside of the calls to `runUninterrubptibly`.
    
    In any case, not a huge deal.


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-201647819
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/54235/
    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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-201647391
  
    **[Test build #54235 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/54235/consoleFull)** for PR 11971 at commit [`8a65a9d`](https://github.com/apache/spark/commit/8a65a9d1c23bde0db8877ec11b45f8ef234d5748).
     * 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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#discussion_r57600647
  
    --- Diff: core/src/main/scala/org/apache/spark/util/UninterruptibleThread.scala ---
    @@ -0,0 +1,106 @@
    +/*
    + * 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.util
    +
    +import javax.annotation.concurrent.GuardedBy
    +
    +/**
    + * A special Thread that provides "runUninterruptibly" to allow running codes without being
    + * interrupted by `Thread.interrupt()`. If `Thread.interrupt()` is called during runUninterruptibly
    + * is running, it won't set the interrupted status. Instead, setting the interrupted status will be
    + * deferred until it's returning from "runUninterruptibly".
    + *
    + * Note: this method should be called only in `this` thread.
    + */
    +private[spark] class UninterruptibleThread(name: String) extends Thread(name) {
    +
    +  /** A monitor to protect "uninterruptible" and "interrupted" */
    +  private val uninterruptibleLock = new Object
    +
    +  /**
    +   * Indicates if `this`  thread are in the uninterruptible status. If so, interrupting
    +   * "this" will be deferred until `this`  enters into the interruptible status.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var uninterruptible = false
    +
    +  /**
    +   * Indicates if we should interrupt `this` when we are leaving the uninterruptible zone.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var shouldInterruptThread = false
    +
    +  /**
    +   * Run `f` uninterruptibly in `this` thread. The thread won't be interrupted before returning
    +   * from `f`.
    +   *
    +   * Note: this method should be called only in `this` thread.
    +   */
    +  def runUninterruptibly[T](f: => T): T = {
    +    if (Thread.currentThread() != this) {
    +      throw new IllegalStateException(s"Call runUninterruptibly in a wrong thread. " +
    +        s"Expected: $this but was ${Thread.currentThread()}")
    +    }
    +
    --- End diff --
    
    > minor: should you bail out early if shouldInterruptThread has already been set somehow?
    
    Don't get it. `shouldInterruptThread` is just a flag that indicates if we should call `super.interrupt`  in `finally`. What do you suggest to do here?


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-201719152
  
    **[Test build #54250 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/54250/consoleFull)** for PR 11971 at commit [`8a65a9d`](https://github.com/apache/spark/commit/8a65a9d1c23bde0db8877ec11b45f8ef234d5748).
     * 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 pull request: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#discussion_r57601601
  
    --- Diff: core/src/main/scala/org/apache/spark/util/UninterruptibleThread.scala ---
    @@ -0,0 +1,106 @@
    +/*
    + * 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.util
    +
    +import javax.annotation.concurrent.GuardedBy
    +
    +/**
    + * A special Thread that provides "runUninterruptibly" to allow running codes without being
    + * interrupted by `Thread.interrupt()`. If `Thread.interrupt()` is called during runUninterruptibly
    + * is running, it won't set the interrupted status. Instead, setting the interrupted status will be
    + * deferred until it's returning from "runUninterruptibly".
    + *
    + * Note: this method should be called only in `this` thread.
    + */
    +private[spark] class UninterruptibleThread(name: String) extends Thread(name) {
    +
    +  /** A monitor to protect "uninterruptible" and "interrupted" */
    +  private val uninterruptibleLock = new Object
    +
    +  /**
    +   * Indicates if `this`  thread are in the uninterruptible status. If so, interrupting
    +   * "this" will be deferred until `this`  enters into the interruptible status.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var uninterruptible = false
    +
    +  /**
    +   * Indicates if we should interrupt `this` when we are leaving the uninterruptible zone.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var shouldInterruptThread = false
    +
    +  /**
    +   * Run `f` uninterruptibly in `this` thread. The thread won't be interrupted before returning
    +   * from `f`.
    +   *
    +   * Note: this method should be called only in `this` thread.
    +   */
    +  def runUninterruptibly[T](f: => T): T = {
    +    if (Thread.currentThread() != this) {
    +      throw new IllegalStateException(s"Call runUninterruptibly in a wrong thread. " +
    +        s"Expected: $this but was ${Thread.currentThread()}")
    +    }
    +
    --- End diff --
    
    I mean: if the thread is already interrupted before you try to run the given function (or, in other words, if `Thread.interrupt()` was called before you get to this point), should you just return early instead of calling the function?
    
    (I guess I should have commented on L68 instead, where there's an explicit check for whether the thread is already interrupted.)


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#discussion_r57603003
  
    --- Diff: core/src/main/scala/org/apache/spark/util/UninterruptibleThread.scala ---
    @@ -0,0 +1,106 @@
    +/*
    + * 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.util
    +
    +import javax.annotation.concurrent.GuardedBy
    +
    +/**
    + * A special Thread that provides "runUninterruptibly" to allow running codes without being
    + * interrupted by `Thread.interrupt()`. If `Thread.interrupt()` is called during runUninterruptibly
    + * is running, it won't set the interrupted status. Instead, setting the interrupted status will be
    + * deferred until it's returning from "runUninterruptibly".
    + *
    + * Note: this method should be called only in `this` thread.
    + */
    +private[spark] class UninterruptibleThread(name: String) extends Thread(name) {
    +
    +  /** A monitor to protect "uninterruptible" and "interrupted" */
    +  private val uninterruptibleLock = new Object
    +
    +  /**
    +   * Indicates if `this`  thread are in the uninterruptible status. If so, interrupting
    +   * "this" will be deferred until `this`  enters into the interruptible status.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var uninterruptible = false
    +
    +  /**
    +   * Indicates if we should interrupt `this` when we are leaving the uninterruptible zone.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var shouldInterruptThread = false
    +
    +  /**
    +   * Run `f` uninterruptibly in `this` thread. The thread won't be interrupted before returning
    +   * from `f`.
    +   *
    +   * Note: this method should be called only in `this` thread.
    +   */
    +  def runUninterruptibly[T](f: => T): T = {
    +    if (Thread.currentThread() != this) {
    +      throw new IllegalStateException(s"Call runUninterruptibly in a wrong thread. " +
    +        s"Expected: $this but was ${Thread.currentThread()}")
    +    }
    +
    --- End diff --
    
    I understand that's what the code does right now. I'm asking whether it would be better to not run `f` if the thread has already been interrupted, since you might be running a long computation after some other code has asked the thread to stop what it's doing.


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

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


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-201647814
  
    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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-202516301
  
    **[Test build #54335 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/54335/consoleFull)** for PR 11971 at commit [`47187d8`](https://github.com/apache/spark/commit/47187d82a4f8748a718d6ef9db5867bf22ef8c99).


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-202575599
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/54335/
    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 pull request: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-201719198
  
    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 pull request: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-202575103
  
    **[Test build #54335 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/54335/consoleFull)** for PR 11971 at commit [`47187d8`](https://github.com/apache/spark/commit/47187d82a4f8748a718d6ef9db5867bf22ef8c99).
     * 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 pull request: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-202575596
  
    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 pull request: [SPARK-14169][Core]Add UninterruptibleThread

Posted by zsxwing <gi...@git.apache.org>.
Github user zsxwing commented on the pull request:

    https://github.com/apache/spark/pull/11971#issuecomment-201703467
  
    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 pull request: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-201703542
  
    **[Test build #54250 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/54250/consoleFull)** for PR 11971 at commit [`8a65a9d`](https://github.com/apache/spark/commit/8a65a9d1c23bde0db8877ec11b45f8ef234d5748).


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#discussion_r57602452
  
    --- Diff: core/src/main/scala/org/apache/spark/util/UninterruptibleThread.scala ---
    @@ -0,0 +1,106 @@
    +/*
    + * 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.util
    +
    +import javax.annotation.concurrent.GuardedBy
    +
    +/**
    + * A special Thread that provides "runUninterruptibly" to allow running codes without being
    + * interrupted by `Thread.interrupt()`. If `Thread.interrupt()` is called during runUninterruptibly
    + * is running, it won't set the interrupted status. Instead, setting the interrupted status will be
    + * deferred until it's returning from "runUninterruptibly".
    + *
    + * Note: this method should be called only in `this` thread.
    + */
    +private[spark] class UninterruptibleThread(name: String) extends Thread(name) {
    +
    +  /** A monitor to protect "uninterruptible" and "interrupted" */
    +  private val uninterruptibleLock = new Object
    +
    +  /**
    +   * Indicates if `this`  thread are in the uninterruptible status. If so, interrupting
    +   * "this" will be deferred until `this`  enters into the interruptible status.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var uninterruptible = false
    +
    +  /**
    +   * Indicates if we should interrupt `this` when we are leaving the uninterruptible zone.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var shouldInterruptThread = false
    +
    +  /**
    +   * Run `f` uninterruptibly in `this` thread. The thread won't be interrupted before returning
    +   * from `f`.
    +   *
    +   * Note: this method should be called only in `this` thread.
    +   */
    +  def runUninterruptibly[T](f: => T): T = {
    +    if (Thread.currentThread() != this) {
    +      throw new IllegalStateException(s"Call runUninterruptibly in a wrong thread. " +
    +        s"Expected: $this but was ${Thread.currentThread()}")
    +    }
    +
    --- End diff --
    
    In this case, it should clear the interrupt status and set it back after calling `f`. `StreamExecution` allows people to `interrupt` at any time.


---
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: [SPARK-14169][Core]Add UninterruptibleThread

Posted by vanzin <gi...@git.apache.org>.
Github user vanzin commented on the pull request:

    https://github.com/apache/spark/pull/11971#issuecomment-202624330
  
    LGTM, merging to master.


---
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: [SPARK-14169][Core]Add UninterruptibleThread

Posted by zsxwing <gi...@git.apache.org>.
Github user zsxwing commented on the pull request:

    https://github.com/apache/spark/pull/11971#issuecomment-201703258
  
    > LGTM but I wonder if just overriding Thread.run and making it final wouldn't be enough (the task to run would have to be passed as a Runnable). It would simplify the code a little bit and you wouldn't need to deal with reentrant calls, which the current code doesn't seem to need anyway.
    
    Could you clarify it? If overriding `run`, then the whole Thread will be uninterruptible and this is not what we want.


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#discussion_r57521413
  
    --- Diff: core/src/main/scala/org/apache/spark/util/UninterruptibleThread.scala ---
    @@ -0,0 +1,106 @@
    +/*
    + * 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.util
    +
    +import javax.annotation.concurrent.GuardedBy
    +
    +/**
    + * A special Thread that provides "runUninterruptibly" to allow running codes without being
    + * interrupted by `Thread.interrupt()`. If `Thread.interrupt()` is called during runUninterruptibly
    + * is running, it won't set the interrupted status. Instead, setting the interrupted status will be
    + * deferred until it's returning from "runUninterruptibly".
    + *
    + * Note: this method should be called only in `this` thread.
    + */
    +private[spark] class UninterruptibleThread(name: String) extends Thread(name) {
    +
    +  /** A monitor to protect "uninterruptible" and "interrupted" */
    +  private val uninterruptibleLock = new Object
    +
    +  /**
    +   * Indicates if `this`  thread are in the uninterruptible status. If so, interrupting
    +   * "this" will be deferred until `this`  enters into the interruptible status.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var uninterruptible = false
    +
    +  /**
    +   * Indicates if we should interrupt `this` when we are leaving the uninterruptible zone.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var shouldInterruptThread = false
    +
    +  /**
    +   * Run `f` uninterruptibly in `this` thread. The thread won't be interrupted before returning
    +   * from `f`.
    +   *
    +   * Note: this method should be called only in `this` thread.
    +   */
    +  def runUninterruptibly[T](f: => T): T = {
    +    if (Thread.currentThread() != this) {
    +      throw new IllegalStateException(s"Call runUninterruptibly in a wrong thread. " +
    +        s"Expected: $this but was ${Thread.currentThread()}")
    +    }
    +
    --- End diff --
    
    minor: should you bail out early if `shouldInterruptThread` has already been set somehow?


---
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: [SPARK-14169][Core]Add UninterruptibleThread

Posted by vanzin <gi...@git.apache.org>.
Github user vanzin commented on the pull request:

    https://github.com/apache/spark/pull/11971#issuecomment-201604050
  
    LGTM but I wonder if just overriding `Thread.run` and making it final wouldn't be enough (the task to run would have to be passed as a `Runnable`). It would simplify the code a little bit and you wouldn't need to deal with reentrant calls, which the current code doesn't seem to need anyway.


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-201719199
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/54250/
    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 pull request: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#issuecomment-201596033
  
    **[Test build #54235 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/54235/consoleFull)** for PR 11971 at commit [`8a65a9d`](https://github.com/apache/spark/commit/8a65a9d1c23bde0db8877ec11b45f8ef234d5748).


---
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: [SPARK-14169][Core]Add UninterruptibleThread

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

    https://github.com/apache/spark/pull/11971#discussion_r57603613
  
    --- Diff: core/src/main/scala/org/apache/spark/util/UninterruptibleThread.scala ---
    @@ -0,0 +1,106 @@
    +/*
    + * 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.util
    +
    +import javax.annotation.concurrent.GuardedBy
    +
    +/**
    + * A special Thread that provides "runUninterruptibly" to allow running codes without being
    + * interrupted by `Thread.interrupt()`. If `Thread.interrupt()` is called during runUninterruptibly
    + * is running, it won't set the interrupted status. Instead, setting the interrupted status will be
    + * deferred until it's returning from "runUninterruptibly".
    + *
    + * Note: this method should be called only in `this` thread.
    + */
    +private[spark] class UninterruptibleThread(name: String) extends Thread(name) {
    +
    +  /** A monitor to protect "uninterruptible" and "interrupted" */
    +  private val uninterruptibleLock = new Object
    +
    +  /**
    +   * Indicates if `this`  thread are in the uninterruptible status. If so, interrupting
    +   * "this" will be deferred until `this`  enters into the interruptible status.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var uninterruptible = false
    +
    +  /**
    +   * Indicates if we should interrupt `this` when we are leaving the uninterruptible zone.
    +   */
    +  @GuardedBy("uninterruptibleLock")
    +  private var shouldInterruptThread = false
    +
    +  /**
    +   * Run `f` uninterruptibly in `this` thread. The thread won't be interrupted before returning
    +   * from `f`.
    +   *
    +   * Note: this method should be called only in `this` thread.
    +   */
    +  def runUninterruptibly[T](f: => T): T = {
    +    if (Thread.currentThread() != this) {
    +      throw new IllegalStateException(s"Call runUninterruptibly in a wrong thread. " +
    +        s"Expected: $this but was ${Thread.currentThread()}")
    +    }
    +
    --- End diff --
    
    That's a good point. Will update my PR.


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