github-actions[bot] commented on code in PR #41627:
URL: https://github.com/apache/beam/pull/41627#discussion_r4700046487


##########
sdks/python/apache_beam/runners/dataflow/internal/apiclient.py:
##########
@@ -956,9 +966,35 @@ def modify_job_state(self, job_id, new_state) -> bool:
     request.job_id = job_id
     request.project_id = self.google_cloud_options.project
     request.location = self.google_cloud_options.region
-    request.job = dataflow.Job(requested_state=new_state)
+    request.job = dataflow.Job(requested_state=requested_state)
+
+    def _should_retry(exception):
+      if retry.retry_on_server_errors_filter(exception):
+        return True
+      if (requested_state == dataflow.JobState.JOB_STATE_CANCELLED and
+          isinstance(exception, exceptions.FailedPrecondition)):
+        try:
+          current_state = self.get_job(job_id).current_state
+        except Exception as get_job_exn:  # pylint: disable=broad-except
+          _LOGGER.warning(
+              'Unable to fetch job %s state after FailedPrecondition on '
+              'cancel; will not retry: %s',
+              job_id,
+              get_job_exn)
+          return False
+        return current_state not in _NON_RETRYABLE_CANCEL_STATES

Review Comment:
   **🔵 Info**: If `update_job` raises `FailedPrecondition` because the job 
concurrently transitioned to `JOB_STATE_CANCELLED` or `JOB_STATE_CANCELLING` 
(for example, between `DataflowPipelineResult.cancel()`'s initial 
`_update_job()` check and the `modify_job_state` RPC, or between retry 
attempts), returning `False` from `_should_retry` will re-raise 
`FailedPrecondition` to callers of `cancel()` even though the job is already 
cancelled/cancelling. Consider whether `modify_job_state` should treat 
`current_state in (JOB_STATE_CANCELLED, JOB_STATE_CANCELLING)` as a successful 
no-op (or handle it in `_update_job`) rather than raising.



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

Reply via email to