dongjoon-hyun commented on code in PR #711:
URL: 
https://github.com/apache/spark-kubernetes-operator/pull/711#discussion_r3430347708


##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppInitStep.java:
##########
@@ -66,17 +70,30 @@ public ReconcileProgress reconcile(
     if (app.getStatus().getPreviousAttemptSummary() != null) {
       Instant lastTransitionTime = 
Instant.parse(currentState.getLastTransitionTime());
       ApplicationAttemptSummary attemptSummary = 
app.getStatus().getPreviousAttemptSummary();
-      ApplicationState lastState = attemptSummary.getStateTransitionHistory()
-          .get(attemptSummary.getStateTransitionHistory().lastKey());
-      Instant restartTime =
-          lastTransitionTime.plusMillis(
-              app.getSpec()
-                  .getApplicationTolerations()
-                  .getRestartConfig()
-                  
.getEffectiveRestartBackoffMillis(lastState.getCurrentStateSummary()));
-      Instant now = Instant.now();
-      if (restartTime.isAfter(now)) {
-        return ReconcileProgress.completeAndRequeueAfter(Duration.between(now, 
restartTime));
+      SortedMap<Long, ApplicationState> attemptHistory = 
attemptSummary.getStateTransitionHistory();
+      final ApplicationState lastState;
+      if (attemptHistory != null && !attemptHistory.isEmpty()) {
+        lastState = attemptHistory.get(attemptHistory.lastKey());
+      } else {
+        // Non-trim mode: previousAttemptSummary carries null 
stateTransitionHistory.
+        // Fall back to the main history and pick the state entered just 
before the current
+        // initializing state (which is the stopping state that triggered the 
restart).
+        NavigableMap<Long, ApplicationState> mainNav =
+            (NavigableMap<Long, ApplicationState>) 
app.getStatus().getStateTransitionHistory();
+        Map.Entry<Long, ApplicationState> prevEntry = 
mainNav.lowerEntry(mainNav.lastKey());
+        lastState = prevEntry != null ? prevEntry.getValue() : 
mainNav.lastEntry().getValue();
+      }
+      RestartConfig restartConfig =
+          app.getSpec().getApplicationTolerations().getRestartConfig();
+      if (restartConfig != null) {

Review Comment:
   May I ask when `restartConfig == null` here? 
   
   If it doesn't happen in the context, can we simply do some assertion 
statement for this condition instead of `if (restartConfig != null)`



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

Reply via email to