1996fanrui commented on code in PR #707:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/707#discussion_r1390586714


##########
flink-autoscaler/src/main/java/org/apache/flink/autoscaler/JobAutoScalerImpl.java:
##########
@@ -115,10 +123,39 @@ public void cleanup(KEY jobKey) {
         stateStore.removeInfoFromCache(jobKey);
     }
 
-    private void clearParallelismOverrides(Context ctx) throws Exception {
-        var parallelismOverrides = stateStore.getParallelismOverrides(ctx);
-        if (parallelismOverrides.isPresent()) {
+    private void clearStatesAfterAutoscalerDisabled(Context ctx) throws 
Exception {
+        var needFlush = false;
+        var parallelismOverridesOpt = stateStore.getParallelismOverrides(ctx);
+        if (parallelismOverridesOpt.isPresent()) {
+            needFlush = true;
             stateStore.removeParallelismOverrides(ctx);
+        }
+
+        Optional<SortedMap<Instant, CollectedMetrics>> collectedMetricsOpt =
+                stateStore.getCollectedMetrics(ctx);
+        if (collectedMetricsOpt.isPresent()) {
+            needFlush = true;
+            stateStore.removeCollectedMetrics(ctx);
+        }
+
+        Optional<Map<JobVertexID, SortedMap<Instant, ScalingSummary>>> 
scalingHistoryOpt =
+                stateStore.getScalingHistory(ctx);
+        if (scalingHistoryOpt.isPresent()) {
+            Map<JobVertexID, SortedMap<Instant, ScalingSummary>> 
scalingHistory =
+                    trimScalingHistory(
+                            clock.instant(), ctx.getConfiguration(), 
scalingHistoryOpt.get());
+            if (scalingHistory.isEmpty()) {
+                // All scaling histories are trimmed.
+                needFlush = true;
+                stateStore.removeScalingHistory(ctx);
+            } else if (!scalingHistoryOpt.get().equals(scalingHistory)) {
+                // Some scaling histories are trimmed.
+                needFlush = true;
+                stateStore.storeScalingHistory(ctx, scalingHistory);
+            }
+        }

Review Comment:
   Trimming logic will consider `VERTEX_SCALING_HISTORY_AGE` option, and the 
default value is `24 hours`.
   
   My thought is: if users enable autoscaler within 24 hours, the 
`ScalingHistory` can be used for subsequent scaling. WDYT?



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