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

 ##########
 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(
+                                       "{} - did NOT finish synchronous part 
of checkpoint {}. Alignment duration: {} ms, snapshot duration {} ms",
+                                       taskName, 
checkpointMetaData.getCheckpointId(),
 
 Review comment:
   nit: better to split line for every argument

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to