Source:
<code>private void startTriggeringCheckpoint(CheckpointTriggerRequest request) { try { synchronized (lock) { <START> preCheckGlobalState(request.isPeriodic); <END> } final Execution[] executions = getTriggerExecutions(); final Map<ExecutionAttemptID, ExecutionVertex> ackTasks = getAckTasks(); Preconditions.checkState(!isTriggering); isTriggering = true; final CompletableFuture<PendingCheckpoint> pendingCheckpointCompletableFuture = initializeCheckpoint(request.props, request.externalSavepointLocation) .thenApplyAsync( (checkpointIdAndStorageLocation) -> createPendingCheckpoint( request.timestamp, request.props, ackTasks, request.isPeriodic, checkpointIdAndStorageLocation.checkpointId, checkpointIdAndStorageLocation.checkpointStorageLocation, request.onCompletionPromise), timer); final CompletableFuture<?> masterStatesComplete = pendingCheckpointCompletableFuture .thenCompose(this::snapshotMasterState); final CompletableFuture<?> coordinatorCheckpointsComplete = pendingCheckpointCompletableFuture .thenComposeAsync((pendingCheckpoint) -> OperatorCoordinatorCheckpoints.triggerAndAcknowledgeAllCoordinatorCheckpointsWithCompletion( coordinatorsToCheckpoint, pendingCheckpoint, timer), timer); CompletableFuture.allOf(masterStatesComplete, coordinatorCheckpointsComplete) .whenCompleteAsync( (ignored, throwable) -> { final PendingCheckpoint checkpoint = FutureUtils.getWithoutException(pendingCheckpointCompletableFuture); if (throwable == null && checkpoint != null && !checkpoint.isDiscarded()) { snapshotTaskState( request.timestamp, checkpoint.getCheckpointId(), checkpoint.getCheckpointStorageLocation(), request.props, executions, request.advanceToEndOfTime); onTriggerSuccess(); } else { if (checkpoint == null) { onTriggerFailure(request.onCompletionPromise, throwable); } else { onTriggerFailure(checkpoint, throwable); } } }, timer); } catch (Throwable throwable) { onTriggerFailure(request.onCompletionPromise, throwable); } }</code><technical_language>extracted a bit of refactoring independent commit. CheckpointTriggerRequest a parameter moving CompletableFuture<CompletedCheckpoint> onCompletionPromise request (it significantly simplify review of this change)</technical_language>

Target:
private void startTriggeringCheckpoint(CheckpointTriggerRequest request) { try { synchronized (lock) { preCheckGlobalState(request.isPeriodic); } final Execution[] executions = getTriggerExecutions(); final Map<ExecutionAttemptID, ExecutionVertex> ackTasks = getAckTasks(); Preconditions.checkState(!isTriggering); isTriggering = true; final long timestamp = System.currentTimeMillis(); final CompletableFuture<PendingCheckpoint> pendingCheckpointCompletableFuture = initializeCheckpoint(request.props, request.externalSavepointLocation) .thenApplyAsync( (checkpointIdAndStorageLocation) -> createPendingCheckpoint( timestamp, request.props, ackTasks, request.isPeriodic, checkpointIdAndStorageLocation.checkpointId, checkpointIdAndStorageLocation.checkpointStorageLocation, request.getOnCompletionFuture()), timer); final CompletableFuture<?> masterStatesComplete = pendingCheckpointCompletableFuture.thenCompose(this::snapshotMasterState); final CompletableFuture<?> coordinatorCheckpointsComplete = pendingCheckpointCompletableFuture.thenComposeAsync( pendingCheckpoint -> triggerAndAcknowledgeAllCoordinatorCheckpointsWithCompletion(coordinatorsToCheckpoint, pendingCheckpoint, timer), timer); CompletableFuture.allOf(masterStatesComplete, coordinatorCheckpointsComplete) .whenCompleteAsync( (ignored, throwable) -> { final PendingCheckpoint checkpoint = FutureUtils.getWithoutException(pendingCheckpointCompletableFuture); if (throwable == null && checkpoint != null && !checkpoint.isDiscarded()) { snapshotTaskState( timestamp, checkpoint.getCheckpointId(), checkpoint.getCheckpointStorageLocation(), request.props, executions, request.advanceToEndOfTime); onTriggerSuccess(); } else { if (checkpoint == null) { onTriggerFailure(request, throwable); } else { onTriggerFailure(checkpoint, throwable); } } }, timer); } catch (Throwable throwable) { onTriggerFailure(request, throwable); } }