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_r405303703
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/SubtaskCheckpointCoordinatorImpl.java
 ##########
 @@ -130,95 +130,108 @@ public void checkpointState(
 
                // Step (1): Prepare the checkpoint, allow operators to do some 
pre-barrier work.
                //           The pre-barrier work should be nothing or minimal 
in the common case.
-               operatorChain.prepareSnapshotPreBarrier(checkpointId);
+               
operatorChain.prepareSnapshotPreBarrier(metadata.getCheckpointId());
 
                // Step (2): Send the checkpoint barrier downstream
-               operatorChain.broadcastCheckpointBarrier(
-                       checkpointId,
-                       checkpointMetaData.getTimestamp(),
-                       checkpointOptions);
+               
operatorChain.broadcastCheckpointBarrier(metadata.getCheckpointId(), 
metadata.getTimestamp(), options);
 
-               // Step (3): Take the state snapshot. This should be largely 
asynchronous, to not
-               //           impact progress of the streaming topology
+               // Step (3): Take the state snapshot. This should be largely 
asynchronous, to not impact progress of the streaming topology
 
-               long startSyncPartNano = System.nanoTime();
-
-               HashMap<OperatorID, OperatorSnapshotFutures> 
operatorSnapshotsInProgress = new 
HashMap<>(operatorChain.getNumberOfOperators());
-               ChannelStateWriteResult channelStateWriteResult =
-                       checkpointOptions.getCheckpointType() == CHECKPOINT ? 
channelStateWriter.getWriteResult(checkpointMetaData.getCheckpointId()) :
-                               ChannelStateWriteResult.EMPTY;
+               Map<OperatorID, OperatorSnapshotFutures> snapshotFutures = new 
HashMap<>(operatorChain.getNumberOfOperators());
                try {
-                       for (StreamOperatorWrapper<?, ?> operatorWrapper : 
operatorChain.getAllOperators(true)) {
-                               operatorSnapshotsInProgress.put(
-                                       
operatorWrapper.getStreamOperator().getOperatorID(),
-                                       buildOperatorSnapshotFutures(
-                                               checkpointMetaData,
-                                               checkpointOptions,
-                                               operatorChain,
-                                               
operatorWrapper.getStreamOperator(),
-                                               isCanceled,
-                                               channelStateWriteResult)
-                               );
-                       }
-                       
checkpointStorage.clearCacheFor(checkpointMetaData.getCheckpointId());
+                       takeSnapshotSync(snapshotFutures, metadata, metrics, 
options, operatorChain, isCanceled);
+                       finishAndReportAsync(snapshotFutures, metadata, 
metrics);
+               } catch (Exception ex) {
+                       cleanup(snapshotFutures, metadata, metrics, options, 
ex);
+               }
+       }
 
-                       if (LOG.isDebugEnabled()) {
-                               LOG.debug("Finished synchronous checkpoints for 
checkpoint {} on task {}",
-                                       checkpointMetaData.getCheckpointId(), 
taskName);
-                       }
+       private void cleanup(
+                       Map<OperatorID, OperatorSnapshotFutures> 
operatorSnapshotsInProgress,
+                       CheckpointMetaData metadata,
+                       CheckpointMetrics metrics, CheckpointOptions options,
+                       Exception ex) throws Exception {
 
-                       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);
-                                       }
+               for (OperatorSnapshotFutures operatorSnapshotResult : 
operatorSnapshotsInProgress.values()) {
+                       if (operatorSnapshotResult != null) {
+                               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(),
-                                       
checkpointMetrics.getAlignmentDurationNanos() / 1_000_000,
-                                       
checkpointMetrics.getSyncDurationMillis());
-                       }
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug(
+                               "{} - did NOT finish synchronous part of 
checkpoint {}. Alignment duration: {} ms, snapshot duration {} ms",
+                               taskName, metadata.getCheckpointId(),
+                               metrics.getAlignmentDurationNanos() / 1_000_000,
+                               metrics.getSyncDurationMillis());
+               }
 
-                       if 
(checkpointOptions.getCheckpointType().isSynchronous()) {
-                               // in the case of a synchronous checkpoint, we 
always rethrow the exception,
-                               // so that the task fails.
-                               // this is because the intention is always to 
stop the job after this checkpointing
-                               // operation, and without the failure, the task 
would go back to normal execution.
-                               throw ex;
-                       } else {
-                               
env.declineCheckpoint(checkpointMetaData.getCheckpointId(), ex);
-                       }
+               if (options.getCheckpointType().isSynchronous()) {
+                       // in the case of a synchronous checkpoint, we always 
rethrow the exception,
+                       // so that the task fails.
+                       // this is because the intention is always to stop the 
job after this checkpointing
+                       // operation, and without the failure, the task would 
go back to normal execution.
+                       throw ex;
+               } else {
+                       env.declineCheckpoint(metadata.getCheckpointId(), ex);
+               }
+       }
+
+       private void finishAndReportAsync(Map<OperatorID, 
OperatorSnapshotFutures> snapshotFutures, CheckpointMetaData metadata, 
CheckpointMetrics metrics) {
+               // we are transferring ownership over snapshotInProgressList 
for cleanup to the thread, active on submit
+               executorService.execute(new AsyncCheckpointRunnable(
+                       snapshotFutures,
+                       metadata,
+                       metrics,
+                       System.nanoTime(),
+                       taskName,
+                       closeableRegistry,
+                       env,
+                       asyncExceptionHandler));
+       }
+
+       private void takeSnapshotSync(
+               Map<OperatorID, OperatorSnapshotFutures> 
operatorSnapshotsInProgress, CheckpointMetaData checkpointMetaData,
 
 Review comment:
   it is not suggested putting multiple arguments in one line. 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