Search in sources :

Example 16 with CheckpointMetadata

use of org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata in project flink by apache.

the class CheckpointMetadataLoadingTest method createSavepointWithOperatorState.

// ------------------------------------------------------------------------
// setup utils
// ------------------------------------------------------------------------
private static CompletedCheckpointStorageLocation createSavepointWithOperatorState(final long checkpointId, final OperatorState state) throws IOException {
    final CheckpointMetadata savepoint = new CheckpointMetadata(checkpointId, Collections.singletonList(state), Collections.emptyList());
    final StreamStateHandle serializedMetadata;
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        Checkpoints.storeCheckpointMetadata(savepoint, os);
        serializedMetadata = new ByteStreamStateHandle("checkpoint", os.toByteArray());
    }
    return new TestCompletedCheckpointStorageLocation(serializedMetadata, "dummy/pointer");
}
Also used : OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)

Example 17 with CheckpointMetadata

use of org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata in project flink by apache.

the class SavepointFormatITCase method testTriggerSavepointAndResumeWithFileBasedCheckpointsAndRelocateBasePath.

@ParameterizedTest(name = "[{index}] {0}, {1}")
@MethodSource("parameters")
public void testTriggerSavepointAndResumeWithFileBasedCheckpointsAndRelocateBasePath(SavepointFormatType formatType, StateBackendConfig stateBackendConfig) throws Exception {
    final int numTaskManagers = 2;
    final int numSlotsPerTaskManager = 2;
    final Configuration config = stateBackendConfig.getConfiguration();
    config.set(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointsDir.toUri().toString());
    final MiniClusterWithClientResource miniClusterResource = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(config).setNumberTaskManagers(numTaskManagers).setNumberSlotsPerTaskManager(numSlotsPerTaskManager).build());
    miniClusterResource.before();
    try {
        final String savepointPath = submitJobAndTakeSavepoint(miniClusterResource, formatType, stateBackendConfig.getCheckpointsBeforeSavepoint(), config);
        final CheckpointMetadata metadata = loadCheckpointMetadata(savepointPath);
        final OperatorState operatorState = metadata.getOperatorStates().stream().filter(hasKeyedState()).findFirst().get();
        operatorState.getStates().stream().flatMap(subtaskState -> subtaskState.getManagedKeyedState().stream()).forEach(handle -> validateState(handle, formatType, stateBackendConfig));
        relocateAndVerify(miniClusterResource, savepointPath, renamedSavepointDir, config);
    } finally {
        miniClusterResource.after();
    }
}
Also used : KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) BiFunction(java.util.function.BiFunction) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) IncrementalRemoteKeyedStateHandle(org.apache.flink.runtime.state.IncrementalRemoteKeyedStateHandle) MemorySize(org.apache.flink.configuration.MemorySize) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) CommonTestUtils.waitForAllTaskRunning(org.apache.flink.runtime.testutils.CommonTestUtils.waitForAllTaskRunning) Arrays.asList(java.util.Arrays.asList) ChangelogStateBackendHandle(org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle) Level(org.slf4j.event.Level) Checkpoints(org.apache.flink.runtime.checkpoint.Checkpoints) Path(java.nio.file.Path) MethodSource(org.junit.jupiter.params.provider.MethodSource) LoggerAuditingExtension(org.apache.flink.testutils.logging.LoggerAuditingExtension) Predicate(java.util.function.Predicate) CompletedCheckpointStorageLocation(org.apache.flink.runtime.state.CompletedCheckpointStorageLocation) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) Arguments(org.junit.jupiter.params.provider.Arguments) CheckpointingOptions(org.apache.flink.configuration.CheckpointingOptions) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata) List(java.util.List) ValueState(org.apache.flink.api.common.state.ValueState) ClusterClient(org.apache.flink.client.program.ClusterClient) TempDir(org.junit.jupiter.api.io.TempDir) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) DataInputStream(java.io.DataInputStream) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) AbstractFsCheckpointStorageAccess(org.apache.flink.runtime.state.filesystem.AbstractFsCheckpointStorageAccess) RestoreMode(org.apache.flink.runtime.jobgraph.RestoreMode) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LinkedList(java.util.LinkedList) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) DiscardingSink(org.apache.flink.streaming.api.functions.sink.DiscardingSink) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) StateChangelogOptions(org.apache.flink.configuration.StateChangelogOptions) Configuration(org.apache.flink.configuration.Configuration) IOException(java.io.IOException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) JobID(org.apache.flink.api.common.JobID) RuntimeExecutionMode(org.apache.flink.api.common.RuntimeExecutionMode) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) SavepointKeyedStateHandle(org.apache.flink.runtime.state.SavepointKeyedStateHandle) StateBackendOptions(org.apache.flink.configuration.StateBackendOptions) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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