Search in sources :

Example 1 with CheckpointMetadata

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());
}
Also used : CheckpointMetadataOutputStream(org.apache.flink.runtime.state.CheckpointMetadataOutputStream) CheckpointStorage(org.apache.flink.runtime.state.CheckpointStorage) CheckpointStorageCoordinatorView(org.apache.flink.runtime.state.CheckpointStorageCoordinatorView) CheckpointStorageLocation(org.apache.flink.runtime.state.CheckpointStorageLocation) CompletedCheckpointStorageLocation(org.apache.flink.runtime.state.CompletedCheckpointStorageLocation) CompletedCheckpointStorageLocation(org.apache.flink.runtime.state.CompletedCheckpointStorageLocation) File(java.io.File) URI(java.net.URI) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata) Nonnull(javax.annotation.Nonnull)

Example 2 with CheckpointMetadata

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);
}
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)

Example 3 with CheckpointMetadata

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);
}
Also used : SavepointMetadata(org.apache.flink.state.api.runtime.metadata.SavepointMetadata) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)

Example 4 with CheckpointMetadata

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);
}
Also used : SavepointMetadata(org.apache.flink.state.api.runtime.metadata.SavepointMetadata) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)

Example 5 with CheckpointMetadata

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());
}
Also used : Path(org.apache.flink.core.fs.Path) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata) Test(org.junit.Test)

Aggregations

CheckpointMetadata (org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)17 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)10 CompletedCheckpointStorageLocation (org.apache.flink.runtime.state.CompletedCheckpointStorageLocation)4 SavepointMetadataV2 (org.apache.flink.state.api.runtime.metadata.SavepointMetadataV2)4 DataInputStream (java.io.DataInputStream)3 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CheckpointMetadataOutputStream (org.apache.flink.runtime.state.CheckpointMetadataOutputStream)2 SavepointMetadata (org.apache.flink.state.api.runtime.metadata.SavepointMetadata)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Optional (java.util.Optional)1