Search in sources :

Example 1 with StateHandle

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

the class SavepointV0Serializer method convertSubtaskState.

private org.apache.flink.runtime.checkpoint.SubtaskState convertSubtaskState(SubtaskState subtaskState, int parallelInstanceIdx, ClassLoader userClassLoader, long checkpointID) throws Exception {
    SerializedValue<StateHandle<?>> serializedValue = subtaskState.getState();
    StreamTaskStateList stateList = (StreamTaskStateList) serializedValue.deserializeValue(userClassLoader);
    StreamTaskState[] streamTaskStates = stateList.getState(userClassLoader);
    List<StreamStateHandle> newChainStateList = Arrays.asList(new StreamStateHandle[streamTaskStates.length]);
    KeyGroupsStateHandle newKeyedState = null;
    for (int chainIdx = 0; chainIdx < streamTaskStates.length; ++chainIdx) {
        StreamTaskState streamTaskState = streamTaskStates[chainIdx];
        if (streamTaskState == null) {
            continue;
        }
        newChainStateList.set(chainIdx, convertOperatorAndFunctionState(streamTaskState));
        HashMap<String, KvStateSnapshot<?, ?, ?, ?>> oldKeyedState = streamTaskState.getKvStates();
        if (null != oldKeyedState) {
            Preconditions.checkState(null == newKeyedState, "Found more than one keyed state in chain");
            newKeyedState = convertKeyedBackendState(oldKeyedState, parallelInstanceIdx, checkpointID);
        }
    }
    ChainedStateHandle<StreamStateHandle> newChainedState = new ChainedStateHandle<>(newChainStateList);
    ChainedStateHandle<OperatorStateHandle> nopChain = new ChainedStateHandle<>(Arrays.asList(new OperatorStateHandle[newChainedState.getLength()]));
    return new org.apache.flink.runtime.checkpoint.SubtaskState(newChainedState, nopChain, nopChain, newKeyedState, null);
}
Also used : KvStateSnapshot(org.apache.flink.migration.runtime.state.KvStateSnapshot) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) ChainedStateHandle(org.apache.flink.runtime.state.ChainedStateHandle) MigrationStreamStateHandle(org.apache.flink.migration.state.MigrationStreamStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) MultiStreamStateHandle(org.apache.flink.runtime.state.MultiStreamStateHandle) SubtaskState(org.apache.flink.migration.runtime.checkpoint.SubtaskState) StreamTaskStateList(org.apache.flink.migration.streaming.runtime.tasks.StreamTaskStateList) MigrationKeyGroupStateHandle(org.apache.flink.migration.state.MigrationKeyGroupStateHandle) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) ChainedStateHandle(org.apache.flink.runtime.state.ChainedStateHandle) FileStateHandle(org.apache.flink.runtime.state.filesystem.FileStateHandle) AbstractFileStateHandle(org.apache.flink.migration.runtime.state.filesystem.AbstractFileStateHandle) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) MigrationStreamStateHandle(org.apache.flink.migration.state.MigrationStreamStateHandle) SerializedStateHandle(org.apache.flink.migration.runtime.state.memory.SerializedStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) StateHandle(org.apache.flink.migration.runtime.state.StateHandle) MultiStreamStateHandle(org.apache.flink.runtime.state.MultiStreamStateHandle) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) StreamTaskState(org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState)

Example 2 with StateHandle

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

the class SavepointV0Serializer method deserialize.

@Override
public SavepointV1 deserialize(DataInputStream dis, ClassLoader userClassLoader) throws IOException {
    long checkpointId = dis.readLong();
    // Task states
    int numTaskStates = dis.readInt();
    List<TaskState> taskStates = new ArrayList<>(numTaskStates);
    for (int i = 0; i < numTaskStates; i++) {
        JobVertexID jobVertexId = new JobVertexID(dis.readLong(), dis.readLong());
        int parallelism = dis.readInt();
        // Add task state
        TaskState taskState = new TaskState(jobVertexId, parallelism);
        taskStates.add(taskState);
        // Sub task states
        int numSubTaskStates = dis.readInt();
        for (int j = 0; j < numSubTaskStates; j++) {
            int subtaskIndex = dis.readInt();
            SerializedValue<StateHandle<?>> serializedValue = readSerializedValueStateHandle(dis);
            long stateSize = dis.readLong();
            long duration = dis.readLong();
            SubtaskState subtaskState = new SubtaskState(serializedValue, stateSize, duration);
            taskState.putState(subtaskIndex, subtaskState);
        }
        // Key group states
        int numKvStates = dis.readInt();
        for (int j = 0; j < numKvStates; j++) {
            int keyGroupIndex = dis.readInt();
            SerializedValue<StateHandle<?>> serializedValue = readSerializedValueStateHandle(dis);
            long stateSize = dis.readLong();
            long duration = dis.readLong();
            KeyGroupState keyGroupState = new KeyGroupState(serializedValue, stateSize, duration);
            taskState.putKvState(keyGroupIndex, keyGroupState);
        }
    }
    try {
        return convertSavepoint(taskStates, userClassLoader, checkpointId);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : SubtaskState(org.apache.flink.migration.runtime.checkpoint.SubtaskState) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ArrayList(java.util.ArrayList) MigrationKeyGroupStateHandle(org.apache.flink.migration.state.MigrationKeyGroupStateHandle) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) ChainedStateHandle(org.apache.flink.runtime.state.ChainedStateHandle) FileStateHandle(org.apache.flink.runtime.state.filesystem.FileStateHandle) AbstractFileStateHandle(org.apache.flink.migration.runtime.state.filesystem.AbstractFileStateHandle) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) MigrationStreamStateHandle(org.apache.flink.migration.state.MigrationStreamStateHandle) SerializedStateHandle(org.apache.flink.migration.runtime.state.memory.SerializedStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) StateHandle(org.apache.flink.migration.runtime.state.StateHandle) MultiStreamStateHandle(org.apache.flink.runtime.state.MultiStreamStateHandle) KeyGroupState(org.apache.flink.migration.runtime.checkpoint.KeyGroupState) IOException(java.io.IOException) StreamTaskState(org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState) TaskState(org.apache.flink.migration.runtime.checkpoint.TaskState) IOException(java.io.IOException)

Aggregations

SubtaskState (org.apache.flink.migration.runtime.checkpoint.SubtaskState)2 StateHandle (org.apache.flink.migration.runtime.state.StateHandle)2 AbstractFileStateHandle (org.apache.flink.migration.runtime.state.filesystem.AbstractFileStateHandle)2 SerializedStateHandle (org.apache.flink.migration.runtime.state.memory.SerializedStateHandle)2 MigrationKeyGroupStateHandle (org.apache.flink.migration.state.MigrationKeyGroupStateHandle)2 MigrationStreamStateHandle (org.apache.flink.migration.state.MigrationStreamStateHandle)2 StreamTaskState (org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState)2 ChainedStateHandle (org.apache.flink.runtime.state.ChainedStateHandle)2 KeyGroupsStateHandle (org.apache.flink.runtime.state.KeyGroupsStateHandle)2 MultiStreamStateHandle (org.apache.flink.runtime.state.MultiStreamStateHandle)2 OperatorStateHandle (org.apache.flink.runtime.state.OperatorStateHandle)2 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)2 FileStateHandle (org.apache.flink.runtime.state.filesystem.FileStateHandle)2 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 KeyGroupState (org.apache.flink.migration.runtime.checkpoint.KeyGroupState)1 TaskState (org.apache.flink.migration.runtime.checkpoint.TaskState)1 KvStateSnapshot (org.apache.flink.migration.runtime.state.KvStateSnapshot)1 StreamTaskStateList (org.apache.flink.migration.streaming.runtime.tasks.StreamTaskStateList)1