Search in sources :

Example 1 with SerializedStateHandle

use of org.apache.flink.migration.runtime.state.memory.SerializedStateHandle in project flink by apache.

the class MigrationV0ToV1Test method createTaskStatesOld.

private static Collection<org.apache.flink.migration.runtime.checkpoint.TaskState> createTaskStatesOld(int numTaskStates, int numSubtaskStates) throws Exception {
    List<org.apache.flink.migration.runtime.checkpoint.TaskState> taskStates = new ArrayList<>(numTaskStates);
    for (int i = 0; i < numTaskStates; i++) {
        org.apache.flink.migration.runtime.checkpoint.TaskState taskState = new org.apache.flink.migration.runtime.checkpoint.TaskState(new JobVertexID(), numSubtaskStates);
        for (int j = 0; j < numSubtaskStates; j++) {
            StreamTaskState[] streamTaskStates = new StreamTaskState[2];
            for (int k = 0; k < streamTaskStates.length; k++) {
                StreamTaskState state = new StreamTaskState();
                Tuple4<Integer, Integer, Integer, Integer> testState = new Tuple4<>(0, i, j, k);
                if (j % 4 != 0) {
                    state.setFunctionState(new SerializedStateHandle<Serializable>(testState));
                }
                testState = new Tuple4<>(1, i, j, k);
                state.setOperatorState(new SerializedStateHandle<>(testState));
                if ((0 == k) && (i % 3 != 0)) {
                    HashMap<String, KvStateSnapshot<?, ?, ?, ?>> testKeyedState = new HashMap<>(2);
                    for (int l = 0; l < 2; ++l) {
                        String name = "keyed-" + l;
                        KvStateSnapshot<?, ?, ?, ?> testKeyedSnapshot = new MemValueState.Snapshot<>(IntSerializer.INSTANCE, VoidNamespaceSerializer.INSTANCE, IntSerializer.INSTANCE, new ValueStateDescriptor<>(name, Integer.class, 0), new byte[] { (byte) i, (byte) j });
                        testKeyedState.put(name, testKeyedSnapshot);
                    }
                    state.setKvStates(testKeyedState);
                }
                streamTaskStates[k] = state;
            }
            StreamTaskStateList streamTaskStateList = new StreamTaskStateList(streamTaskStates);
            org.apache.flink.migration.util.SerializedValue<org.apache.flink.migration.runtime.state.StateHandle<?>> handle = new org.apache.flink.migration.util.SerializedValue<org.apache.flink.migration.runtime.state.StateHandle<?>>(streamTaskStateList);
            taskState.putState(j, new org.apache.flink.migration.runtime.checkpoint.SubtaskState(handle, 0, 0));
        }
        taskStates.add(taskState);
    }
    return taskStates;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ArrayList(java.util.ArrayList) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) ChainedStateHandle(org.apache.flink.runtime.state.ChainedStateHandle) SerializedStateHandle(org.apache.flink.migration.runtime.state.memory.SerializedStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) StreamTaskState(org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState) KvStateSnapshot(org.apache.flink.migration.runtime.state.KvStateSnapshot) Tuple4(org.apache.flink.api.java.tuple.Tuple4) KvStateSnapshot(org.apache.flink.migration.runtime.state.KvStateSnapshot) StreamTaskStateList(org.apache.flink.migration.streaming.runtime.tasks.StreamTaskStateList) StreamTaskState(org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState) TaskState(org.apache.flink.runtime.checkpoint.TaskState)

Aggregations

Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Tuple4 (org.apache.flink.api.java.tuple.Tuple4)1 KvStateSnapshot (org.apache.flink.migration.runtime.state.KvStateSnapshot)1 SerializedStateHandle (org.apache.flink.migration.runtime.state.memory.SerializedStateHandle)1 StreamTaskState (org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState)1 StreamTaskStateList (org.apache.flink.migration.streaming.runtime.tasks.StreamTaskStateList)1 TaskState (org.apache.flink.runtime.checkpoint.TaskState)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 ChainedStateHandle (org.apache.flink.runtime.state.ChainedStateHandle)1 KeyGroupsStateHandle (org.apache.flink.runtime.state.KeyGroupsStateHandle)1 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)1 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)1