ForVic commented on code in PR #58489:
URL: https://github.com/apache/spark/pull/58489#discussion_r4050226897
##########
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala:
##########
@@ -706,6 +705,42 @@ private[spark] object Config extends Logging {
.booleanConf
.createWithDefault(false)
+ val KUBERNETES_EXECUTOR_ENABLE_INFORMER =
+ ConfigBuilder("spark.kubernetes.executor.enableInformer")
+ .doc("If true, use a shared Kubernetes informer (list + watch) to track
executor pod " +
+ "state, driven by ExecutorPodsInformerSnapshotSource (event-driven)
and " +
+ "ExecutorPodsListerSnapshotSource (periodic refresh of the informer
cache). If " +
Review Comment:
“Periodic refresh of the informer cache” is a little wrong. The lister reads
that cache and refreshes Spark’s snapshot store.
##########
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsListerSnapshotSource.scala:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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 scala.jdk.CollectionConverters._
+
+import io.fabric8.kubernetes.api.model.Pod
+import io.fabric8.kubernetes.client.KubernetesClient
+import io.fabric8.kubernetes.client.informers.cache.Lister
+
+import org.apache.spark.SparkConf
+import
org.apache.spark.deploy.k8s.Config.KUBERNETES_EXECUTOR_LISTER_POLLING_INTERVAL
+import org.apache.spark.internal.Logging
+import org.apache.spark.util.{ThreadUtils, Utils}
+
+/**
+ * Periodically snapshots the local cache of the shared [[InformerManager]]
and replaces the
+ * contents of the [[ExecutorPodsSnapshotsStore]] with the result. Companion to
+ * [[ExecutorPodsInformerSnapshotSource]], which pushes updates as informer
events arrive.
+ */
+private[spark] class ExecutorPodsListerSnapshotSource(
+ conf: SparkConf,
+ kubernetesClient: KubernetesClient,
+ snapshotsStore: ExecutorPodsSnapshotsStore,
+ informerManager: InformerManager,
+ pollingExecutor: ScheduledExecutorService)
+ extends ExecutorPodsSnapshotSource with Logging {
+
+ private val pollingInterval =
conf.get(KUBERNETES_EXECUTOR_LISTER_POLLING_INTERVAL)
+
+ private var pollingFuture: Future[_] = _
+
+ override def start(applicationId: String): Unit = {
+ require(pollingFuture == null, "Cannot start lister polling more than
once.")
+ informerManager.initInformer(applicationId)
+ informerManager.startInformer()
+ val lister = new Lister[Pod](
+ informerManager.getInformer().getIndexer, kubernetesClient.getNamespace)
+ pollingFuture = pollingExecutor.scheduleWithFixedDelay(
+ new PollRunnable(lister), pollingInterval, pollingInterval,
TimeUnit.MILLISECONDS)
+ }
+
+ override def stop(): Unit = {
+ if (pollingFuture != null) {
+ pollingFuture.cancel(true)
+ pollingFuture = null
+ }
+ Utils.tryLogNonFatalError {
+ informerManager.stopInformer()
+ }
+ ThreadUtils.shutdown(pollingExecutor)
+ }
+
+ private class PollRunnable(lister: Lister[Pod]) extends Runnable {
+ override def run(): Unit = Utils.tryLogNonFatalError {
+ // Skip the round if the informer has not completed its initial LIST
yet. Otherwise the
+ // empty local cache would be handed to replaceSnapshot() and wipe every
known executor
+ // from the snapshot store. Combined with InformerManager's force-retry
exceptionHandler,
+ // a never-synced informer will keep retrying until sync completes
rather than leaving
+ // polls skipped forever.
+ if (informerManager.getInformer().hasSynced) {
Review Comment:
fabric8 `hasSynced` just means that the informer has synced at some point in
the past ([see
impl](https://github.com/fabric8io/kubernetes-client/blob/v7.9.0/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/informers/SharedIndexInformer.java))
so it stays true after the first sync even if watch disconnected there's
some space for Spark's state to drift from reality.
##########
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/InformerManager.scala:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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 io.fabric8.kubernetes.client.KubernetesClient
+import io.fabric8.kubernetes.client.informers.SharedIndexInformer
+
+import org.apache.spark.SparkConf
+import
org.apache.spark.deploy.k8s.Config.KUBERNETES_EXECUTOR_INFORMER_RESYNC_INTERVAL
+import org.apache.spark.deploy.k8s.Constants.{SPARK_APP_ID_LABEL,
SPARK_EXECUTOR_INACTIVE_LABEL, SPARK_POD_EXECUTOR_ROLE, SPARK_ROLE_LABEL}
+import org.apache.spark.internal.Logging
+import org.apache.spark.util.Utils
+
+/**
+ * Owns the shared [[SharedIndexInformer]] used by executor pod snapshot
sources when the
+ * informer-based mode is enabled. The informer is scoped server-side to the
current
+ * application's executor pods that are not marked inactive, matching the
filter set used by
+ * [[ExecutorPodsWatchSnapshotSource]] and
[[ExecutorPodsPollingSnapshotSource]].
+ *
+ * The informer is configured with an
[[io.fabric8.kubernetes.client.informers.ExceptionHandler]]
+ * that forces retries so transient errors self-heal instead of leaving
executor pod state
+ * silently frozen.
+ */
+private[spark] class InformerManager(kubernetesClient: KubernetesClient, conf:
SparkConf)
+ extends Logging {
+
+ private val resyncInterval =
conf.get(KUBERNETES_EXECUTOR_INFORMER_RESYNC_INTERVAL)
Review Comment:
The original resync option supported informer-only/custom-source setups when
I added it in https://github.com/apache/spark/pull/51396 (which I'm pretty sure
this is mostly inspired from). This version always includes the lister and
drops unchanged-version updates, so resync appears to have no remaining
purpose. Can we remove the setting and keep it disabled internally now?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]