jerryshao commented on code in PR #14230:
URL: https://github.com/apache/gravitino/pull/14230#discussion_r4384410209


##########
plugins/k8s-job-executor/src/main/java/org/apache/gravitino/job/k8s/K8sJobExecutor.java:
##########
@@ -557,6 +592,59 @@ private Optional<GenericKubernetesResource> 
updateSparkApplication(
     }
   }
 
+  /**
+   * Deletes the SparkApplication of a job if it should be, only if it hasn't 
changed since it was
+   * read, and reads it again to decide again otherwise.
+   *
+   * @param id the job execution id
+   * @param shouldDelete tells whether to delete the SparkApplication
+   * @return the SparkApplication the deletion was decided on, or empty if it 
doesn't exist, also if
+   *     it was gone by the time it was deleted
+   */
+  private Optional<GenericKubernetesResource> deleteSparkApplicationIf(
+      K8sJobExecutionId id, Predicate<GenericKubernetesResource> shouldDelete) 
{
+    for (int attempt = 0; ; attempt++) {
+      Optional<GenericKubernetesResource> app = getSparkApplication(id);
+      if (!app.isPresent() || !shouldDelete.test(app.get())) {
+        return app;
+      }
+      try {
+        // fabric8 reports that nothing was deleted, rather than failing, for 
a SparkApplication
+        // that is gone, for example deleted by a cancellation on another 
server meanwhile.
+        boolean deleted = !lockSparkApplication(app.get()).delete().isEmpty();

Review Comment:
   No wait is needed. A 409 here means the SparkApplication changed after it 
was read, not that the API server is busy, so each retry re-reads it and 
decides again with the latest `resourceVersion`; waiting wouldn't make the next 
attempt more likely to succeed. The usual writer is the operator updating the 
status: on the no-status path the re-read then sees a status and stops 
deleting, and the failed-submit cleanup deletes the new version. If the 3 
retries still run out, the no-status path fails the status query and the next 
poll tries again, and the failed-submit cleanup logs a WARN with the command to 
delete it by hand. This matches `updateSparkApplication`, which also re-reads 
right away on a 409.
   
   _🤖 Generated with [Claude Code](https://claude.com/claude-code)_



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