Search in sources :

Example 56 with OperatorState

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

the class MetadataV3SerializerTest method testCheckpointWithMasterAndTaskState.

private void testCheckpointWithMasterAndTaskState(String basePath) throws Exception {
    final Random rnd = new Random();
    final int maxNumMasterStates = 5;
    final int maxTaskStates = 20;
    final int maxNumSubtasks = 20;
    for (int i = 0; i < 100; ++i) {
        final long checkpointId = rnd.nextLong() & 0x7fffffffffffffffL;
        final int numTasks = rnd.nextInt(maxTaskStates) + 1;
        final int numSubtasks = rnd.nextInt(maxNumSubtasks) + 1;
        final Collection<OperatorState> taskStates = CheckpointTestUtils.createOperatorStates(rnd, basePath, numTasks, 0, 0, numSubtasks);
        final int numMasterStates = rnd.nextInt(maxNumMasterStates) + 1;
        final Collection<MasterState> masterStates = CheckpointTestUtils.createRandomMasterStates(rnd, numMasterStates);
        testCheckpointSerialization(checkpointId, taskStates, masterStates, basePath);
    }
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MasterState(org.apache.flink.runtime.checkpoint.MasterState) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState)

Example 57 with OperatorState

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

the class MetadataV3SerializerTest method testCheckpointWithFinishedTasks.

private void testCheckpointWithFinishedTasks(String basePath) throws Exception {
    final Random rnd = new Random();
    final int maxNumMasterStates = 5;
    final int maxNumSubtasks = 20;
    final int maxAllRunningTaskStates = 20;
    final int maxPartlyFinishedStates = 10;
    final int maxFullyFinishedSubtasks = 10;
    final long checkpointId = rnd.nextLong() & 0x7fffffffffffffffL;
    final int numSubtasks = rnd.nextInt(maxNumSubtasks) + 1;
    final int numAllRunningTasks = rnd.nextInt(maxAllRunningTaskStates) + 1;
    final int numPartlyFinishedTasks = rnd.nextInt(maxPartlyFinishedStates) + 1;
    final int numFullyFinishedTasks = rnd.nextInt(maxFullyFinishedSubtasks) + 1;
    final Collection<OperatorState> taskStates = CheckpointTestUtils.createOperatorStates(rnd, basePath, numAllRunningTasks, numPartlyFinishedTasks, numFullyFinishedTasks, numSubtasks);
    final int numMasterStates = rnd.nextInt(maxNumMasterStates) + 1;
    final Collection<MasterState> masterStates = CheckpointTestUtils.createRandomMasterStates(rnd, numMasterStates);
    testCheckpointSerialization(checkpointId, taskStates, masterStates, basePath);
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MasterState(org.apache.flink.runtime.checkpoint.MasterState) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState)

Example 58 with OperatorState

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

the class CheckpointMetadata method dispose.

@Override
public void dispose() throws Exception {
    for (OperatorState operatorState : operatorStates) {
        operatorState.discardState();
    }
    operatorStates.clear();
    masterStates.clear();
}
Also used : OperatorState(org.apache.flink.runtime.checkpoint.OperatorState)

Example 59 with OperatorState

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

the class MetadataV3Serializer method deserializeOperatorState.

@Override
protected OperatorState deserializeOperatorState(DataInputStream dis, @Nullable DeserializationContext context) throws IOException {
    final OperatorID jobVertexId = new OperatorID(dis.readLong(), dis.readLong());
    final int parallelism = dis.readInt();
    final int maxParallelism = dis.readInt();
    ByteStreamStateHandle coordinateState = deserializeAndCheckByteStreamStateHandle(dis, context);
    final int numSubTaskStates = dis.readInt();
    if (numSubTaskStates < 0) {
        checkState(coordinateState == null, "Coordinator State should be null for fully finished operator state");
        return new FullyFinishedOperatorState(jobVertexId, parallelism, maxParallelism);
    }
    final OperatorState operatorState = new OperatorState(jobVertexId, parallelism, maxParallelism);
    // Coordinator state
    operatorState.setCoordinatorState(coordinateState);
    // Sub task states
    for (int j = 0; j < numSubTaskStates; j++) {
        SubtaskAndFinishedState subtaskAndFinishedState = deserializeSubtaskIndexAndFinishedState(dis);
        if (subtaskAndFinishedState.isFinished) {
            operatorState.putState(subtaskAndFinishedState.subtaskIndex, FinishedOperatorSubtaskState.INSTANCE);
        } else {
            final OperatorSubtaskState subtaskState = deserializeSubtaskState(dis, context);
            operatorState.putState(subtaskAndFinishedState.subtaskIndex, subtaskState);
        }
    }
    return operatorState;
}
Also used : OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) FullyFinishedOperatorState(org.apache.flink.runtime.checkpoint.FullyFinishedOperatorState) FullyFinishedOperatorState(org.apache.flink.runtime.checkpoint.FullyFinishedOperatorState) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) FinishedOperatorSubtaskState(org.apache.flink.runtime.checkpoint.FinishedOperatorSubtaskState)

Example 60 with OperatorState

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

the class TestUtils method createOperatorState.

private static Collection<OperatorState> createOperatorState(OperatorID... operatorIds) {
    Random random = new Random();
    Collection<OperatorState> operatorStates = new ArrayList<>(operatorIds.length);
    for (OperatorID operatorId : operatorIds) {
        final OperatorState operatorState = new OperatorState(operatorId, 1, 42);
        final OperatorSubtaskState subtaskState = OperatorSubtaskState.builder().setManagedOperatorState(new OperatorStreamStateHandle(Collections.emptyMap(), new ByteStreamStateHandle("foobar", new byte[0]))).setInputChannelState(singleton(createNewInputChannelStateHandle(10, random))).setResultSubpartitionState(singleton(createNewResultSubpartitionStateHandle(10, random))).build();
        operatorState.putState(0, subtaskState);
        operatorStates.add(operatorState);
    }
    return operatorStates;
}
Also used : Random(java.util.Random) OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) ArrayList(java.util.ArrayList) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState)

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