You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by mccheah <gi...@git.apache.org> on 2018/05/18 21:24:17 UTC

[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

GitHub user mccheah opened a pull request:

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

    [SPARK-24248][K8S][WIP] Use the Kubernetes API to populate an event queue for scheduling

    ## What changes were proposed in this pull request?
    
    Previously, the scheduler backend was maintaining state in many places, not only for reading state but also writing to it. For example, state had to be managed in both the watch and in the executor allocator runnable. Furthermore, one had to keep track of multiple hash tables.
    
    We can do better here by:
    
    1. Consolidating the places where we manage state. Here, we take inspiration from traditional Kubernetes controllers. These controllers tend to implement an event queue which is populated by two sources: a watch connection, and a periodic poller. Controllers typically use both mechanisms for redundancy; the watch connection may drop, so the periodic polling serves as a backup. Both sources write pod updates to a single event queue and then a processor periodically processes the current state of pods as reported by the two sources.
    
    2. Storing less specialized in-memory state in general. Previously we were creating hash tables to represent the state of executors. Instead, it's easier to represent state solely by the event queue, which has predictable read/write patterns and is more or less just a local up-to-date cache of the cluster's status.
    
    ## How was this patch tested?
    
    Integration tests should test there's no regressions end to end. Unit tests to be updated, in particular focusing on different orderings of events, particularly accounting for when events come in unexpected ordering.
    
    Please review http://spark.apache.org/contributing.html before opening a pull request.


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

    $ git pull https://github.com/palantir/spark event-queue-driven-scheduling

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

    https://github.com/apache/spark/pull/21366.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 #21366
    
----
commit 310263c253a8c4a3748cab5b5a7698e076695cd6
Author: mcheah <mc...@...>
Date:   2018-05-18T20:39:47Z

    [SPARK-24248][K8S] Use the Kubernetes API to populate an event queue for scheduling
    
    Previously, the scheduler backend was maintaining state in many places,
    not only for reading state but also writing to it. For example, state
    had to be managed in both the watch and in the executor allocator
    runnable. Furthermore one had to keep track of multiple hash tables.
    
    We can do better here by:
    
    (1) Consolidating the places where we manage state. Here, we take
    inspiration from traditional Kubernetes controllers. These controllers
    tend to implement an event queue which is populated by two sources: a
    watch connection, and a periodic poller. Controllers typically use both
    mechanisms for redundancy; the watch connection may drop, so the
    periodic polling serves as a backup. Both sources write pod updates to a
    single event queue and then a processor periodically processes the
    current state of pods as reported by the two sources.
    
    (2) Storing less specialized in-memory state in general. Previously we
    were creating hash tables to represent the state of executors. Instead,
    it's easier to represent state solely by the event queue, which has
    predictable read/write patterns and is more or less just a local
    up-to-date cache of the cluster's status.

----


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3664/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    @foxish did you have a chance to take a look?


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Agree with @mccheah on not blocking this on a design doc. This PR strictly improves the management of executor states in k8s compared to how it was done before. So we really should get this merged soon.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status failure
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3249/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3446/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Ok, addressed @dvogelbacher's comments. Also changed the subscribers to be given the whole buffer, and the subscribers can choose for some operations to be done on a per-snapshot basis but other operations only require processing the latest snapshot.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3720/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91075 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91075/testReport)** for PR 21366 at commit [`2a2374c`](https://github.com/apache/spark/commit/2a2374c915aafa1b5a53c8e02581cea0c2c176df).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91583 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91583/testReport)** for PR 21366 at commit [`03b1064`](https://github.com/apache/spark/commit/03b1064b7a2bb133a02e4616b9ed009ab36c803e).


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190951741
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala ---
    @@ -154,6 +154,24 @@ private[spark] object Config extends Logging {
           .checkValue(interval => interval > 0, s"Logging interval must be a positive time value.")
           .createWithDefaultString("1s")
     
    +  val KUBERNETES_EXECUTOR_API_POLLING_INTERVAL =
    +    ConfigBuilder("spark.kubernetes.executor.apiPollingInterval")
    +      .doc("Interval between polls against the Kubernetes API server to inspect the" +
    +        " state of executors.")
    --- End diff --
    
    I think they generally prefer putting the empty space at the end of the previous line.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #90813 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/90813/testReport)** for PR 21366 at commit [`60990f1`](https://github.com/apache/spark/commit/60990f1c4dc1169ec9cf3f74a2b623805eb4a627).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91281 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91281/testReport)** for PR 21366 at commit [`5b9c00f`](https://github.com/apache/spark/commit/5b9c00fa39d1c83435ca65de5394345e5d6f1f00).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3247/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194535271
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsSnapshotsStoreImpl.scala ---
    @@ -0,0 +1,95 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{ExecutorService, ScheduledExecutorService, TimeUnit}
    +
    +import com.google.common.collect.Lists
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.reactivex.disposables.Disposable
    +import io.reactivex.functions.Consumer
    +import io.reactivex.schedulers.Schedulers
    +import io.reactivex.subjects.PublishSubject
    +import javax.annotation.concurrent.GuardedBy
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.util.{ThreadUtils, Utils}
    +
    +private[spark] class ExecutorPodsSnapshotsStoreImpl(
    --- End diff --
    
    Prefer an impl class here because we also implement a test-only version in https://github.com/apache/spark/pull/21366/files#diff-ac93ac5a7a34f600bb942c7feb092924


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #90813 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/90813/testReport)** for PR 21366 at commit [`60990f1`](https://github.com/apache/spark/commit/60990f1c4dc1169ec9cf3f74a2b623805eb4a627).
     * This patch **fails build dependency tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3898/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194177422
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala ---
    @@ -49,48 +54,58 @@ private[spark] class ExecutorPodsAllocator(
         .withName(kubernetesDriverPodName)
         .get()
     
    -  // Use sets of ids instead of counters to be able to handle duplicate events.
    -
    -  // Executor IDs that have been requested from Kubernetes but are not running yet.
    -  private val pendingExecutors = mutable.Set.empty[Long]
    -
    -  // We could use CoarseGrainedSchedulerBackend#totalRegisteredExecutors here for tallying the
    -  // executors that are running. But, here we choose instead to maintain all state within this
    -  // class from the persecptive of the k8s API. Therefore whether or not this scheduler loop
    -  // believes an executor is running is dictated by the K8s API rather than Spark's RPC events.
    -  // We may need to consider where these perspectives may differ and which perspective should
    -  // take precedence.
    -  private val runningExecutors = mutable.Set.empty[Long]
    +  // Executor IDs that have been requested from Kubernetes but have not been detected in any
    +  // snapshot yet. Mapped to the timestamp when they were created.
    +  private val newlyCreatedExecutors = mutable.Map.empty[Long, Long]
     
       def start(applicationId: String): Unit = {
    -    eventQueue.addSubscriber(
    -      podAllocationDelay,
    -      new ExecutorPodBatchSubscriber(
    -        processUpdatedPod(applicationId),
    -        () => postProcessBatch(applicationId)))
    +    snapshotsStore.addSubscriber(podAllocationDelay) {
    +      processSnapshot(applicationId, _)
    +    }
       }
     
       def setTotalExpectedExecutors(total: Int): Unit = totalExpectedExecutors.set(total)
     
    -  private def processUpdatedPod(applicationId: String): PartialFunction[ExecutorPodState, Unit] = {
    -    case running @ PodRunning(_) =>
    -      pendingExecutors -= running.execId()
    -      runningExecutors += running.execId()
    -    case completed @ (PodSucceeded(_) | PodDeleted(_) | PodFailed(_)) =>
    -      pendingExecutors -= completed.execId()
    -      runningExecutors -= completed.execId()
    -    case _ =>
    -  }
    +  private def processSnapshot(applicationId: String, snapshot: ExecutorPodsSnapshot): Unit = {
    +    snapshot.executorPods.keys.foreach { newlyCreatedExecutors -= _ }
    +
    +    // For all executors we've created against the API but have not seen in a snapshot
    +    // yet - check the current time. If the current time has exceeded some threshold,
    +    // assume that the pod was either never created (the API server never properly
    +    // handled the creation request), or the API server created the pod but we missed
    +    // both the creation and deletion events. In either case, delete the missing pod
    +    // if possible, and mark such a pod to be rescheduled below.
    +    (newlyCreatedExecutors.keySet -- snapshot.executorPods.keySet).foreach { execId =>
    --- End diff --
    
    `newlyCreatedExecutors.keySet -- snapshot.executorPods.keySet` is unnecessary as you remove all snapshot pods from `newlyCreatedExecutors` in the line above


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191865387
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala ---
    @@ -154,6 +154,24 @@ private[spark] object Config extends Logging {
           .checkValue(interval => interval > 0, s"Logging interval must be a positive time value.")
           .createWithDefaultString("1s")
     
    +  val KUBERNETES_EXECUTOR_API_POLLING_INTERVAL =
    +    ConfigBuilder("spark.kubernetes.executor.apiPollingInterval")
    +      .doc("Interval between polls against the Kubernetes API server to inspect the " +
    +        "state of executors.")
    +      .timeConf(TimeUnit.MILLISECONDS)
    +      .checkValue(interval => interval > 0, s"API server polling interval must be a" +
    +        " positive time value.")
    +      .createWithDefaultString("30s")
    +
    +  val KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL =
    --- End diff --
    
    I think this option is hard to reason about and relies on understanding an implementation detail (the event queue). Why not just pick a default and leave it at that? What scenario do we see for the user to try and choose this value?


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status failure
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3803/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    @mccheah could you add a design doc for future reference and so that new contributors can understand better the rationale behind this. There is some description in the JIRA ticket but not enough to describe the final solution. 



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195565315
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingSnapshotSource.scala ---
    @@ -0,0 +1,65 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.util.ThreadUtils
    +
    +private[spark] class ExecutorPodsPollingSnapshotSource(
    +    conf: SparkConf,
    +    kubernetesClient: KubernetesClient,
    +    snapshotsStore: ExecutorPodsSnapshotsStore,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private val pollingInterval = conf.get(KUBERNETES_EXECUTOR_API_POLLING_INTERVAL)
    +
    +  private var pollingFuture: Future[_] = _
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), pollingInterval, pollingInterval, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (pollingFuture != null) {
    +      pollingFuture.cancel(true)
    +      pollingFuture = null
    +    }
    +    ThreadUtils.shutdown(pollingExecutor)
    +  }
    +
    +  private class PollRunnable(applicationId: String) extends Runnable {
    +    override def run(): Unit = {
    +      snapshotsStore.replaceSnapshot(kubernetesClient
    --- End diff --
    
    You could add some comment saying this is where we create executors and by what way.
    I mean on mesos you start executors when you get offers from agents and that is straightforward and makes sense. Here you want to start them ASAP I guess so then you can send tasks to them right? 


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3701/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3321/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3311/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190354568
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsEventHandler.scala ---
    @@ -0,0 +1,229 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, LinkedBlockingQueue, ScheduledExecutorService, TimeUnit}
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventProcessorExecutor: ScheduledExecutorService) extends Logging {
    +
    +  import ExecutorPodsEventHandler._
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val eventQueue = new LinkedBlockingQueue[Seq[Pod]]()
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    +
    +  // Executor IDs that have been requested from Kubernetes but are not running yet.
    +  private val pendingExecutors = mutable.Set.empty[Long]
    +
    +  // We could use CoarseGrainedSchedulerBackend#totalRegisteredExecutors here for tallying the
    +  // executors that are running. But, here we choose instead to maintain all state within this
    +  // class from the persecptive of the k8s API. Therefore whether or not this scheduler loop
    +  // believes an executor is running is dictated by the K8s API rather than Spark's RPC events.
    +  // We may need to consider where these perspectives may differ and which perspective should
    +  // take precedence.
    +  private val runningExecutors = mutable.Set.empty[Long]
    +
    +  private var eventProcessorFuture: Future[_] = _
    +
    +  def start(applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    require(eventProcessorFuture == null, "Cannot start event processing twice.")
    +    logInfo(s"Starting Kubernetes executor pods event handler for application with" +
    +      s" id $applicationId.")
    +    val eventProcessor = new Runnable {
    +      override def run(): Unit = {
    +        Utils.tryLogNonFatalError {
    +          processEvents(applicationId, schedulerBackend)
    +        }
    +      }
    +    }
    +    eventProcessorFuture = eventProcessorExecutor.scheduleWithFixedDelay(
    +      eventProcessor, 0L, podAllocationDelay, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (eventProcessorFuture != null) {
    +      eventProcessorFuture.cancel(true)
    +      eventProcessorFuture = null
    +    }
    +  }
    +
    +  private def processEvents(
    +      applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend) {
    +    val currentEvents = new java.util.ArrayList[Seq[Pod]](eventQueue.size())
    +    eventQueue.drainTo(currentEvents)
    +    currentEvents.asScala.flatten.foreach { updatedPod =>
    +      val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +      val podPhase = updatedPod.getStatus.getPhase.toLowerCase
    +      if (isDeleted(updatedPod)) {
    +        removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +      } else {
    +        updatedPod.getStatus.getPhase.toLowerCase match {
    +          case "running" =>
    +            // If clause is for resililence to out of order operations - executor must be
    +            // pending and first reach running. Without this check you may e.g. process a
    +            // deletion event followed by some arbitrary modification event - we want the
    +            // deletion event to "stick".
    +            if (pendingExecutors.contains(execId)) {
    +              pendingExecutors.remove(execId)
    +              runningExecutors.add(execId)
    +            }
    +          // TODO (SPARK-24135) - handle more classes of errors
    +          case "error" | "failed" | "succeeded" =>
    +            // If deletion failed on a previous try, we can try again if resync informs us the pod
    +            // is still around.
    +            // Delete as best attempt - duplicate deletes will throw an exception but the end state
    +            // of getting rid of the pod is what matters.
    +            if (!isDeleted(updatedPod)) {
    +              Utils.tryLogNonFatalError {
    +                kubernetesClient
    +                  .pods()
    +                  .withName(updatedPod.getMetadata.getName)
    +                  .delete()
    +              }
    +            }
    +            removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +        }
    +      }
    +    }
    +
    +    val currentRunningExecutors = runningExecutors.size
    --- End diff --
    
    I think you can move the code for creating new executors to its own executor service that can actually run concurrently with the executor service for processing pod events. This way you can use independent schedules for the two. I think this is less confusing and allows pod event processing to run with a higher frequency than pod allocation. 


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3699/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190962726
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsLifecycleEventHandler.scala ---
    @@ -0,0 +1,130 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.TimeUnit
    +
    +import com.google.common.cache.{Cache, CacheBuilder}
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsLifecycleEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    podsEventQueue: ExecutorPodsEventQueue,
    +    // Use a best-effort to track which executors have been removed already. It's not generally
    +    // job-breaking if we remove executors more than once but it's ideal if we make an attempt
    +    // to avoid doing so. Expire cache entries so that this data structure doesn't grow beyond
    +    // bounds.
    +    removedExecutorsCache: Cache[java.lang.Long, java.lang.Long] =
    --- End diff --
    
    For usage, see line 87. Avoid removing the same executor from Spark's management components twice.
    
    We can inject this from `KubernetesClusterManager` if you believe that's easier to read.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3445/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190958844
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterManager.scala ---
    @@ -56,17 +56,43 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)),
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)))
     
    -    val allocatorExecutor = ThreadUtils
    -      .newDaemonSingleThreadScheduledExecutor("kubernetes-pod-allocator")
         val requestExecutorsService = ThreadUtils.newDaemonCachedThreadPool(
           "kubernetes-executor-requests")
    +
    +    val bufferEventsExecutor = ThreadUtils
    +      .newDaemonSingleThreadScheduledExecutor("kubernetes-executor-pods-event-buffer")
    +    val executeEventSubscribersExecutor = ThreadUtils
    +      .newDaemonCachedThreadPool("kubernetes-executor-pods-event-handlers")
    +    val eventQueue = new ExecutorPodsEventQueueImpl(
    +      bufferEventsExecutor, executeEventSubscribersExecutor)
    --- End diff --
    
    Given that we now have several executors to shutdown, can we shutdown them all in as few places as possible, e.g., in `KubernetesClusterSchedulerBackend.stop`? For example, you can shutdown `requestExecutorsService` and `eventsPollingExecutor` in `KubernetesClusterSchedulerBackend.stop`. Shutdown of `bufferEventsExecutor` and `executeEventSubscribersExecutor` probably need to handled by `ExecutorPodsEventQueueImpl` in its `stopProcessingEvents` method. Ideally they should be shutdown in the same place where they are created, but it's not doable in this case because `KubernetesClusterManager` doesn't have a stop method.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r192200162
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsLifecycleEventHandler.scala ---
    @@ -0,0 +1,130 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import com.google.common.cache.{Cache, CacheBuilder}
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsLifecycleEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    podsEventQueue: ExecutorPodsEventQueue,
    +    // Use a best-effort to track which executors have been removed already. It's not generally
    +    // job-breaking if we remove executors more than once but it's ideal if we make an attempt
    +    // to avoid doing so. Expire cache entries so that this data structure doesn't grow beyond
    +    // bounds.
    +    removedExecutorsCache: Cache[java.lang.Long, java.lang.Long]) {
    +
    +  import ExecutorPodsLifecycleEventHandler._
    +
    +  private val eventProcessingInterval = conf.get(KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL)
    +
    +  def start(schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    podsEventQueue.addSubscriber(eventProcessingInterval) { updatedPods =>
    +      updatedPods.foreach { updatedPod =>
    +        processUpdatedPod(schedulerBackend, updatedPod)
    +      }
    +    }
    +  }
    +
    +  private def processUpdatedPod(
    +      schedulerBackend: KubernetesClusterSchedulerBackend, updatedPod: Pod) = {
    +    val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +    if (isDeleted(updatedPod)) {
    +      removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +    } else {
    +      updatedPod.getStatus.getPhase.toLowerCase match {
    +        // TODO (SPARK-24135) - handle more classes of errors
    +        case "error" | "failed" | "succeeded" =>
    --- End diff --
    
    btw, I just tried testing a pod with an init error locally and doing `kubectl get -o=yaml pod {name} | grep phase` gives me `phase: Failed`. So I think the Init errors of `SPARK-24135` will be handled by this as well. 


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194183023
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsSnapshotsStoreImpl.scala ---
    @@ -0,0 +1,95 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{ExecutorService, ScheduledExecutorService, TimeUnit}
    +
    +import com.google.common.collect.Lists
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.reactivex.disposables.Disposable
    +import io.reactivex.functions.Consumer
    +import io.reactivex.schedulers.Schedulers
    +import io.reactivex.subjects.PublishSubject
    +import javax.annotation.concurrent.GuardedBy
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.util.{ThreadUtils, Utils}
    +
    +private[spark] class ExecutorPodsSnapshotsStoreImpl(
    +    bufferSnapshotsExecutor: ScheduledExecutorService,
    +    executeSubscriptionsExecutor: ExecutorService)
    +  extends ExecutorPodsSnapshotsStore {
    +
    +  private val SNAPSHOT_LOCK = new Object()
    +
    +  private val snapshotsObservable = PublishSubject.create[ExecutorPodsSnapshot]()
    +  private val observedDisposables = mutable.Buffer.empty[Disposable]
    +
    +  @GuardedBy("SNAPSHOT_LOCK")
    +  private var currentSnapshot = ExecutorPodsSnapshot()
    +
    +  override def addSubscriber(
    +      processBatchIntervalMillis: Long)
    +      (subscriber: ExecutorPodsSnapshot => Unit): Unit = {
    +    observedDisposables += snapshotsObservable
    +      // Group events in the time window given by the caller. These buffers are then sent
    +      // to the caller's lambda at the given interval, with the pod updates that occurred
    +      // in that given interval.
    +      .buffer(
    +        processBatchIntervalMillis,
    +        TimeUnit.MILLISECONDS,
    +        // For testing - specifically use the given scheduled executor service to trigger
    +        // buffer boundaries. Allows us to inject a deterministic scheduler here.
    +        Schedulers.from(bufferSnapshotsExecutor))
    +      // Trigger an event cycle immediately. Not strictly required to be fully correct, but
    +      // in particular the pod allocator should try to request executors immediately instead
    +      // of waiting for one pod allocation delay.
    +      .startWith(Lists.newArrayList(ExecutorPodsSnapshot()))
    +      // Force all triggered events - both the initial event above and the buffered ones in
    +      // the following time windows - to execute asynchronously to this call's thread.
    +      .observeOn(Schedulers.from(executeSubscriptionsExecutor))
    +      .subscribe(toReactivexConsumer { snapshots: java.util.List[ExecutorPodsSnapshot] =>
    +        Utils.tryLogNonFatalError {
    +          snapshots.asScala.foreach(subscriber)
    +        }
    +      })
    +  }
    +
    +  override def stop(): Unit = {
    +    observedDisposables.foreach(_.dispose())
    +    snapshotsObservable.onComplete()
    +    ThreadUtils.shutdown(bufferSnapshotsExecutor)
    +    ThreadUtils.shutdown(executeSubscriptionsExecutor)
    +  }
    +
    +  override def updatePod(updatedPod: Pod): Unit = SNAPSHOT_LOCK.synchronized {
    +    currentSnapshot = currentSnapshot.withUpdate(updatedPod)
    --- End diff --
    
    gotcha, that makes sense


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190365332
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsEventHandler.scala ---
    @@ -0,0 +1,229 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, LinkedBlockingQueue, ScheduledExecutorService, TimeUnit}
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventProcessorExecutor: ScheduledExecutorService) extends Logging {
    +
    +  import ExecutorPodsEventHandler._
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val eventQueue = new LinkedBlockingQueue[Seq[Pod]]()
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    +
    +  // Executor IDs that have been requested from Kubernetes but are not running yet.
    +  private val pendingExecutors = mutable.Set.empty[Long]
    +
    +  // We could use CoarseGrainedSchedulerBackend#totalRegisteredExecutors here for tallying the
    +  // executors that are running. But, here we choose instead to maintain all state within this
    +  // class from the persecptive of the k8s API. Therefore whether or not this scheduler loop
    +  // believes an executor is running is dictated by the K8s API rather than Spark's RPC events.
    +  // We may need to consider where these perspectives may differ and which perspective should
    +  // take precedence.
    +  private val runningExecutors = mutable.Set.empty[Long]
    +
    +  private var eventProcessorFuture: Future[_] = _
    +
    +  def start(applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    require(eventProcessorFuture == null, "Cannot start event processing twice.")
    +    logInfo(s"Starting Kubernetes executor pods event handler for application with" +
    +      s" id $applicationId.")
    +    val eventProcessor = new Runnable {
    +      override def run(): Unit = {
    +        Utils.tryLogNonFatalError {
    +          processEvents(applicationId, schedulerBackend)
    +        }
    +      }
    +    }
    +    eventProcessorFuture = eventProcessorExecutor.scheduleWithFixedDelay(
    +      eventProcessor, 0L, podAllocationDelay, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (eventProcessorFuture != null) {
    +      eventProcessorFuture.cancel(true)
    +      eventProcessorFuture = null
    +    }
    +  }
    +
    +  private def processEvents(
    +      applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend) {
    +    val currentEvents = new java.util.ArrayList[Seq[Pod]](eventQueue.size())
    +    eventQueue.drainTo(currentEvents)
    +    currentEvents.asScala.flatten.foreach { updatedPod =>
    +      val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +      val podPhase = updatedPod.getStatus.getPhase.toLowerCase
    +      if (isDeleted(updatedPod)) {
    +        removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +      } else {
    +        updatedPod.getStatus.getPhase.toLowerCase match {
    +          case "running" =>
    +            // If clause is for resililence to out of order operations - executor must be
    +            // pending and first reach running. Without this check you may e.g. process a
    +            // deletion event followed by some arbitrary modification event - we want the
    +            // deletion event to "stick".
    +            if (pendingExecutors.contains(execId)) {
    +              pendingExecutors.remove(execId)
    +              runningExecutors.add(execId)
    +            }
    +          // TODO (SPARK-24135) - handle more classes of errors
    +          case "error" | "failed" | "succeeded" =>
    +            // If deletion failed on a previous try, we can try again if resync informs us the pod
    +            // is still around.
    +            // Delete as best attempt - duplicate deletes will throw an exception but the end state
    +            // of getting rid of the pod is what matters.
    +            if (!isDeleted(updatedPod)) {
    +              Utils.tryLogNonFatalError {
    +                kubernetesClient
    +                  .pods()
    +                  .withName(updatedPod.getMetadata.getName)
    +                  .delete()
    +              }
    +            }
    +            removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +        }
    +      }
    +    }
    +
    +    val currentRunningExecutors = runningExecutors.size
    --- End diff --
    
    I thought about this, and prefer the current way because of the ease of reasoning about synchronization. One of the downsides with the previous approach was the need to synchronize state and reason about thread safety in multiple places. With a separate executor service that reads/writes from the `pendingExecutorIds` and `runningExecutorIds` field, we'd have to reason about how the two executors would share about these data structures with the right thread safety model.
    
    But what do you think, would the concurrency complexity be manageable and worth the upside of having separate schedules?


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91731 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91731/testReport)** for PR 21366 at commit [`8b0a211`](https://github.com/apache/spark/commit/8b0a211f4c5046065b0e2abcac0ee71119ff6bd6).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #90921 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/90921/testReport)** for PR 21366 at commit [`9e5abfb`](https://github.com/apache/spark/commit/9e5abfbf2d21b788e26315f11cfeb1a83c82262e).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status failure
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3244/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190964856
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingEventSource.scala ---
    @@ -0,0 +1,65 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +
    +private[spark] class ExecutorPodsPollingEventSource(
    +    conf: SparkConf,
    +    kubernetesClient: KubernetesClient,
    +    eventQueue: ExecutorPodsEventQueue,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private val pollingInterval = conf.get(KUBERNETES_EXECUTOR_API_POLLING_INTERVAL)
    +
    +  private var pollingFuture: Future[_] = _
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), pollingInterval, pollingInterval, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (pollingFuture != null) {
    +      pollingFuture.cancel(true)
    +      pollingFuture = null
    +    }
    +    pollingExecutor.shutdown()
    --- End diff --
    
    Yes, but that's unfortunate. But for our code I think we should use a consistent mechanism to gracefully shutdown the executors.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    I think there's a single case here that could be missed.
    
    If we delete a pod from the API server entirely, and neither the watch receives a Pod with the deletion timestamp set OR the polling captures the pod with a deletion timestamp set, and the pod just disappears from the cluster and a subsequent poll doesn't return the pod at all - in that specific case we won't mark the pod as deleted.
    
    I think the above case shows that we're not being 100% accurate in a level triggered approach. If you look carefully, we're only processing pod state as seen by a periodic poll or watch events. But that isn't equivalent to monitoring the whole cluster's state, periodically.
    
    @foxish @dvogelbacher can you double check my theory here?


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91727 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91727/testReport)** for PR 21366 at commit [`108181d`](https://github.com/apache/spark/commit/108181d8190b7bc15eb80caeceff2ce8103284a4).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91074 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91074/testReport)** for PR 21366 at commit [`4f58393`](https://github.com/apache/spark/commit/4f583939f9e3d6d1df7a0d44ec0c5acf6ae82ef1).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3410/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195542619
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingSnapshotSource.scala ---
    @@ -0,0 +1,65 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.util.ThreadUtils
    +
    +private[spark] class ExecutorPodsPollingSnapshotSource(
    +    conf: SparkConf,
    +    kubernetesClient: KubernetesClient,
    +    snapshotsStore: ExecutorPodsSnapshotsStore,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private val pollingInterval = conf.get(KUBERNETES_EXECUTOR_API_POLLING_INTERVAL)
    +
    +  private var pollingFuture: Future[_] = _
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), pollingInterval, pollingInterval, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (pollingFuture != null) {
    +      pollingFuture.cancel(true)
    +      pollingFuture = null
    +    }
    +    ThreadUtils.shutdown(pollingExecutor)
    +  }
    +
    +  private class PollRunnable(applicationId: String) extends Runnable {
    +    override def run(): Unit = {
    +      snapshotsStore.replaceSnapshot(kubernetesClient
    --- End diff --
    
    I see - I think what we actually want is `ExecutorPodsSnapshotStoreImpl` to initialize the subscriber with its current snapshot. That creates the semantics where the new subscriber will first receive the most up to date state immediately.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194179846
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsSnapshotsStoreImpl.scala ---
    @@ -0,0 +1,95 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{ExecutorService, ScheduledExecutorService, TimeUnit}
    +
    +import com.google.common.collect.Lists
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.reactivex.disposables.Disposable
    +import io.reactivex.functions.Consumer
    +import io.reactivex.schedulers.Schedulers
    +import io.reactivex.subjects.PublishSubject
    +import javax.annotation.concurrent.GuardedBy
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.util.{ThreadUtils, Utils}
    +
    +private[spark] class ExecutorPodsSnapshotsStoreImpl(
    +    bufferSnapshotsExecutor: ScheduledExecutorService,
    +    executeSubscriptionsExecutor: ExecutorService)
    +  extends ExecutorPodsSnapshotsStore {
    +
    +  private val SNAPSHOT_LOCK = new Object()
    +
    +  private val snapshotsObservable = PublishSubject.create[ExecutorPodsSnapshot]()
    +  private val observedDisposables = mutable.Buffer.empty[Disposable]
    +
    +  @GuardedBy("SNAPSHOT_LOCK")
    +  private var currentSnapshot = ExecutorPodsSnapshot()
    +
    +  override def addSubscriber(
    +      processBatchIntervalMillis: Long)
    +      (subscriber: ExecutorPodsSnapshot => Unit): Unit = {
    +    observedDisposables += snapshotsObservable
    +      // Group events in the time window given by the caller. These buffers are then sent
    +      // to the caller's lambda at the given interval, with the pod updates that occurred
    +      // in that given interval.
    +      .buffer(
    +        processBatchIntervalMillis,
    +        TimeUnit.MILLISECONDS,
    +        // For testing - specifically use the given scheduled executor service to trigger
    +        // buffer boundaries. Allows us to inject a deterministic scheduler here.
    +        Schedulers.from(bufferSnapshotsExecutor))
    +      // Trigger an event cycle immediately. Not strictly required to be fully correct, but
    +      // in particular the pod allocator should try to request executors immediately instead
    +      // of waiting for one pod allocation delay.
    +      .startWith(Lists.newArrayList(ExecutorPodsSnapshot()))
    +      // Force all triggered events - both the initial event above and the buffered ones in
    +      // the following time windows - to execute asynchronously to this call's thread.
    +      .observeOn(Schedulers.from(executeSubscriptionsExecutor))
    +      .subscribe(toReactivexConsumer { snapshots: java.util.List[ExecutorPodsSnapshot] =>
    +        Utils.tryLogNonFatalError {
    +          snapshots.asScala.foreach(subscriber)
    +        }
    +      })
    +  }
    +
    +  override def stop(): Unit = {
    +    observedDisposables.foreach(_.dispose())
    +    snapshotsObservable.onComplete()
    +    ThreadUtils.shutdown(bufferSnapshotsExecutor)
    +    ThreadUtils.shutdown(executeSubscriptionsExecutor)
    +  }
    +
    +  override def updatePod(updatedPod: Pod): Unit = SNAPSHOT_LOCK.synchronized {
    +    currentSnapshot = currentSnapshot.withUpdate(updatedPod)
    --- End diff --
    
    we only ever need to send the latest snapshot update with this new approach, so having the `snapshotsObservable buffer` doesn't make sense anymore? I.e., we don't need to send the subscriber all the Snapshots that happened during a given interval. Only the last one.
    So we can just have a periodic task that takes the latest snapshot and sends it to all subscribers.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194856403
  
    --- Diff: pom.xml ---
    @@ -760,6 +760,12 @@
             <version>1.10.19</version>
             <scope>test</scope>
           </dependency>
    +      <dependency>
    --- End diff --
    
    I ended up just removing reactive programming entirely - the buffering is implemented manually. Please take a look.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Latest change removes the dependency on rxjava.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    > @mccheah could you add a design doc for future reference and so that new contributors can understand better the rationale behind this. There is some description in the JIRA ticket but not enough to describe the final solution.
    
    I can do that, but would we consider that blocking the merge of this PR? I'd like to get this in soon, it's been open for awhile.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190762965
  
    --- Diff: resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/DeterministicExecutorPodsEventQueue.scala ---
    @@ -0,0 +1,41 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import io.fabric8.kubernetes.api.model.Pod
    +import scala.collection.mutable
    +
    +class DeterministicExecutorPodsEventQueue extends ExecutorPodsEventQueue {
    +
    +  private val eventBuffer = mutable.Buffer.empty[Pod]
    +  private val subscribers = mutable.Buffer.empty[(Seq[Pod]) => Unit]
    +
    +  override def addSubscriber
    +      (processBatchIntervalMillis: Long)
    +      (onNextBatch: (Seq[Pod]) => Unit): Unit = {
    +    subscribers += onNextBatch
    +  }
    +
    +  override def stopProcessingEvents(): Unit = {}
    +
    +  override def pushPodUpdate(updatedPod: Pod): Unit = eventBuffer += updatedPod
    --- End diff --
    
    Yup, basically just a live stream of the pod statuses as reported by the API.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191913958
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala ---
    @@ -154,6 +154,24 @@ private[spark] object Config extends Logging {
           .checkValue(interval => interval > 0, s"Logging interval must be a positive time value.")
           .createWithDefaultString("1s")
     
    +  val KUBERNETES_EXECUTOR_API_POLLING_INTERVAL =
    +    ConfigBuilder("spark.kubernetes.executor.apiPollingInterval")
    +      .doc("Interval between polls against the Kubernetes API server to inspect the " +
    +        "state of executors.")
    +      .timeConf(TimeUnit.MILLISECONDS)
    +      .checkValue(interval => interval > 0, s"API server polling interval must be a" +
    +        " positive time value.")
    +      .createWithDefaultString("30s")
    +
    +  val KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL =
    --- End diff --
    
    I think it's fine to leave this configurable but not to document it. It would give users an escape hatch if for whatever reason they do need to adjust the timing.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191914114
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala ---
    @@ -0,0 +1,120 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +
    +private[spark] class ExecutorPodsAllocator(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventQueue: ExecutorPodsEventQueue) extends Logging {
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    --- End diff --
    
    It's in reference to both mutable hash sets below. A suggestion on how to better format this?


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194181797
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsSnapshotsStoreImpl.scala ---
    @@ -0,0 +1,95 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{ExecutorService, ScheduledExecutorService, TimeUnit}
    +
    +import com.google.common.collect.Lists
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.reactivex.disposables.Disposable
    +import io.reactivex.functions.Consumer
    +import io.reactivex.schedulers.Schedulers
    +import io.reactivex.subjects.PublishSubject
    +import javax.annotation.concurrent.GuardedBy
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.util.{ThreadUtils, Utils}
    +
    +private[spark] class ExecutorPodsSnapshotsStoreImpl(
    +    bufferSnapshotsExecutor: ScheduledExecutorService,
    +    executeSubscriptionsExecutor: ExecutorService)
    +  extends ExecutorPodsSnapshotsStore {
    +
    +  private val SNAPSHOT_LOCK = new Object()
    +
    +  private val snapshotsObservable = PublishSubject.create[ExecutorPodsSnapshot]()
    +  private val observedDisposables = mutable.Buffer.empty[Disposable]
    +
    +  @GuardedBy("SNAPSHOT_LOCK")
    +  private var currentSnapshot = ExecutorPodsSnapshot()
    +
    +  override def addSubscriber(
    +      processBatchIntervalMillis: Long)
    +      (subscriber: ExecutorPodsSnapshot => Unit): Unit = {
    +    observedDisposables += snapshotsObservable
    +      // Group events in the time window given by the caller. These buffers are then sent
    +      // to the caller's lambda at the given interval, with the pod updates that occurred
    +      // in that given interval.
    +      .buffer(
    +        processBatchIntervalMillis,
    +        TimeUnit.MILLISECONDS,
    +        // For testing - specifically use the given scheduled executor service to trigger
    +        // buffer boundaries. Allows us to inject a deterministic scheduler here.
    +        Schedulers.from(bufferSnapshotsExecutor))
    +      // Trigger an event cycle immediately. Not strictly required to be fully correct, but
    +      // in particular the pod allocator should try to request executors immediately instead
    +      // of waiting for one pod allocation delay.
    +      .startWith(Lists.newArrayList(ExecutorPodsSnapshot()))
    +      // Force all triggered events - both the initial event above and the buffered ones in
    +      // the following time windows - to execute asynchronously to this call's thread.
    +      .observeOn(Schedulers.from(executeSubscriptionsExecutor))
    +      .subscribe(toReactivexConsumer { snapshots: java.util.List[ExecutorPodsSnapshot] =>
    +        Utils.tryLogNonFatalError {
    +          snapshots.asScala.foreach(subscriber)
    +        }
    +      })
    +  }
    +
    +  override def stop(): Unit = {
    +    observedDisposables.foreach(_.dispose())
    +    snapshotsObservable.onComplete()
    +    ThreadUtils.shutdown(bufferSnapshotsExecutor)
    +    ThreadUtils.shutdown(executeSubscriptionsExecutor)
    +  }
    +
    +  override def updatePod(updatedPod: Pod): Unit = SNAPSHOT_LOCK.synchronized {
    +    currentSnapshot = currentSnapshot.withUpdate(updatedPod)
    --- End diff --
    
    I'm pretty sure we want all snapshots. The reason is to get a more accurate response in the lifecycle handler. If a pod enters and error state and then someone marks it for deletion, you want to at least have the chance to capture the error state when sending the executor removal request to the Spark scheduler.
    
    For the pods allocator we can do either the latest or all.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194176787
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala ---
    @@ -105,14 +120,15 @@ private[spark] class ExecutorPodsAllocator(
               .endSpec()
               .build()
             kubernetesClient.pods().create(podWithAttachedContainer)
    -        pendingExecutors += newExecutorId
    +        newlyCreatedExecutors(newExecutorId) = clock.getTimeMillis()
           }
         } else if (currentRunningExecutors >= currentTotalExpectedExecutors) {
    +      // TODO handle edge cases if we end up with more running executors than expected.
           logDebug("Current number of running executors is equal to the number of requested" +
             " executors. Not scaling up further.")
    -    } else if (pendingExecutors.nonEmpty) {
    -      logDebug(s"Still waiting for ${pendingExecutors.size} executors to begin running before" +
    -        " requesting for more executors.")
    +    } else if (newlyCreatedExecutors.nonEmpty || currentPendingExecutors != 0) {
    +      logDebug(s"Still waiting for ${newlyCreatedExecutors.size + currentPendingExecutors}" +
    --- End diff --
    
    can we make this debug statement more verbose to distinguish between `newlyCreatedExecutors` and `currentPendingExecutors ` ? might help in case anyone ever needs to debug executors never reaching pending state or something like that


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #90810 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/90810/testReport)** for PR 21366 at commit [`310263c`](https://github.com/apache/spark/commit/310263c253a8c4a3748cab5b5a7698e076695cd6).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190964276
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingEventSource.scala ---
    @@ -0,0 +1,65 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +
    +private[spark] class ExecutorPodsPollingEventSource(
    +    conf: SparkConf,
    +    kubernetesClient: KubernetesClient,
    +    eventQueue: ExecutorPodsEventQueue,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private val pollingInterval = conf.get(KUBERNETES_EXECUTOR_API_POLLING_INTERVAL)
    +
    +  private var pollingFuture: Future[_] = _
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), pollingInterval, pollingInterval, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (pollingFuture != null) {
    +      pollingFuture.cancel(true)
    +      pollingFuture = null
    +    }
    +    pollingExecutor.shutdown()
    --- End diff --
    
    I don't think we use `MoreExecutors` to shut down executors throughout the Spark project in general. See e.g. `BlockManager#stop()`.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r189739169
  
    --- Diff: pom.xml ---
    @@ -150,6 +150,7 @@
         <!--  org.apache.httpcomponents/httpclient-->
         <commons.httpclient.version>4.5.4</commons.httpclient.version>
         <commons.httpcore.version>4.4.8</commons.httpcore.version>
    +    <trove.version>3.0.1</trove.version>
    --- End diff --
    
    Noted, will remove in the next push.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190356134
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsEventHandler.scala ---
    @@ -0,0 +1,229 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, LinkedBlockingQueue, ScheduledExecutorService, TimeUnit}
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventProcessorExecutor: ScheduledExecutorService) extends Logging {
    +
    +  import ExecutorPodsEventHandler._
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val eventQueue = new LinkedBlockingQueue[Seq[Pod]]()
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    +
    +  // Executor IDs that have been requested from Kubernetes but are not running yet.
    +  private val pendingExecutors = mutable.Set.empty[Long]
    +
    +  // We could use CoarseGrainedSchedulerBackend#totalRegisteredExecutors here for tallying the
    +  // executors that are running. But, here we choose instead to maintain all state within this
    +  // class from the persecptive of the k8s API. Therefore whether or not this scheduler loop
    +  // believes an executor is running is dictated by the K8s API rather than Spark's RPC events.
    +  // We may need to consider where these perspectives may differ and which perspective should
    +  // take precedence.
    +  private val runningExecutors = mutable.Set.empty[Long]
    +
    +  private var eventProcessorFuture: Future[_] = _
    +
    +  def start(applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    require(eventProcessorFuture == null, "Cannot start event processing twice.")
    +    logInfo(s"Starting Kubernetes executor pods event handler for application with" +
    +      s" id $applicationId.")
    +    val eventProcessor = new Runnable {
    +      override def run(): Unit = {
    +        Utils.tryLogNonFatalError {
    +          processEvents(applicationId, schedulerBackend)
    +        }
    +      }
    +    }
    +    eventProcessorFuture = eventProcessorExecutor.scheduleWithFixedDelay(
    +      eventProcessor, 0L, podAllocationDelay, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (eventProcessorFuture != null) {
    +      eventProcessorFuture.cancel(true)
    +      eventProcessorFuture = null
    +    }
    +  }
    +
    +  private def processEvents(
    +      applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend) {
    +    val currentEvents = new java.util.ArrayList[Seq[Pod]](eventQueue.size())
    +    eventQueue.drainTo(currentEvents)
    +    currentEvents.asScala.flatten.foreach { updatedPod =>
    +      val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +      val podPhase = updatedPod.getStatus.getPhase.toLowerCase
    +      if (isDeleted(updatedPod)) {
    +        removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +      } else {
    +        updatedPod.getStatus.getPhase.toLowerCase match {
    +          case "running" =>
    +            // If clause is for resililence to out of order operations - executor must be
    +            // pending and first reach running. Without this check you may e.g. process a
    +            // deletion event followed by some arbitrary modification event - we want the
    +            // deletion event to "stick".
    +            if (pendingExecutors.contains(execId)) {
    +              pendingExecutors.remove(execId)
    +              runningExecutors.add(execId)
    +            }
    +          // TODO (SPARK-24135) - handle more classes of errors
    +          case "error" | "failed" | "succeeded" =>
    +            // If deletion failed on a previous try, we can try again if resync informs us the pod
    +            // is still around.
    +            // Delete as best attempt - duplicate deletes will throw an exception but the end state
    +            // of getting rid of the pod is what matters.
    +            if (!isDeleted(updatedPod)) {
    +              Utils.tryLogNonFatalError {
    +                kubernetesClient
    +                  .pods()
    +                  .withName(updatedPod.getMetadata.getName)
    +                  .delete()
    +              }
    +            }
    +            removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +        }
    +      }
    +    }
    +
    +    val currentRunningExecutors = runningExecutors.size
    +    val currentTotalExpectedExecutors = totalExpectedExecutors.get
    +    if (pendingExecutors.isEmpty && currentRunningExecutors < currentTotalExpectedExecutors) {
    +      val numExecutorsToAllocate = math.min(
    +        currentTotalExpectedExecutors - currentRunningExecutors, podAllocationSize)
    +      logInfo(s"Going to request $numExecutorsToAllocate executors from Kubernetes.")
    +      val newExecutorIds = mutable.Buffer.empty[Long]
    +      val podsToAllocate = mutable.Buffer.empty[Pod]
    +      for ( _ <- 0 until numExecutorsToAllocate) {
    +        val newExecutorId = EXECUTOR_ID_COUNTER.incrementAndGet()
    +        val executorConf = KubernetesConf.createExecutorConf(
    +          conf,
    +          newExecutorId.toString,
    +          applicationId,
    +          driverPod)
    +        val executorPod = executorBuilder.buildFromFeatures(executorConf)
    +        val podWithAttachedContainer = new PodBuilder(executorPod.pod)
    +          .editOrNewSpec()
    +          .addToContainers(executorPod.container)
    +          .endSpec()
    +          .build()
    +        kubernetesClient.pods().create(podWithAttachedContainer)
    +        pendingExecutors += newExecutorId
    +      }
    +    } else if (currentRunningExecutors == currentTotalExpectedExecutors) {
    +      logDebug("Current number of running executors is equal to the number of requested" +
    +        " executors. Not scaling up further.")
    +    } else if (pendingExecutors.nonEmpty) {
    +      logInfo(s"Still waiting for ${pendingExecutors.size} executors to begin running before" +
    +        s" requesting for more executors.")
    +    }
    +  }
    +
    +  def sendUpdatedPodMetadata(updatedPod: Pod): Unit = {
    +    eventQueue.add(Seq(updatedPod))
    +  }
    +
    +  def sendUpdatedPodMetadata(updatedPods: Iterable[Pod]): Unit = {
    +    eventQueue.add(updatedPods.toSeq)
    --- End diff --
    
    Instead of storing a `Seq` of events, how about storing events directly, and calling `eventQueue.add` for each pod here? Then you don't need to call `flatten` when processing the events.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190964141
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterManager.scala ---
    @@ -56,17 +56,43 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)),
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)))
     
    -    val allocatorExecutor = ThreadUtils
    -      .newDaemonSingleThreadScheduledExecutor("kubernetes-pod-allocator")
         val requestExecutorsService = ThreadUtils.newDaemonCachedThreadPool(
           "kubernetes-executor-requests")
    +
    +    val bufferEventsExecutor = ThreadUtils
    +      .newDaemonSingleThreadScheduledExecutor("kubernetes-executor-pods-event-buffer")
    +    val executeEventSubscribersExecutor = ThreadUtils
    +      .newDaemonCachedThreadPool("kubernetes-executor-pods-event-handlers")
    +    val eventQueue = new ExecutorPodsEventQueueImpl(
    +      bufferEventsExecutor, executeEventSubscribersExecutor)
    --- End diff --
    
    OK, I'm fine with that.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Alright, this should be good for review now, with all cleanups and appropriate test coverage in place. Please take a look. Thanks!


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3719/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    I was planning to do one last pass over it today/tomorrow. I can merge after that.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3248/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195401593
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingSnapshotSource.scala ---
    @@ -0,0 +1,65 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.util.ThreadUtils
    +
    +private[spark] class ExecutorPodsPollingSnapshotSource(
    +    conf: SparkConf,
    +    kubernetesClient: KubernetesClient,
    +    snapshotsStore: ExecutorPodsSnapshotsStore,
    +    pollingExecutor: ScheduledExecutorService) {
    --- End diff --
    
    Could you add some debug logging here. In general it would be good to be able to trace what is happening in case of a an issue with debug mode, this applies to all classes introduced for both watching and polling.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #90819 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/90819/testReport)** for PR 21366 at commit [`522b079`](https://github.com/apache/spark/commit/522b0799b31f064e378c688eeecec3eca3b0810d).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r196257515
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala ---
    @@ -154,6 +154,24 @@ private[spark] object Config extends Logging {
           .checkValue(interval => interval > 0, s"Logging interval must be a positive time value.")
           .createWithDefaultString("1s")
     
    +  val KUBERNETES_EXECUTOR_API_POLLING_INTERVAL =
    +    ConfigBuilder("spark.kubernetes.executor.apiPollingInterval")
    +      .doc("Interval between polls against the Kubernetes API server to inspect the " +
    +        "state of executors.")
    +      .timeConf(TimeUnit.MILLISECONDS)
    +      .checkValue(interval => interval > 0, s"API server polling interval must be a" +
    +        " positive time value.")
    +      .createWithDefaultString("30s")
    +
    +  val KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL =
    --- End diff --
    
    This should have been marked with `internal()`, that was an oversight. Don't think it's entirely necessary.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3446/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3720/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191653358
  
    --- Diff: pom.xml ---
    @@ -760,6 +760,12 @@
             <version>1.10.19</version>
             <scope>test</scope>
           </dependency>
    +      <dependency>
    --- End diff --
    
    right - not saying we should completely reinvent the wheel of course. Does including this in the root pom bring the rxjava jar into the spark-core's dependency chain? If so, we should avoid it.
    
    license - you are right, for Apache 2.0 we don't need to list. but `jmock` yes the way you have.



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status failure
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3410/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190385827
  
    --- Diff: pom.xml ---
    @@ -760,6 +760,12 @@
             <version>1.10.19</version>
             <scope>test</scope>
           </dependency>
    +      <dependency>
    --- End diff --
    
    We always add to the top level and then in the lower level poms, we reference the dependent modules without listing their versions.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194572858
  
    --- Diff: pom.xml ---
    @@ -760,6 +760,12 @@
             <version>1.10.19</version>
             <scope>test</scope>
           </dependency>
    +      <dependency>
    --- End diff --
    
    > f not mistaken Java 9 has introduced the related interfaces, so rx-java might not be needed in the future when Spark will update the supported java version.
    
    Spark will need to support Java 8 for the foreseeable future. We'll be using a Java 8 only compatible solution for awhile.
    
    > Some more scala centric implementations: akka streams a Reactive Streams and JDK 9+ java.util.concurrent.Flow-compliant implementation. This does not depend on rx-java.
    Also there is monix, and RxScala seems outdated. A comparison between monix and others here.
    
    Does Akka streams without JDK 9 depend on ReactiveX? If so then we have the same dependency problem. As for monix vs. Akka vs. RxJava, think that's an implementation detail - at the end of the day the main concern is the dependency addition and either way we're adding an external dependency vs. implementing the semantics ourselves. If we think monix / Akka is the more elegant solution over RxJava we can switch to that, but given how little we're actually doing that's actually in the functional programming style I don't think the difference between Java and Scala is significant in this particular instance.
    
    > From the dependencies already brought in by Spark is there a lib that could provide similar functionality, if not based on Reactive stuff some other way queues or something?
    
    I didn't see any but I am open to being corrected here. Spark implements an event queue but it doesn't suffice for the paradigm of having multiple subscribers process snapshots at different intervals.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Do most controllers use both Watches and polling? I'm wondering if we can just poll very frequently and not have the watch.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3555/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3322/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190963140
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterManager.scala ---
    @@ -56,17 +56,43 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)),
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)))
     
    -    val allocatorExecutor = ThreadUtils
    -      .newDaemonSingleThreadScheduledExecutor("kubernetes-pod-allocator")
         val requestExecutorsService = ThreadUtils.newDaemonCachedThreadPool(
           "kubernetes-executor-requests")
    +
    +    val bufferEventsExecutor = ThreadUtils
    +      .newDaemonSingleThreadScheduledExecutor("kubernetes-executor-pods-event-buffer")
    +    val executeEventSubscribersExecutor = ThreadUtils
    +      .newDaemonCachedThreadPool("kubernetes-executor-pods-event-handlers")
    +    val eventQueue = new ExecutorPodsEventQueueImpl(
    +      bufferEventsExecutor, executeEventSubscribersExecutor)
    --- End diff --
    
    Think we'd want to then have all the `start` methods take the scheduled executor service as an argument, then the scheduler backend owns shutting them down. But I don't think that's the right abstraction - the subcomponents own the thread pools and know how these thread pools are being used, when tasks are being submitted to them, etc. I think it's fine to shut down these thread pools from the subcomponents.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3702/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191866216
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala ---
    @@ -0,0 +1,120 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +
    +private[spark] class ExecutorPodsAllocator(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventQueue: ExecutorPodsEventQueue) extends Logging {
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    +
    +  // Executor IDs that have been requested from Kubernetes but are not running yet.
    +  private val pendingExecutors = mutable.Set.empty[Long]
    +
    +  // We could use CoarseGrainedSchedulerBackend#totalRegisteredExecutors here for tallying the
    +  // executors that are running. But, here we choose instead to maintain all state within this
    +  // class from the persecptive of the k8s API. Therefore whether or not this scheduler loop
    +  // believes an executor is running is dictated by the K8s API rather than Spark's RPC events.
    +  // We may need to consider where these perspectives may differ and which perspective should
    +  // take precedence.
    +  private val runningExecutors = mutable.Set.empty[Long]
    +
    +  def start(applicationId: String): Unit = {
    +    eventQueue.addSubscriber(podAllocationDelay) { updatedPods =>
    +      processUpdatedPodEvents(applicationId, updatedPods)
    +    }
    +  }
    +
    +  def setTotalExpectedExecutors(total: Int): Unit = totalExpectedExecutors.set(total)
    +
    +  private def processUpdatedPodEvents(applicationId: String, updatedPods: Seq[Pod]): Unit = {
    +    updatedPods.foreach { updatedPod =>
    +      val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +      val phase = updatedPod.getStatus.getPhase.toLowerCase
    +      phase match {
    +        case "running" =>
    +          pendingExecutors -= execId
    +          runningExecutors += execId
    +        case "failed" | "succeeded" | "error" =>
    +          pendingExecutors -= execId
    +          runningExecutors -= execId
    +      }
    +    }
    +
    +    val currentRunningExecutors = runningExecutors.size
    +    val currentTotalExpectedExecutors = totalExpectedExecutors.get
    +    if (pendingExecutors.isEmpty && currentRunningExecutors < currentTotalExpectedExecutors) {
    +      val numExecutorsToAllocate = math.min(
    +        currentTotalExpectedExecutors - currentRunningExecutors, podAllocationSize)
    +      logInfo(s"Going to request $numExecutorsToAllocate executors from Kubernetes.")
    +      val newExecutorIds = mutable.Buffer.empty[Long]
    +      val podsToAllocate = mutable.Buffer.empty[Pod]
    +      for ( _ <- 0 until numExecutorsToAllocate) {
    +        val newExecutorId = EXECUTOR_ID_COUNTER.incrementAndGet()
    +        val executorConf = KubernetesConf.createExecutorConf(
    +          conf,
    +          newExecutorId.toString,
    +          applicationId,
    +          driverPod)
    +        val executorPod = executorBuilder.buildFromFeatures(executorConf)
    +        val podWithAttachedContainer = new PodBuilder(executorPod.pod)
    +          .editOrNewSpec()
    +          .addToContainers(executorPod.container)
    +          .endSpec()
    +          .build()
    +        kubernetesClient.pods().create(podWithAttachedContainer)
    +        pendingExecutors += newExecutorId
    +      }
    +    } else if (currentRunningExecutors == currentTotalExpectedExecutors) {
    --- End diff --
    
    `>=` to be more defensive?


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3723/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195379907
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsLifecycleManager.scala ---
    @@ -0,0 +1,164 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import com.google.common.cache.Cache
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsLifecycleManager(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    snapshotsStore: ExecutorPodsSnapshotsStore,
    +    // Use a best-effort to track which executors have been removed already. It's not generally
    +    // job-breaking if we remove executors more than once but it's ideal if we make an attempt
    +    // to avoid doing so. Expire cache entries so that this data structure doesn't grow beyond
    +    // bounds.
    +    removedExecutorsCache: Cache[java.lang.Long, java.lang.Long]) {
    +
    +  import ExecutorPodsLifecycleManager._
    +
    +  private val eventProcessingInterval = conf.get(KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL)
    +
    +  def start(schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    snapshotsStore.addSubscriber(eventProcessingInterval) {
    +      onNewSnapshots(schedulerBackend, _)
    +    }
    +  }
    +
    +  private def onNewSnapshots(
    +      schedulerBackend: KubernetesClusterSchedulerBackend,
    +      snapshots: Seq[ExecutorPodsSnapshot]): Unit = {
    +    val execIdsRemovedInThisRound = mutable.HashSet.empty[Long]
    +    snapshots.foreach { snapshot =>
    +      snapshot.executorPods.foreach { case (execId, state) =>
    +        state match {
    +          case deleted@PodDeleted(pod) =>
    --- End diff --
    
    s/succeeded@PodSucceeded(pod)/succeeded@PodSucceeded(_)


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91870 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91870/testReport)** for PR 21366 at commit [`1a99dce`](https://github.com/apache/spark/commit/1a99dceeb9dfbfc58e26885c290461cbf37a5428).


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190350563
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsEventHandler.scala ---
    @@ -0,0 +1,229 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, LinkedBlockingQueue, ScheduledExecutorService, TimeUnit}
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventProcessorExecutor: ScheduledExecutorService) extends Logging {
    +
    +  import ExecutorPodsEventHandler._
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val eventQueue = new LinkedBlockingQueue[Seq[Pod]]()
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    +
    +  // Executor IDs that have been requested from Kubernetes but are not running yet.
    +  private val pendingExecutors = mutable.Set.empty[Long]
    +
    +  // We could use CoarseGrainedSchedulerBackend#totalRegisteredExecutors here for tallying the
    +  // executors that are running. But, here we choose instead to maintain all state within this
    +  // class from the persecptive of the k8s API. Therefore whether or not this scheduler loop
    +  // believes an executor is running is dictated by the K8s API rather than Spark's RPC events.
    +  // We may need to consider where these perspectives may differ and which perspective should
    +  // take precedence.
    +  private val runningExecutors = mutable.Set.empty[Long]
    +
    +  private var eventProcessorFuture: Future[_] = _
    +
    +  def start(applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    require(eventProcessorFuture == null, "Cannot start event processing twice.")
    +    logInfo(s"Starting Kubernetes executor pods event handler for application with" +
    +      s" id $applicationId.")
    +    val eventProcessor = new Runnable {
    +      override def run(): Unit = {
    +        Utils.tryLogNonFatalError {
    +          processEvents(applicationId, schedulerBackend)
    +        }
    +      }
    +    }
    +    eventProcessorFuture = eventProcessorExecutor.scheduleWithFixedDelay(
    --- End diff --
    
    The `eventProcessorExecutor` should be shutdown properly. Or you can use https://google.github.io/guava/releases/17.0/api/docs/com/google/common/util/concurrent/MoreExecutors.html#getExitingScheduledExecutorService(java.util.concurrent.ScheduledThreadPoolExecutor) to avoid having to manually shutdown it.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status failure
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3804/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #90907 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/90907/testReport)** for PR 21366 at commit [`931529a`](https://github.com/apache/spark/commit/931529a74c07b3212dcbe34e7329384555777146).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r192187397
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsLifecycleEventHandler.scala ---
    @@ -0,0 +1,130 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import com.google.common.cache.{Cache, CacheBuilder}
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsLifecycleEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    podsEventQueue: ExecutorPodsEventQueue,
    +    // Use a best-effort to track which executors have been removed already. It's not generally
    +    // job-breaking if we remove executors more than once but it's ideal if we make an attempt
    +    // to avoid doing so. Expire cache entries so that this data structure doesn't grow beyond
    +    // bounds.
    +    removedExecutorsCache: Cache[java.lang.Long, java.lang.Long]) {
    +
    +  import ExecutorPodsLifecycleEventHandler._
    +
    +  private val eventProcessingInterval = conf.get(KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL)
    +
    +  def start(schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    podsEventQueue.addSubscriber(eventProcessingInterval) { updatedPods =>
    +      updatedPods.foreach { updatedPod =>
    +        processUpdatedPod(schedulerBackend, updatedPod)
    +      }
    +    }
    +  }
    +
    +  private def processUpdatedPod(
    +      schedulerBackend: KubernetesClusterSchedulerBackend, updatedPod: Pod) = {
    +    val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +    if (isDeleted(updatedPod)) {
    +      removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    --- End diff --
    
    we don't check for this in `ExecutorPodsAllocator`. So it could happen that we remove an executor here but not there. 


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190973324
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterManager.scala ---
    @@ -56,17 +56,43 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)),
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)))
     
    -    val allocatorExecutor = ThreadUtils
    -      .newDaemonSingleThreadScheduledExecutor("kubernetes-pod-allocator")
         val requestExecutorsService = ThreadUtils.newDaemonCachedThreadPool(
           "kubernetes-executor-requests")
    +
    +    val bufferEventsExecutor = ThreadUtils
    +      .newDaemonSingleThreadScheduledExecutor("kubernetes-executor-pods-event-buffer")
    +    val executeEventSubscribersExecutor = ThreadUtils
    +      .newDaemonCachedThreadPool("kubernetes-executor-pods-event-handlers")
    +    val eventQueue = new ExecutorPodsEventQueueImpl(
    +      bufferEventsExecutor, executeEventSubscribersExecutor)
    --- End diff --
    
    Done


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191061934
  
    --- Diff: pom.xml ---
    @@ -760,6 +760,12 @@
             <version>1.10.19</version>
             <scope>test</scope>
           </dependency>
    +      <dependency>
    --- End diff --
    
    also add dependency should have its LICENSE added under /license


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3320/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Agree with @mccheah on not blocking this on a design doc. This PR strictly improves the management of executor states in k8s compared to how it was done before. So we really should get this merged soon.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194184310
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsSnapshotsStoreImpl.scala ---
    @@ -0,0 +1,95 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{ExecutorService, ScheduledExecutorService, TimeUnit}
    +
    +import com.google.common.collect.Lists
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.reactivex.disposables.Disposable
    +import io.reactivex.functions.Consumer
    +import io.reactivex.schedulers.Schedulers
    +import io.reactivex.subjects.PublishSubject
    +import javax.annotation.concurrent.GuardedBy
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.util.{ThreadUtils, Utils}
    +
    +private[spark] class ExecutorPodsSnapshotsStoreImpl(
    +    bufferSnapshotsExecutor: ScheduledExecutorService,
    +    executeSubscriptionsExecutor: ExecutorService)
    +  extends ExecutorPodsSnapshotsStore {
    +
    +  private val SNAPSHOT_LOCK = new Object()
    +
    +  private val snapshotsObservable = PublishSubject.create[ExecutorPodsSnapshot]()
    +  private val observedDisposables = mutable.Buffer.empty[Disposable]
    +
    +  @GuardedBy("SNAPSHOT_LOCK")
    +  private var currentSnapshot = ExecutorPodsSnapshot()
    +
    +  override def addSubscriber(
    +      processBatchIntervalMillis: Long)
    +      (subscriber: ExecutorPodsSnapshot => Unit): Unit = {
    +    observedDisposables += snapshotsObservable
    +      // Group events in the time window given by the caller. These buffers are then sent
    +      // to the caller's lambda at the given interval, with the pod updates that occurred
    +      // in that given interval.
    +      .buffer(
    +        processBatchIntervalMillis,
    +        TimeUnit.MILLISECONDS,
    +        // For testing - specifically use the given scheduled executor service to trigger
    +        // buffer boundaries. Allows us to inject a deterministic scheduler here.
    +        Schedulers.from(bufferSnapshotsExecutor))
    +      // Trigger an event cycle immediately. Not strictly required to be fully correct, but
    +      // in particular the pod allocator should try to request executors immediately instead
    +      // of waiting for one pod allocation delay.
    +      .startWith(Lists.newArrayList(ExecutorPodsSnapshot()))
    +      // Force all triggered events - both the initial event above and the buffered ones in
    +      // the following time windows - to execute asynchronously to this call's thread.
    +      .observeOn(Schedulers.from(executeSubscriptionsExecutor))
    +      .subscribe(toReactivexConsumer { snapshots: java.util.List[ExecutorPodsSnapshot] =>
    +        Utils.tryLogNonFatalError {
    +          snapshots.asScala.foreach(subscriber)
    +        }
    +      })
    +  }
    +
    +  override def stop(): Unit = {
    +    observedDisposables.foreach(_.dispose())
    +    snapshotsObservable.onComplete()
    +    ThreadUtils.shutdown(bufferSnapshotsExecutor)
    +    ThreadUtils.shutdown(executeSubscriptionsExecutor)
    +  }
    +
    +  override def updatePod(updatedPod: Pod): Unit = SNAPSHOT_LOCK.synchronized {
    +    currentSnapshot = currentSnapshot.withUpdate(updatedPod)
    --- End diff --
    
    A brief remark that one still might not be 100% accurate because of failures in the information flow (missing events etc) - but for all the events we do get we should be trying to handle them all as best we can.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195445788
  
    --- Diff: pom.xml ---
    @@ -760,6 +760,12 @@
             <version>1.10.19</version>
             <scope>test</scope>
           </dependency>
    +      <dependency>
    --- End diff --
    
    Thanx @ktoso!


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r192187376
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsLifecycleEventHandler.scala ---
    @@ -0,0 +1,130 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import com.google.common.cache.{Cache, CacheBuilder}
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsLifecycleEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    podsEventQueue: ExecutorPodsEventQueue,
    +    // Use a best-effort to track which executors have been removed already. It's not generally
    +    // job-breaking if we remove executors more than once but it's ideal if we make an attempt
    +    // to avoid doing so. Expire cache entries so that this data structure doesn't grow beyond
    +    // bounds.
    +    removedExecutorsCache: Cache[java.lang.Long, java.lang.Long]) {
    +
    +  import ExecutorPodsLifecycleEventHandler._
    +
    +  private val eventProcessingInterval = conf.get(KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL)
    +
    +  def start(schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    podsEventQueue.addSubscriber(eventProcessingInterval) { updatedPods =>
    +      updatedPods.foreach { updatedPod =>
    +        processUpdatedPod(schedulerBackend, updatedPod)
    +      }
    +    }
    +  }
    +
    +  private def processUpdatedPod(
    +      schedulerBackend: KubernetesClusterSchedulerBackend, updatedPod: Pod) = {
    +    val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +    if (isDeleted(updatedPod)) {
    +      removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +    } else {
    +      updatedPod.getStatus.getPhase.toLowerCase match {
    +        // TODO (SPARK-24135) - handle more classes of errors
    +        case "error" | "failed" | "succeeded" =>
    --- End diff --
    
    same as above, "error" doesn't seem to be a phase


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3663/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190952296
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsEventQueue.scala ---
    @@ -0,0 +1,29 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import io.fabric8.kubernetes.api.model.Pod
    +
    +private[spark] trait ExecutorPodsEventQueue {
    +
    +  def addSubscriber(processBatchIntervalMillis: Long)(onNextBatch: Seq[Pod] => Unit): Unit
    +
    +  def stopProcessingEvents(): Unit
    +
    +  def pushPodUpdate(updatedPod: Pod): Unit
    --- End diff --
    
    Can we simply name it `enqueue` given the name of the trait already tells clearly what the queue stores? 


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190964855
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterManager.scala ---
    @@ -56,17 +56,43 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)),
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)))
     
    -    val allocatorExecutor = ThreadUtils
    -      .newDaemonSingleThreadScheduledExecutor("kubernetes-pod-allocator")
         val requestExecutorsService = ThreadUtils.newDaemonCachedThreadPool(
           "kubernetes-executor-requests")
    +
    +    val bufferEventsExecutor = ThreadUtils
    +      .newDaemonSingleThreadScheduledExecutor("kubernetes-executor-pods-event-buffer")
    +    val executeEventSubscribersExecutor = ThreadUtils
    +      .newDaemonCachedThreadPool("kubernetes-executor-pods-event-handlers")
    +    val eventQueue = new ExecutorPodsEventQueueImpl(
    +      bufferEventsExecutor, executeEventSubscribersExecutor)
    --- End diff --
    
    One way to share this logic would be to have a shared trait for all the things that have thread pools to stop, and then use the trait to stop everything. e.g.
    
    ```
    trait HasThreadPools {
    
      protected def threadPools(): Iterable[Executor]
      
      def stop(): Unit = threadPools().foreach(_.shutdownNow())
    }
    
    class MyThreadPoolsDependentClass {
    
      override def threadPools(): Iterable[Executor] = { // All the executors I want to shut down }
      
      override def stop(): Unit = {
        // Stop everything else
        super.stop()
      }
    }
    ```
    
    Not sure if it's worth the extra abstraction to do this though.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195379975
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsLifecycleManager.scala ---
    @@ -0,0 +1,164 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import com.google.common.cache.Cache
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsLifecycleManager(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    snapshotsStore: ExecutorPodsSnapshotsStore,
    +    // Use a best-effort to track which executors have been removed already. It's not generally
    +    // job-breaking if we remove executors more than once but it's ideal if we make an attempt
    +    // to avoid doing so. Expire cache entries so that this data structure doesn't grow beyond
    +    // bounds.
    +    removedExecutorsCache: Cache[java.lang.Long, java.lang.Long]) {
    +
    +  import ExecutorPodsLifecycleManager._
    +
    +  private val eventProcessingInterval = conf.get(KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL)
    +
    +  def start(schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    snapshotsStore.addSubscriber(eventProcessingInterval) {
    +      onNewSnapshots(schedulerBackend, _)
    +    }
    +  }
    +
    +  private def onNewSnapshots(
    +      schedulerBackend: KubernetesClusterSchedulerBackend,
    +      snapshots: Seq[ExecutorPodsSnapshot]): Unit = {
    +    val execIdsRemovedInThisRound = mutable.HashSet.empty[Long]
    +    snapshots.foreach { snapshot =>
    +      snapshot.executorPods.foreach { case (execId, state) =>
    +        state match {
    +          case deleted@PodDeleted(pod) =>
    +            removeExecutorFromSpark(schedulerBackend, deleted, execId)
    +            execIdsRemovedInThisRound += execId
    +          case failed@PodFailed(pod) =>
    --- End diff --
    
    same as above.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r192271761
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsLifecycleEventHandler.scala ---
    @@ -0,0 +1,130 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import com.google.common.cache.{Cache, CacheBuilder}
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsLifecycleEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    podsEventQueue: ExecutorPodsEventQueue,
    +    // Use a best-effort to track which executors have been removed already. It's not generally
    +    // job-breaking if we remove executors more than once but it's ideal if we make an attempt
    +    // to avoid doing so. Expire cache entries so that this data structure doesn't grow beyond
    +    // bounds.
    +    removedExecutorsCache: Cache[java.lang.Long, java.lang.Long]) {
    +
    +  import ExecutorPodsLifecycleEventHandler._
    +
    +  private val eventProcessingInterval = conf.get(KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL)
    +
    +  def start(schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    podsEventQueue.addSubscriber(eventProcessingInterval) { updatedPods =>
    +      updatedPods.foreach { updatedPod =>
    +        processUpdatedPod(schedulerBackend, updatedPod)
    +      }
    +    }
    +  }
    +
    +  private def processUpdatedPod(
    +      schedulerBackend: KubernetesClusterSchedulerBackend, updatedPod: Pod) = {
    +    val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +    if (isDeleted(updatedPod)) {
    +      removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    --- End diff --
    
    It's not entirely analogous but there are parts that can be shared. The pods allocator has a "post-batch" processing task which can run even on empty batches (particularly important for the first empty batch to request the first round of executors). But, I have some ideas for shared code that can be posted shortly.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3468/



---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190964894
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterManager.scala ---
    @@ -56,17 +56,43 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)),
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)))
     
    -    val allocatorExecutor = ThreadUtils
    -      .newDaemonSingleThreadScheduledExecutor("kubernetes-pod-allocator")
         val requestExecutorsService = ThreadUtils.newDaemonCachedThreadPool(
           "kubernetes-executor-requests")
    +
    +    val bufferEventsExecutor = ThreadUtils
    +      .newDaemonSingleThreadScheduledExecutor("kubernetes-executor-pods-event-buffer")
    +    val executeEventSubscribersExecutor = ThreadUtils
    +      .newDaemonCachedThreadPool("kubernetes-executor-pods-event-handlers")
    +    val eventQueue = new ExecutorPodsEventQueueImpl(
    +      bufferEventsExecutor, executeEventSubscribersExecutor)
    --- End diff --
    
    One way to share this logic would be to have a shared trait for all the things that have thread pools to stop, and then use the trait to stop everything. e.g.
    
    ```
    trait HasThreadPools {
    
      protected def threadPools(): Iterable[Executor]
      
      def stop(): Unit = threadPools().foreach(_.shutdownNow())
    }
    
    class MyThreadPoolsDependentClass {
    
      override def threadPools(): Iterable[Executor] = { // All the executors I want to shut down }
      
      override def stop(): Unit = {
        // Stop everything else
        super.stop()
      }
    }
    ```
    
    Not sure if it's worth the extra abstraction to do this though.


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195513995
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterManager.scala ---
    @@ -56,17 +58,44 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)),
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)))
     
    -    val allocatorExecutor = ThreadUtils
    -      .newDaemonSingleThreadScheduledExecutor("kubernetes-pod-allocator")
         val requestExecutorsService = ThreadUtils.newDaemonCachedThreadPool(
           "kubernetes-executor-requests")
    +
    +    val bufferSnapshotsExecutor = ThreadUtils
    +      .newDaemonSingleThreadScheduledExecutor("kubernetes-executor-snapshots-buffer")
    +    val snapshotsStore = new ExecutorPodsSnapshotsStoreImpl(bufferSnapshotsExecutor)
    +    val removedExecutorsCache = CacheBuilder.newBuilder()
    +      .expireAfterWrite(3, TimeUnit.MINUTES)
    --- End diff --
    
    The cache is only for a best effort attempt to not remove the same executor from the scheduler backend multiple times, but at the end of the day even if we do accidentally remove multiple times the only noticeable result is noisy logs. The scheduler backend properly handles multiple attempts to remove but we'd prefer it if we didn't have to.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3245/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r196249925
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala ---
    @@ -154,6 +154,24 @@ private[spark] object Config extends Logging {
           .checkValue(interval => interval > 0, s"Logging interval must be a positive time value.")
           .createWithDefaultString("1s")
     
    +  val KUBERNETES_EXECUTOR_API_POLLING_INTERVAL =
    +    ConfigBuilder("spark.kubernetes.executor.apiPollingInterval")
    +      .doc("Interval between polls against the Kubernetes API server to inspect the " +
    +        "state of executors.")
    +      .timeConf(TimeUnit.MILLISECONDS)
    +      .checkValue(interval => interval > 0, s"API server polling interval must be a" +
    +        " positive time value.")
    +      .createWithDefaultString("30s")
    +
    +  val KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL =
    --- End diff --
    
    @mccheah because this is not internal.... shouldn't we include this in `docs/` I don't see why we aren't documenting this. 


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190966224
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterManager.scala ---
    @@ -56,17 +56,43 @@ private[spark] class KubernetesClusterManager extends ExternalClusterManager wit
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)),
           Some(new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)))
     
    -    val allocatorExecutor = ThreadUtils
    -      .newDaemonSingleThreadScheduledExecutor("kubernetes-pod-allocator")
         val requestExecutorsService = ThreadUtils.newDaemonCachedThreadPool(
           "kubernetes-executor-requests")
    +
    +    val bufferEventsExecutor = ThreadUtils
    +      .newDaemonSingleThreadScheduledExecutor("kubernetes-executor-pods-event-buffer")
    +    val executeEventSubscribersExecutor = ThreadUtils
    +      .newDaemonCachedThreadPool("kubernetes-executor-pods-event-handlers")
    +    val eventQueue = new ExecutorPodsEventQueueImpl(
    +      bufferEventsExecutor, executeEventSubscribersExecutor)
    --- End diff --
    
    I don't think it's worth it. I'm fine shutting them down inside the subcomponents as long as the contract that each thread-pool is only used by a single owning component holds.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3719/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91319 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91319/testReport)** for PR 21366 at commit [`260d82c`](https://github.com/apache/spark/commit/260d82ca9fbbd16ad8174d0dafa2f95bc177a219).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3444/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91123 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91123/testReport)** for PR 21366 at commit [`5850439`](https://github.com/apache/spark/commit/5850439652fad6bb2b03daf4e35497304c8defdd).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3580/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195351851
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsSnapshotsStoreImpl.scala ---
    @@ -0,0 +1,88 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent._
    +
    +import io.fabric8.kubernetes.api.model.Pod
    +import javax.annotation.concurrent.GuardedBy
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.util.{ThreadUtils, Utils}
    +
    +private[spark] class ExecutorPodsSnapshotsStoreImpl(subscribersExecutor: ScheduledExecutorService)
    --- End diff --
    
    Could you add a description of the class here.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190769478
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingEventSource.scala ---
    @@ -0,0 +1,58 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.deploy.k8s.Constants._
    +
    +private[spark] class ExecutorPodsPollingEventSource(
    +    kubernetesClient: KubernetesClient,
    +    eventHandler: ExecutorPodsEventHandler,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private var pollingFuture: Future[_] = null
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), 0L, 30L, TimeUnit.SECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (pollingFuture != null) {
    +      pollingFuture.cancel(true)
    +      pollingFuture = null
    --- End diff --
    
    Done, see below.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r189735073
  
    --- Diff: pom.xml ---
    @@ -150,6 +150,7 @@
         <!--  org.apache.httpcomponents/httpclient-->
         <commons.httpclient.version>4.5.4</commons.httpclient.version>
         <commons.httpcore.version>4.4.8</commons.httpcore.version>
    +    <trove.version>3.0.1</trove.version>
    --- End diff --
    
    My take is that the performance is probably not worth the additional dependency.
    I also noticed that the trove dep is LGPL, which is considered incompatible with Apache license. Although I believe this is not a show-stopper with respect to "containerized" dependencies, it probably is for a direct dependency in the code.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test starting
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3723/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191871593
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala ---
    @@ -0,0 +1,120 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +
    +private[spark] class ExecutorPodsAllocator(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventQueue: ExecutorPodsEventQueue) extends Logging {
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    +
    +  // Executor IDs that have been requested from Kubernetes but are not running yet.
    +  private val pendingExecutors = mutable.Set.empty[Long]
    +
    +  // We could use CoarseGrainedSchedulerBackend#totalRegisteredExecutors here for tallying the
    +  // executors that are running. But, here we choose instead to maintain all state within this
    +  // class from the persecptive of the k8s API. Therefore whether or not this scheduler loop
    +  // believes an executor is running is dictated by the K8s API rather than Spark's RPC events.
    +  // We may need to consider where these perspectives may differ and which perspective should
    +  // take precedence.
    +  private val runningExecutors = mutable.Set.empty[Long]
    +
    +  def start(applicationId: String): Unit = {
    +    eventQueue.addSubscriber(podAllocationDelay) { updatedPods =>
    +      processUpdatedPodEvents(applicationId, updatedPods)
    +    }
    +  }
    +
    +  def setTotalExpectedExecutors(total: Int): Unit = totalExpectedExecutors.set(total)
    +
    +  private def processUpdatedPodEvents(applicationId: String, updatedPods: Seq[Pod]): Unit = {
    --- End diff --
    
    We're actually processing pods here right? Not the events themselves from the watch. 


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195549746
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingSnapshotSource.scala ---
    @@ -0,0 +1,65 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.util.ThreadUtils
    +
    +private[spark] class ExecutorPodsPollingSnapshotSource(
    +    conf: SparkConf,
    +    kubernetesClient: KubernetesClient,
    +    snapshotsStore: ExecutorPodsSnapshotsStore,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private val pollingInterval = conf.get(KUBERNETES_EXECUTOR_API_POLLING_INTERVAL)
    +
    +  private var pollingFuture: Future[_] = _
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), pollingInterval, pollingInterval, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (pollingFuture != null) {
    +      pollingFuture.cancel(true)
    +      pollingFuture = null
    +    }
    +    ThreadUtils.shutdown(pollingExecutor)
    +  }
    +
    +  private class PollRunnable(applicationId: String) extends Runnable {
    +    override def run(): Unit = {
    +      snapshotsStore.replaceSnapshot(kubernetesClient
    --- End diff --
    
    Also you can do it at doRequestTotalExecutors right? When do you have the information of how many you need?


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191918908
  
    --- Diff: pom.xml ---
    @@ -760,6 +760,12 @@
             <version>1.10.19</version>
             <scope>test</scope>
           </dependency>
    +      <dependency>
    --- End diff --
    
    I don't think this should cause rxjava to be pulled in from spark core. But the library will be put into the Spark distribution, and anyone depending on both Kubernetes integration and RxJava will have to resolve potential conflicts.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r190967170
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingEventSource.scala ---
    @@ -0,0 +1,65 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +
    +private[spark] class ExecutorPodsPollingEventSource(
    +    conf: SparkConf,
    +    kubernetesClient: KubernetesClient,
    +    eventQueue: ExecutorPodsEventQueue,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private val pollingInterval = conf.get(KUBERNETES_EXECUTOR_API_POLLING_INTERVAL)
    +
    +  private var pollingFuture: Future[_] = _
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), pollingInterval, pollingInterval, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (pollingFuture != null) {
    +      pollingFuture.cancel(true)
    +      pollingFuture = null
    +    }
    +    pollingExecutor.shutdown()
    --- End diff --
    
    And also since Spark depends on Guava 14.0.1 we don't have that method.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190356761
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingEventSource.scala ---
    @@ -0,0 +1,58 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.deploy.k8s.Constants._
    +
    +private[spark] class ExecutorPodsPollingEventSource(
    +    kubernetesClient: KubernetesClient,
    +    eventHandler: ExecutorPodsEventHandler,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private var pollingFuture: Future[_] = null
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), 0L, 30L, TimeUnit.SECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (pollingFuture != null) {
    +      pollingFuture.cancel(true)
    +      pollingFuture = null
    --- End diff --
    
    Ditto. the `pollingExecutor` should be shutdown properly.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91866 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91866/testReport)** for PR 21366 at commit [`1a99dce`](https://github.com/apache/spark/commit/1a99dceeb9dfbfc58e26885c290461cbf37a5428).


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r189642632
  
    --- Diff: pom.xml ---
    @@ -150,6 +150,7 @@
         <!--  org.apache.httpcomponents/httpclient-->
         <commons.httpclient.version>4.5.4</commons.httpclient.version>
         <commons.httpcore.version>4.4.8</commons.httpcore.version>
    +    <trove.version>3.0.1</trove.version>
    --- End diff --
    
    These are data structures optimized for storing primitives. We could use standard Scala here functionally speaking.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r194840955
  
    --- Diff: pom.xml ---
    @@ -760,6 +760,12 @@
             <version>1.10.19</version>
             <scope>test</scope>
           </dependency>
    +      <dependency>
    --- End diff --
    
    These types are not exposed - they're only implementation details in the Kubernetes module. Furthermore the RxJava dependency will be in the Spark distribution but is not a dependency pulled in by spark-core.
    
    It sounds like there is some contention with the extra dependency though, so should we be considering implementing our own mechanisms from the ground up? I think the bottom line question is: can spark-kubernetes, NOT spark-core, pull in RxJava?


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3898/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3326/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #90820 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/90820/testReport)** for PR 21366 at commit [`600e25f`](https://github.com/apache/spark/commit/600e25f0ca70eddd5407d76c1210b9b637eeae77).


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use level triggering and state...

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

    https://github.com/apache/spark/pull/21366#discussion_r195380019
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsLifecycleManager.scala ---
    @@ -0,0 +1,164 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import com.google.common.cache.Cache
    +import io.fabric8.kubernetes.api.model.Pod
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsLifecycleManager(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    snapshotsStore: ExecutorPodsSnapshotsStore,
    +    // Use a best-effort to track which executors have been removed already. It's not generally
    +    // job-breaking if we remove executors more than once but it's ideal if we make an attempt
    +    // to avoid doing so. Expire cache entries so that this data structure doesn't grow beyond
    +    // bounds.
    +    removedExecutorsCache: Cache[java.lang.Long, java.lang.Long]) {
    +
    +  import ExecutorPodsLifecycleManager._
    +
    +  private val eventProcessingInterval = conf.get(KUBERNETES_EXECUTOR_EVENT_PROCESSING_INTERVAL)
    +
    +  def start(schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    snapshotsStore.addSubscriber(eventProcessingInterval) {
    +      onNewSnapshots(schedulerBackend, _)
    +    }
    +  }
    +
    +  private def onNewSnapshots(
    +      schedulerBackend: KubernetesClusterSchedulerBackend,
    +      snapshots: Seq[ExecutorPodsSnapshot]): Unit = {
    +    val execIdsRemovedInThisRound = mutable.HashSet.empty[Long]
    +    snapshots.foreach { snapshot =>
    +      snapshot.executorPods.foreach { case (execId, state) =>
    +        state match {
    +          case deleted@PodDeleted(pod) =>
    +            removeExecutorFromSpark(schedulerBackend, deleted, execId)
    +            execIdsRemovedInThisRound += execId
    +          case failed@PodFailed(pod) =>
    +            onFinalNonDeletedState(failed, execId, schedulerBackend, execIdsRemovedInThisRound)
    +          case succeeded@PodSucceeded(pod) =>
    --- End diff --
    
    same as above.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use level triggering and state reconc...

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

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


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190356590
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsPollingEventSource.scala ---
    @@ -0,0 +1,58 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, ScheduledExecutorService, TimeUnit}
    +
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +
    +import org.apache.spark.deploy.k8s.Constants._
    +
    +private[spark] class ExecutorPodsPollingEventSource(
    +    kubernetesClient: KubernetesClient,
    +    eventHandler: ExecutorPodsEventHandler,
    +    pollingExecutor: ScheduledExecutorService) {
    +
    +  private var pollingFuture: Future[_] = _
    +
    +  def start(applicationId: String): Unit = {
    +    require(pollingFuture == null, "Cannot start polling more than once.")
    +    pollingFuture = pollingExecutor.scheduleWithFixedDelay(
    +      new PollRunnable(applicationId), 0L, 30L, TimeUnit.SECONDS)
    --- End diff --
    
    Agreed.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    Kubernetes integration test status success
    URL: https://amplab.cs.berkeley.edu/jenkins/job/testing-k8s-prb-spark-integration/3468/



---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

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


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S] Use the Kubernetes API to populate an...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #91134 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/91134/testReport)** for PR 21366 at commit [`45a02de`](https://github.com/apache/spark/commit/45a02de19a07217084caaa0a5d87b424e1b79d2e).


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S] Use the Kubernetes API to popu...

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

    https://github.com/apache/spark/pull/21366#discussion_r191865834
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala ---
    @@ -0,0 +1,120 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +
    +private[spark] class ExecutorPodsAllocator(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventQueue: ExecutorPodsEventQueue) extends Logging {
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    --- End diff --
    
    nit: hanging comment? 


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r189435162
  
    --- Diff: pom.xml ---
    @@ -150,6 +150,7 @@
         <!--  org.apache.httpcomponents/httpclient-->
         <commons.httpclient.version>4.5.4</commons.httpclient.version>
         <commons.httpcore.version>4.4.8</commons.httpcore.version>
    +    <trove.version>3.0.1</trove.version>
    --- End diff --
    
    it looks like this dep is being taken on for a couple data structures: are these important or could they be replaced with scala Array and HashMap?


---

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


[GitHub] spark pull request #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to...

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

    https://github.com/apache/spark/pull/21366#discussion_r190389782
  
    --- Diff: resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsEventHandler.scala ---
    @@ -0,0 +1,229 @@
    +/*
    + * 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.scheduler.cluster.k8s
    +
    +import java.util.concurrent.{Future, LinkedBlockingQueue, ScheduledExecutorService, TimeUnit}
    +import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
    +
    +import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
    +import io.fabric8.kubernetes.client.KubernetesClient
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +import org.apache.spark.{SparkConf, SparkException}
    +import org.apache.spark.deploy.k8s.Config._
    +import org.apache.spark.deploy.k8s.Constants._
    +import org.apache.spark.deploy.k8s.KubernetesConf
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.scheduler.ExecutorExited
    +import org.apache.spark.util.Utils
    +
    +private[spark] class ExecutorPodsEventHandler(
    +    conf: SparkConf,
    +    executorBuilder: KubernetesExecutorBuilder,
    +    kubernetesClient: KubernetesClient,
    +    eventProcessorExecutor: ScheduledExecutorService) extends Logging {
    +
    +  import ExecutorPodsEventHandler._
    +
    +  private val EXECUTOR_ID_COUNTER = new AtomicLong(0L)
    +
    +  private val totalExpectedExecutors = new AtomicInteger(0)
    +
    +  private val eventQueue = new LinkedBlockingQueue[Seq[Pod]]()
    +
    +  private val podAllocationSize = conf.get(KUBERNETES_ALLOCATION_BATCH_SIZE)
    +
    +  private val podAllocationDelay = conf.get(KUBERNETES_ALLOCATION_BATCH_DELAY)
    +
    +  private val kubernetesDriverPodName = conf
    +    .get(KUBERNETES_DRIVER_POD_NAME)
    +    .getOrElse(throw new SparkException("Must specify the driver pod name"))
    +
    +  private val driverPod = kubernetesClient.pods()
    +    .withName(kubernetesDriverPodName)
    +    .get()
    +
    +  // Use sets of ids instead of counters to be able to handle duplicate events.
    +
    +  // Executor IDs that have been requested from Kubernetes but are not running yet.
    +  private val pendingExecutors = mutable.Set.empty[Long]
    +
    +  // We could use CoarseGrainedSchedulerBackend#totalRegisteredExecutors here for tallying the
    +  // executors that are running. But, here we choose instead to maintain all state within this
    +  // class from the persecptive of the k8s API. Therefore whether or not this scheduler loop
    +  // believes an executor is running is dictated by the K8s API rather than Spark's RPC events.
    +  // We may need to consider where these perspectives may differ and which perspective should
    +  // take precedence.
    +  private val runningExecutors = mutable.Set.empty[Long]
    +
    +  private var eventProcessorFuture: Future[_] = _
    +
    +  def start(applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend): Unit = {
    +    require(eventProcessorFuture == null, "Cannot start event processing twice.")
    +    logInfo(s"Starting Kubernetes executor pods event handler for application with" +
    +      s" id $applicationId.")
    +    val eventProcessor = new Runnable {
    +      override def run(): Unit = {
    +        Utils.tryLogNonFatalError {
    +          processEvents(applicationId, schedulerBackend)
    +        }
    +      }
    +    }
    +    eventProcessorFuture = eventProcessorExecutor.scheduleWithFixedDelay(
    +      eventProcessor, 0L, podAllocationDelay, TimeUnit.MILLISECONDS)
    +  }
    +
    +  def stop(): Unit = {
    +    if (eventProcessorFuture != null) {
    +      eventProcessorFuture.cancel(true)
    +      eventProcessorFuture = null
    +    }
    +  }
    +
    +  private def processEvents(
    +      applicationId: String, schedulerBackend: KubernetesClusterSchedulerBackend) {
    +    val currentEvents = new java.util.ArrayList[Seq[Pod]](eventQueue.size())
    +    eventQueue.drainTo(currentEvents)
    +    currentEvents.asScala.flatten.foreach { updatedPod =>
    +      val execId = updatedPod.getMetadata.getLabels.get(SPARK_EXECUTOR_ID_LABEL).toLong
    +      val podPhase = updatedPod.getStatus.getPhase.toLowerCase
    +      if (isDeleted(updatedPod)) {
    +        removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +      } else {
    +        updatedPod.getStatus.getPhase.toLowerCase match {
    +          case "running" =>
    +            // If clause is for resililence to out of order operations - executor must be
    +            // pending and first reach running. Without this check you may e.g. process a
    +            // deletion event followed by some arbitrary modification event - we want the
    +            // deletion event to "stick".
    +            if (pendingExecutors.contains(execId)) {
    +              pendingExecutors.remove(execId)
    +              runningExecutors.add(execId)
    +            }
    +          // TODO (SPARK-24135) - handle more classes of errors
    +          case "error" | "failed" | "succeeded" =>
    +            // If deletion failed on a previous try, we can try again if resync informs us the pod
    +            // is still around.
    +            // Delete as best attempt - duplicate deletes will throw an exception but the end state
    +            // of getting rid of the pod is what matters.
    +            if (!isDeleted(updatedPod)) {
    +              Utils.tryLogNonFatalError {
    +                kubernetesClient
    +                  .pods()
    +                  .withName(updatedPod.getMetadata.getName)
    +                  .delete()
    +              }
    +            }
    +            removeExecutorFromSpark(schedulerBackend, updatedPod, execId)
    +        }
    +      }
    +    }
    +
    +    val currentRunningExecutors = runningExecutors.size
    --- End diff --
    
    Had another idea - you can denormalize the state, meaning each event processor module maintains its own copy of the perceived state. We get the modularization and separate scheduling, without having to worry about thread safety. The amount of state being duplicated is quite small. I'll propose the idea and would appreciate feedback once it's in.


---

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


[GitHub] spark issue #21366: [SPARK-24248][K8S][WIP] Use the Kubernetes API to popula...

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

    https://github.com/apache/spark/pull/21366
  
    **[Test build #90820 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/90820/testReport)** for PR 21366 at commit [`600e25f`](https://github.com/apache/spark/commit/600e25f0ca70eddd5407d76c1210b9b637eeae77).
     * This patch **fails to build**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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