kaxil commented on code in PR #67118:
URL: https://github.com/apache/airflow/pull/67118#discussion_r3270205715
##########
providers/apache/spark/src/airflow/providers/apache/spark/hooks/spark_submit.py:
##########
@@ -626,28 +626,15 @@ def submit(self, application: str = "", **kwargs: Any) ->
None:
f"Cannot execute: {self._mask_cmd(spark_submit_cmd)}.
Error code is: {returncode}."
)
- self.log.debug("Should track driver: %s",
self._should_track_driver_status)
-
- # We want the Airflow job to wait until the Spark driver is
finished
- if self._should_track_driver_status:
- if self._driver_id is None:
- raise AirflowException(
- "No driver id is known: something went wrong when
executing the spark submit command"
- )
-
- # We start with the SUBMITTED status as initial status
- self._driver_status = "SUBMITTED"
-
- # Start tracking the driver status (blocking function)
- self._start_driver_status_tracking()
-
- if self._driver_status != "FINISHED":
- raise AirflowException(
- f"ERROR : Driver {self._driver_id} badly exited with
status {self._driver_status}"
- )
+ if self._should_track_driver_status and self._driver_id is None:
+ raise AirflowException(
+ "No driver id is known: something went wrong when
executing the spark submit command"
+ )
finally:
self._run_post_submit_commands()
Review Comment:
`finally: self._run_post_submit_commands()` now runs immediately after the
spark-submit subprocess exits -- which in cluster mode is right after the
submit returns the driver ID, before driver-status polling (now moved out to
the operator's `poll_until_complete`).
The `post_submit_commands` docstring says "Run after the Spark job finishes.
Useful for cleaning up sidecars such as Istio." That contract is now broken for
cluster mode: a user with `post_submit_commands=["curl -X POST
localhost:15020/quitquitquit"]` will kill the Istio sidecar before the operator
starts polling, and the subsequent `_start_driver_status_tracking` calls (which
need network) will fail.
Either move the post-submit call so it runs after `poll_until_complete`
returns in the operator, or document the timing change explicitly in the param
doc.
##########
providers/apache/spark/src/airflow/providers/apache/spark/operators/spark_submit.py:
##########
@@ -198,8 +221,63 @@ def execute(self, context: Context) -> None:
self.conf =
inject_transport_information_into_spark_properties(self.conf, context)
if self._hook is None:
self._hook = self._get_hook()
+ if self._hook._should_track_driver_status:
+ return self.execute_resumable(context)
self._hook.submit(self.application)
+ def submit_job(self, context: Context) -> str:
+ driver_id = self._hook.submit(self.application)
+ if not driver_id:
+ raise RuntimeError("spark-submit did not return a driver ID")
+ self.log.info("Spark driver submitted: %s", driver_id)
+ return driver_id
+
+ def get_job_status(self, external_id: str) -> str:
+ if self._hook._is_yarn:
+ # TODO: call YARN ResourceManager REST API
+ # GET http://rm:8088/ws/v1/cluster/apps/{external_id}
+ raise NotImplementedError("YARN job status not yet implemented")
+ if self._hook._is_kubernetes:
+ # TODO: call K8s pod status API
+ raise NotImplementedError("K8s job status not yet implemented")
+ host = self._hook._connection["master"].replace("spark://",
"").split(":")[0]
Review Comment:
HA Spark Standalone clusters are configured as
`spark://m1:7077,m2:7077,m3:7077`. After `.replace("spark://",
"").split(":")[0]` this becomes `m1` -- the host most likely to be unreachable
during the very HA failover this operator is supposed to survive.
Suggest iterating the comma-separated masters and trying each until one
responds (matching how the spark client itself handles HA masters).
##########
task-sdk/src/airflow/sdk/bases/resumablemixin.py:
##########
@@ -0,0 +1,135 @@
+# 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.
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Any
+
+import structlog
+
+if TYPE_CHECKING:
+ from airflow.sdk.definitions.context import Context
+
+log = structlog.get_logger(__name__)
Review Comment:
Module-level `structlog.get_logger(__name__)` won't route to the per-TI task
log. Convention in the SDK is either `structlog.get_logger("task")` (see
`bases/xcom.py`, `task_runner.py`) or `self.log` (see `SkipMixin`).
The decision points logged here -- "Reconnecting to existing job", "already
completed", "resubmitting fresh" -- are exactly what a user debugging a retry
needs to see in the task UI, and right now they'll be invisible there.
Since `ResumableJobMixin` is intended to be combined with a `BaseOperator`,
suggest dropping the module-level `log` and using `self.log` in
`execute_resumable`.
--
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]