use of org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata in project flink by apache.
the class DispatcherTest method createTestingSavepoint.
@Nonnull
private URI createTestingSavepoint() throws IOException, URISyntaxException {
final CheckpointStorage storage = Checkpoints.loadCheckpointStorage(configuration, Thread.currentThread().getContextClassLoader(), log);
final CheckpointStorageCoordinatorView checkpointStorage = storage.createCheckpointStorage(jobGraph.getJobID());
final File savepointFile = temporaryFolder.newFolder();
final long checkpointId = 1L;
final CheckpointStorageLocation checkpointStorageLocation = checkpointStorage.initializeLocationForSavepoint(checkpointId, savepointFile.getAbsolutePath());
final CheckpointMetadataOutputStream metadataOutputStream = checkpointStorageLocation.createMetadataOutputStream();
Checkpoints.storeCheckpointMetadata(new CheckpointMetadata(checkpointId, Collections.emptyList(), Collections.emptyList()), metadataOutputStream);
final CompletedCheckpointStorageLocation completedCheckpointStorageLocation = metadataOutputStream.closeAndFinalizeCheckpoint();
return new URI(completedCheckpointStorageLocation.getExternalPointer());
}
use of org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata in project flink by apache.
the class SavepointReader method read.
/**
* Loads an existing savepoint. Useful if you want to query the state of an existing
* application.
*
* @param env The execution environment used to transform the savepoint.
* @param path The path to an existing savepoint on disk.
* @param stateBackend The state backend of the savepoint.
* @return A {@link SavepointReader}.
*/
public static SavepointReader read(StreamExecutionEnvironment env, String path, StateBackend stateBackend) 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 SavepointReader(env, savepointMetadata, stateBackend);
}
use of org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata in project flink by apache.
the class Savepoint method load.
/**
* Loads an existing savepoint. Useful if you want to query, modify, or extend the state of an
* existing application.
*
* @param env The execution environment used to transform the savepoint.
* @param path The path to an existing savepoint on disk.
* @param stateBackend The state backend of the savepoint.
* @see #load(ExecutionEnvironment, String)
*/
public static ExistingSavepoint load(ExecutionEnvironment env, String path, StateBackend stateBackend) throws IOException {
Preconditions.checkNotNull(stateBackend, "The state backend must not be null");
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."));
SavepointMetadata savepointMetadata = new SavepointMetadata(maxParallelism, metadata.getMasterStates(), metadata.getOperatorStates());
return new ExistingSavepoint(env, savepointMetadata, stateBackend);
}
use of org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata in project flink by apache.
the class Savepoint method load.
/**
* Loads an existing savepoint. Useful if you want to query, modify, or extend the state of an
* existing application. The savepoint will be read using the state backend defined via the
* clusters configuration.
*
* @param env The execution environment used to transform the savepoint.
* @param path The path to an existing savepoint on disk.
* @see #load(ExecutionEnvironment, String, StateBackend)
*/
public static ExistingSavepoint load(ExecutionEnvironment env, 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."));
SavepointMetadata savepointMetadata = new SavepointMetadata(maxParallelism, metadata.getMasterStates(), metadata.getOperatorStates());
return new ExistingSavepoint(env, savepointMetadata, null);
}
use of org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata in project flink by apache.
the class SavepointOutputFormatTest method testSavepointOutputFormat.
@Test
public void testSavepointOutputFormat() throws Exception {
Path path = new Path(temporaryFolder.newFolder().getAbsolutePath());
SavepointOutputFormat format = createSavepointOutputFormat(path);
CheckpointMetadata metadata = createSavepoint();
format.open(0, 1);
format.writeRecord(metadata);
format.close();
CheckpointMetadata metadataOnDisk = SavepointLoader.loadSavepointMetadata(path.getPath());
Assert.assertEquals("Incorrect checkpoint id", metadata.getCheckpointId(), metadataOnDisk.getCheckpointId());
Assert.assertEquals("Incorrect number of operator states in savepoint", metadata.getOperatorStates().size(), metadataOnDisk.getOperatorStates().size());
Assert.assertEquals("Incorrect operator state in savepoint", metadata.getOperatorStates().iterator().next(), metadataOnDisk.getOperatorStates().iterator().next());
}
Aggregations