Search in sources :

Example 1 with StateBootstrapTransformationWithID

use of org.apache.flink.state.api.runtime.StateBootstrapTransformationWithID in project flink by apache.

the class SavepointWriter method write.

/**
 * Write out a new or updated savepoint.
 *
 * @param path The path to where the savepoint should be written.
 */
public final void write(String path) {
    final Path savepointPath = new Path(path);
    List<StateBootstrapTransformationWithID<?>> newOperatorTransformations = metadata.getNewOperators();
    DataStream<OperatorState> newOperatorStates = writeOperatorStates(newOperatorTransformations, configuration, savepointPath);
    List<OperatorState> existingOperators = metadata.getExistingOperators();
    DataStream<OperatorState> finalOperatorStates;
    if (existingOperators.isEmpty()) {
        finalOperatorStates = newOperatorStates;
    } else {
        DataStream<OperatorState> existingOperatorStates = newOperatorStates.getExecutionEnvironment().fromCollection(existingOperators).name("existingOperatorStates");
        existingOperatorStates.flatMap(new StatePathExtractor()).setParallelism(1).addSink(new OutputFormatSinkFunction<>(new FileCopyFunction(path)));
        finalOperatorStates = newOperatorStates.union(existingOperatorStates);
    }
    finalOperatorStates.transform("reduce(OperatorState)", TypeInformation.of(CheckpointMetadata.class), new GroupReduceOperator<>(new MergeOperatorStates(metadata.getMasterStates()))).forceNonParallel().addSink(new OutputFormatSinkFunction<>(new SavepointOutputFormat(savepointPath))).setParallelism(1).name(path);
}
Also used : Path(org.apache.flink.core.fs.Path) StatePathExtractor(org.apache.flink.state.api.output.StatePathExtractor) FileCopyFunction(org.apache.flink.state.api.output.FileCopyFunction) SavepointOutputFormat(org.apache.flink.state.api.output.SavepointOutputFormat) MergeOperatorStates(org.apache.flink.state.api.output.MergeOperatorStates) StateBootstrapTransformationWithID(org.apache.flink.state.api.runtime.StateBootstrapTransformationWithID) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)

Example 2 with StateBootstrapTransformationWithID

use of org.apache.flink.state.api.runtime.StateBootstrapTransformationWithID in project flink by apache.

the class SavepointMetadataV2 method addOperator.

public void addOperator(String uid, StateBootstrapTransformation<?> transformation) {
    OperatorID id = OperatorIDGenerator.fromUid(uid);
    if (operatorStateIndex.containsKey(id)) {
        throw new IllegalArgumentException("The savepoint already contains uid " + uid + ". All uid's must be unique");
    }
    operatorStateIndex.put(id, OperatorStateSpecV2.newWithTransformation(new StateBootstrapTransformationWithID<>(id, transformation)));
}
Also used : OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) StateBootstrapTransformationWithID(org.apache.flink.state.api.runtime.StateBootstrapTransformationWithID)

Aggregations

StateBootstrapTransformationWithID (org.apache.flink.state.api.runtime.StateBootstrapTransformationWithID)2 Path (org.apache.flink.core.fs.Path)1 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)1 CheckpointMetadata (org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)1 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)1 FileCopyFunction (org.apache.flink.state.api.output.FileCopyFunction)1 MergeOperatorStates (org.apache.flink.state.api.output.MergeOperatorStates)1 SavepointOutputFormat (org.apache.flink.state.api.output.SavepointOutputFormat)1 StatePathExtractor (org.apache.flink.state.api.output.StatePathExtractor)1