Search in sources :

Example 1 with KeyGroupState

use of org.apache.flink.migration.runtime.checkpoint.KeyGroupState in project flink by apache.

the class SavepointV0Serializer method serializeOld.

@VisibleForTesting
public void serializeOld(SavepointV0 savepoint, DataOutputStream dos) throws IOException {
    dos.writeLong(savepoint.getCheckpointId());
    Collection<org.apache.flink.migration.runtime.checkpoint.TaskState> taskStates = savepoint.getOldTaskStates();
    dos.writeInt(taskStates.size());
    for (org.apache.flink.migration.runtime.checkpoint.TaskState taskState : savepoint.getOldTaskStates()) {
        // Vertex ID
        dos.writeLong(taskState.getJobVertexID().getLowerPart());
        dos.writeLong(taskState.getJobVertexID().getUpperPart());
        // Parallelism
        int parallelism = taskState.getParallelism();
        dos.writeInt(parallelism);
        // Sub task states
        dos.writeInt(taskState.getNumberCollectedStates());
        for (int i = 0; i < parallelism; i++) {
            SubtaskState subtaskState = taskState.getState(i);
            if (subtaskState != null) {
                dos.writeInt(i);
                SerializedValue<?> serializedValue = subtaskState.getState();
                if (serializedValue == null) {
                    // null
                    dos.writeInt(-1);
                } else {
                    byte[] serialized = serializedValue.getByteArray();
                    dos.writeInt(serialized.length);
                    dos.write(serialized, 0, serialized.length);
                }
                dos.writeLong(subtaskState.getStateSize());
                dos.writeLong(subtaskState.getDuration());
            }
        }
        // Key group states
        dos.writeInt(taskState.getNumberCollectedKvStates());
        for (int i = 0; i < parallelism; i++) {
            KeyGroupState keyGroupState = taskState.getKvState(i);
            if (keyGroupState != null) {
                dos.write(i);
                SerializedValue<?> serializedValue = keyGroupState.getKeyGroupState();
                if (serializedValue == null) {
                    // null
                    dos.writeInt(-1);
                } else {
                    byte[] serialized = serializedValue.getByteArray();
                    dos.writeInt(serialized.length);
                    dos.write(serialized, 0, serialized.length);
                }
                dos.writeLong(keyGroupState.getStateSize());
                dos.writeLong(keyGroupState.getDuration());
            }
        }
    }
}
Also used : SubtaskState(org.apache.flink.migration.runtime.checkpoint.SubtaskState) TaskState(org.apache.flink.migration.runtime.checkpoint.TaskState) KeyGroupState(org.apache.flink.migration.runtime.checkpoint.KeyGroupState) StreamTaskState(org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState) TaskState(org.apache.flink.migration.runtime.checkpoint.TaskState) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 2 with KeyGroupState

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

KeyGroupState (org.apache.flink.migration.runtime.checkpoint.KeyGroupState)2 SubtaskState (org.apache.flink.migration.runtime.checkpoint.SubtaskState)2 TaskState (org.apache.flink.migration.runtime.checkpoint.TaskState)2 StreamTaskState (org.apache.flink.migration.streaming.runtime.tasks.StreamTaskState)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 StateHandle (org.apache.flink.migration.runtime.state.StateHandle)1 AbstractFileStateHandle (org.apache.flink.migration.runtime.state.filesystem.AbstractFileStateHandle)1 SerializedStateHandle (org.apache.flink.migration.runtime.state.memory.SerializedStateHandle)1 MigrationKeyGroupStateHandle (org.apache.flink.migration.state.MigrationKeyGroupStateHandle)1 MigrationStreamStateHandle (org.apache.flink.migration.state.MigrationStreamStateHandle)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 MultiStreamStateHandle (org.apache.flink.runtime.state.MultiStreamStateHandle)1 OperatorStateHandle (org.apache.flink.runtime.state.OperatorStateHandle)1 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)1 FileStateHandle (org.apache.flink.runtime.state.filesystem.FileStateHandle)1 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)1