Search in sources :

Example 6 with SavepointMetadataV2

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

the class SavepointWriter method fromExistingSavepoint.

/**
 * Loads an existing savepoint. Useful if you want to modify or extend the state of an existing
 * application. The savepoint will be written using the state backend defined via the clusters
 * configuration.
 *
 * @param path The path to an existing savepoint on disk.
 * @return A {@link SavepointWriter}.
 * @see #fromExistingSavepoint(String, StateBackend)
 * @see #withConfiguration(ConfigOption, Object)
 */
public static SavepointWriter fromExistingSavepoint(String path) throws IOException {
    CheckpointMetadata metadata = SavepointLoader.loadSavepointMetadata(path);
    int maxParallelism = metadata.getOperatorStates().stream().map(OperatorState::getMaxParallelism).max(Comparator.naturalOrder()).orElseThrow(() -> new RuntimeException("Savepoint must contain at least one operator state."));
    SavepointMetadataV2 savepointMetadata = new SavepointMetadataV2(maxParallelism, metadata.getMasterStates(), metadata.getOperatorStates());
    return new SavepointWriter(savepointMetadata, null);
}
Also used : SavepointMetadataV2(org.apache.flink.state.api.runtime.metadata.SavepointMetadataV2) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)

Aggregations

SavepointMetadataV2 (org.apache.flink.state.api.runtime.metadata.SavepointMetadataV2)6 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)4 CheckpointMetadata (org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)4