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


##########
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:
   Do we need to wait for some time between the next deletion?



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