Search in sources :

Example 61 with OperatorState

use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.

the class TestUtils method createSavepointWithOperatorState.

public static File createSavepointWithOperatorState(File savepointFile, long savepointId, OperatorID... operatorIds) throws IOException {
    final Collection<OperatorState> operatorStates = createOperatorState(operatorIds);
    final CheckpointMetadata savepoint = new CheckpointMetadata(savepointId, operatorStates, Collections.emptyList());
    try (FileOutputStream fileOutputStream = new FileOutputStream(savepointFile)) {
        Checkpoints.storeCheckpointMetadata(savepoint, fileOutputStream);
    }
    return savepointFile;
}
Also used : FileOutputStream(java.io.FileOutputStream) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)

Example 62 with OperatorState

use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.

the class OperatorCoordinatorSchedulerTest method testTakeCheckpoint.

// ------------------------------------------------------------------------
// tests for checkpointing
// ------------------------------------------------------------------------
@Test
public void testTakeCheckpoint() throws Exception {
    final byte[] checkpointData = new byte[656];
    new Random().nextBytes(checkpointData);
    final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
    final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
    final CompletableFuture<CompletedCheckpoint> checkpointFuture = triggerCheckpoint(scheduler);
    coordinator.getLastTriggeredCheckpoint().complete(checkpointData);
    acknowledgeCurrentCheckpoint(scheduler);
    final OperatorState state = checkpointFuture.get().getOperatorStates().get(testOperatorId);
    assertArrayEquals(checkpointData, getStateHandleContents(state.getCoordinatorState()));
}
Also used : CompletedCheckpoint(org.apache.flink.runtime.checkpoint.CompletedCheckpoint) Random(java.util.Random) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) DefaultScheduler(org.apache.flink.runtime.scheduler.DefaultScheduler) Test(org.junit.Test)

Example 63 with OperatorState

use of org.apache.flink.runtime.checkpoint.OperatorState 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

OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)63 Test (org.junit.Test)22 Configuration (org.apache.flink.configuration.Configuration)17 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)14 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)14 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)14 CheckpointMetadata (org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata)11 MasterState (org.apache.flink.runtime.checkpoint.MasterState)9 Random (java.util.Random)8 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)8 KeyGroupRangeInputSplit (org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit)7 ArrayList (java.util.ArrayList)6 KeyedStateReaderFunction (org.apache.flink.state.api.functions.KeyedStateReaderFunction)6 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)5 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)4 BroadcastStateInputFormat (org.apache.flink.state.api.input.BroadcastStateInputFormat)4 ListStateInputFormat (org.apache.flink.state.api.input.ListStateInputFormat)4 UnionStateInputFormat (org.apache.flink.state.api.input.UnionStateInputFormat)4 PassThroughReader (org.apache.flink.state.api.input.operator.window.PassThroughReader)4