rkhachatryan commented on a change in pull request #11515: [FLINK-16744][task] 
implement channel state persistence for unaligned checkpoints
URL: https://github.com/apache/flink/pull/11515#discussion_r401955339
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/SubtaskCheckpointCoordinatorImpl.java
 ##########
 @@ -89,17 +101,98 @@ public void checkpointState(
                        checkpointMetaData.getCheckpointId(),
                        checkpointOptions.getTargetLocation());
 
-               CheckpointingOperation.execute(
-                       checkpointMetaData,
-                       checkpointOptions,
-                       checkpointMetrics,
-                       storage,
-                       operatorChain,
-                       taskName,
-                       closeableRegistry,
-                       executorService,
-                       env,
-                       asyncExceptionHandler,
-                       isCanceled);
+               long startSyncPartNano = System.nanoTime();
+
+               HashMap<OperatorID, OperatorSnapshotFutures> 
operatorSnapshotsInProgress = new 
HashMap<>(operatorChain.getNumberOfOperators());
+               try {
+                       for (StreamOperatorWrapper<?, ?> operatorWrapper : 
operatorChain.getAllOperators(true)) {
+                               StreamOperator<?> op = 
operatorWrapper.getStreamOperator();
+                               OperatorSnapshotFutures snapshotInProgress = 
checkpointStreamOperator(
+                                       op,
+                                       checkpointMetaData,
+                                       checkpointOptions,
+                                       storage,
+                                       isCanceled);
+                               
operatorSnapshotsInProgress.put(op.getOperatorID(), snapshotInProgress);
+                       }
+
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug("Finished synchronous checkpoints for 
checkpoint {} on task {}",
+                                       checkpointMetaData.getCheckpointId(), 
taskName);
+                       }
+
+                       long startAsyncPartNano = System.nanoTime();
+
+                       
checkpointMetrics.setSyncDurationMillis((startAsyncPartNano - 
startSyncPartNano) / 1_000_000);
+
+                       // we are transferring ownership over 
snapshotInProgressList for cleanup to the thread, active on submit
+                       executorService.execute(new AsyncCheckpointRunnable(
+                               operatorSnapshotsInProgress,
+                               checkpointMetaData,
+                               checkpointMetrics,
+                               startAsyncPartNano,
+                               taskName,
+                               closeableRegistry,
+                               env,
+                               asyncExceptionHandler));
+
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug(
+                                       "{} - finished synchronous part of 
checkpoint {}. Alignment duration: {} ms, snapshot duration {} ms",
+                                       taskName, 
checkpointMetaData.getCheckpointId(),
+                                       
checkpointMetrics.getAlignmentDurationNanos() / 1_000_000,
+                                       
checkpointMetrics.getSyncDurationMillis());
+                       }
+               } catch (Exception ex) {
+                       // Cleanup to release resources
+                       for (OperatorSnapshotFutures operatorSnapshotResult : 
operatorSnapshotsInProgress.values()) {
+                               if (null != operatorSnapshotResult) {
+                                       try {
+                                               operatorSnapshotResult.cancel();
+                                       } catch (Exception e) {
+                                               LOG.warn("Could not properly 
cancel an operator snapshot result.", e);
+                                       }
+                               }
+                       }
+
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug(
 
 Review comment:
   I refactored a bit `SubtaskCheckpointCoordinatorImpl` while addressing one 
of the issues below and these messages ended up one after another; so removed 
one.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to