wangyang0918 commented on code in PR #216:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/216#discussion_r874335119


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/observer/SavepointObserver.java:
##########
@@ -131,15 +135,63 @@ private Optional<String> 
observeTriggeredSavepointProgress(
 
         LOG.info("Savepoint status updated with latest completed savepoint 
info");
         
currentSavepointInfo.updateLastSavepoint(savepointFetchResult.getSavepoint());
+        updateSavepointHistory(
+                currentSavepointInfo, savepointFetchResult.getSavepoint(), 
deployedConfig, true);
         return Optional.empty();
     }
 
+    @VisibleForTesting
+    void updateSavepointHistory(
+            SavepointInfo currentSavepointInfo,
+            Savepoint newSavepoint,
+            Configuration deployedConfig,
+            boolean cleanup) {
+
+        currentSavepointInfo.addSavepointToHistory(newSavepoint);
+        if (!cleanup) {
+            return;
+        }
+
+        // maintain history
+        List<Savepoint> savepointHistory = 
currentSavepointInfo.getSavepointHistory();
+        int maxCount = 
configManager.getOperatorConfiguration().getSavepointHistoryMaxCount();
+        while (savepointHistory.size() > maxCount) {
+            // remove oldest entries
+            disposeSavepointQuietly(savepointHistory.remove(0), 
deployedConfig);
+        }
+
+        Duration maxAge = 
configManager.getOperatorConfiguration().getSavepointHistoryMaxAge();
+        long maxTms = System.currentTimeMillis() - maxAge.toMillis();
+        Iterator<Savepoint> it = savepointHistory.iterator();
+        while (it.hasNext()) {
+            Savepoint sp = it.next();
+            if (sp.getTimeStamp() < maxTms && sp != newSavepoint) {
+                it.remove();
+                disposeSavepointQuietly(sp, deployedConfig);
+            }
+        }
+    }
+
+    private void disposeSavepointQuietly(Savepoint sp, Configuration conf) {
+        try {
+            LOG.info("Disposing savepoint {}", sp);
+            flinkService.disposeSavepoint(sp.getLocation(), conf);
+        } catch (Exception e) {
+            // savepoint dispose error should nota affect the deployment

Review Comment:
   typo: nota?



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