Search in sources :

Example 1 with ExternallyInducedSource

use of org.apache.flink.streaming.api.checkpoint.ExternallyInducedSource in project flink by apache.

the class SourceStreamTask method init.

@Override
protected void init() {
    // we check if the source is actually inducing the checkpoints, rather
    // than the trigger
    SourceFunction<?> source = mainOperator.getUserFunction();
    if (source instanceof ExternallyInducedSource) {
        externallyInducedCheckpoints = true;
        ExternallyInducedSource.CheckpointTrigger triggerHook = new ExternallyInducedSource.CheckpointTrigger() {

            @Override
            public void triggerCheckpoint(long checkpointId) throws FlinkException {
                // TODO - we need to see how to derive those. We should probably not
                // encode this in the
                // TODO -   source's trigger message, but do a handshake in this task
                // between the trigger
                // TODO -   message from the master, and the source's trigger
                // notification
                final CheckpointOptions checkpointOptions = CheckpointOptions.forConfig(CheckpointType.CHECKPOINT, CheckpointStorageLocationReference.getDefault(), configuration.isExactlyOnceCheckpointMode(), configuration.isUnalignedCheckpointsEnabled(), configuration.getAlignedCheckpointTimeout().toMillis());
                final long timestamp = System.currentTimeMillis();
                final CheckpointMetaData checkpointMetaData = new CheckpointMetaData(checkpointId, timestamp, timestamp);
                try {
                    SourceStreamTask.super.triggerCheckpointAsync(checkpointMetaData, checkpointOptions).get();
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e) {
                    throw new FlinkException(e.getMessage(), e);
                }
            }
        };
        ((ExternallyInducedSource<?, ?>) source).setCheckpointTrigger(triggerHook);
    }
    getEnvironment().getMetricGroup().getIOMetricGroup().gauge(MetricNames.CHECKPOINT_START_DELAY_TIME, this::getAsyncCheckpointStartDelayNanos);
}
Also used : ExternallyInducedSource(org.apache.flink.streaming.api.checkpoint.ExternallyInducedSource) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) FlinkException(org.apache.flink.util.FlinkException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)1 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)1 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)1 ExternallyInducedSource (org.apache.flink.streaming.api.checkpoint.ExternallyInducedSource)1 FlinkException (org.apache.flink.util.FlinkException)1