1996fanrui commented on code in PR #2268:
URL: 
https://github.com/apache/incubator-streampark/pull/2268#discussion_r1104521381


##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/CheckpointProcessor.java:
##########
@@ -52,30 +62,31 @@ public class CheckpointProcessor {
 
   @Autowired private SavePointService savePointService;
 
-  public void process(Long appId, CheckPoints checkPoints) {
-    CheckPoints.Latest latest = checkPoints.getLatest();
-    if (latest == null || latest.getCompleted() == null) {
-      return;
-    }
-    CheckPoints.CheckPoint checkPoint = latest.getCompleted();
+  public void process(Long appId, @Nonnull CheckPoints checkPoints) {
+    checkPoints.getLatestCheckpoint().forEach(checkPoint -> process(appId, 
checkPoint));
+  }
+
+  private void process(Long appId, @Nonnull CheckPoints.CheckPoint checkPoint) 
{
     Application application = applicationService.getById(appId);
     CheckPointStatus status = checkPoint.getCheckPointStatus();
 
     if (CheckPointStatus.COMPLETED.equals(status)) {
-      String cacheId = appId + "_" + application.getJobId();
-      Long latestId =
-          checkPointCache.get(
-              cacheId,
-              key -> {
-                SavePoint savePoint = savePointService.getLatest(appId);
-                return 
Optional.ofNullable(savePoint).map(SavePoint::getChkId).orElse(null);
-              });
-
-      if (latestId == null || latestId < checkPoint.getId()) {
-        saveSavepoint(checkPoint, application);
+      String cacheId = getCacheIdForCheckpoint(appId, application.getJobId());
+      Long latestChkId = getLatestCheckpointedId(appId, cacheId);
+      if (shouldStoreAsSavepoint(checkPoint, latestChkId)) {
+        savepointedCache.put(checkPoint.getExternalPath(), DEFAULT_FLAG_BYTE);
+        if ((latestChkId == null || checkPoint.getId() > latestChkId)) {
+          checkPointCache.put(cacheId, checkPoint.getId());

Review Comment:
   If `savepointedCache` is necessary, why do  you store the savepoint to 
checkPointCache? Could it just be stored in `savepointedCache`?
   
   In fact, the logic is a bit more complicated now, it's better to simplify 
it. It reduces the chance of bugs and is easier for other developers to 
understand.



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/CheckpointProcessor.java:
##########
@@ -52,30 +62,31 @@ public class CheckpointProcessor {
 
   @Autowired private SavePointService savePointService;
 
-  public void process(Long appId, CheckPoints checkPoints) {
-    CheckPoints.Latest latest = checkPoints.getLatest();
-    if (latest == null || latest.getCompleted() == null) {
-      return;
-    }
-    CheckPoints.CheckPoint checkPoint = latest.getCompleted();
+  public void process(Long appId, @Nonnull CheckPoints checkPoints) {
+    checkPoints.getLatestCheckpoint().forEach(checkPoint -> process(appId, 
checkPoint));
+  }
+
+  private void process(Long appId, @Nonnull CheckPoints.CheckPoint checkPoint) 
{
     Application application = applicationService.getById(appId);
     CheckPointStatus status = checkPoint.getCheckPointStatus();
 
     if (CheckPointStatus.COMPLETED.equals(status)) {
-      String cacheId = appId + "_" + application.getJobId();
-      Long latestId =
-          checkPointCache.get(
-              cacheId,
-              key -> {
-                SavePoint savePoint = savePointService.getLatest(appId);
-                return 
Optional.ofNullable(savePoint).map(SavePoint::getChkId).orElse(null);
-              });
-
-      if (latestId == null || latestId < checkPoint.getId()) {
-        saveSavepoint(checkPoint, application);
+      String cacheId = getCacheIdForCheckpoint(appId, application.getJobId());
+      Long latestChkId = getLatestCheckpointedId(appId, cacheId);
+      if (shouldStoreAsSavepoint(checkPoint, latestChkId)) {
+        savepointedCache.put(checkPoint.getExternalPath(), DEFAULT_FLAG_BYTE);

Review Comment:
   Why using the `DEFAULT_FLAG_BYTE` as the value?
   
   Why don't using the similar logic to checkpointCache that using the cacheId 
as the key and checkpointId as the value?



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/CheckpointProcessor.java:
##########
@@ -52,30 +62,31 @@ public class CheckpointProcessor {
 
   @Autowired private SavePointService savePointService;
 
-  public void process(Long appId, CheckPoints checkPoints) {
-    CheckPoints.Latest latest = checkPoints.getLatest();
-    if (latest == null || latest.getCompleted() == null) {
-      return;
-    }
-    CheckPoints.CheckPoint checkPoint = latest.getCompleted();
+  public void process(Long appId, @Nonnull CheckPoints checkPoints) {
+    checkPoints.getLatestCheckpoint().forEach(checkPoint -> process(appId, 
checkPoint));
+  }
+
+  private void process(Long appId, @Nonnull CheckPoints.CheckPoint checkPoint) 
{
     Application application = applicationService.getById(appId);
     CheckPointStatus status = checkPoint.getCheckPointStatus();
 
     if (CheckPointStatus.COMPLETED.equals(status)) {
-      String cacheId = appId + "_" + application.getJobId();
-      Long latestId =
-          checkPointCache.get(
-              cacheId,
-              key -> {
-                SavePoint savePoint = savePointService.getLatest(appId);
-                return 
Optional.ofNullable(savePoint).map(SavePoint::getChkId).orElse(null);
-              });
-
-      if (latestId == null || latestId < checkPoint.getId()) {
-        saveSavepoint(checkPoint, application);
+      String cacheId = getCacheIdForCheckpoint(appId, application.getJobId());
+      Long latestChkId = getLatestCheckpointedId(appId, cacheId);
+      if (shouldStoreAsSavepoint(checkPoint, latestChkId)) {

Review Comment:
   > However, if the savepoint store-logic follow checkpoint, here would be 
some bug-case. If the triggered savepoint is completed after a completed 
checkpoint whose chk-id is bigger than the savepoint, the savepoint will be 
discard based on the current logic.
   
   When it happened, the latestChkId is bigger than the savepoint. So 
`shouldStoreAsSavepoint(checkPoint, latestChkId)` returns false, right?



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