Search in sources :

Example 1 with MigrationKeyGroupStateHandle

use of org.apache.flink.migration.state.MigrationKeyGroupStateHandle in project flink by apache.

the class SavepointV0Serializer method convertKeyedBackendState.

/**
	 * This is public so that we can use it when restoring a legacy snapshot
	 * in {@code AbstractStreamOperatorTestHarness}.
	 */
public static KeyGroupsStateHandle convertKeyedBackendState(HashMap<String, KvStateSnapshot<?, ?, ?, ?>> oldKeyedState, int parallelInstanceIdx, long checkpointID) throws Exception {
    if (null != oldKeyedState) {
        CheckpointStreamFactory checkpointStreamFactory = new MemCheckpointStreamFactory(MAX_SIZE);
        CheckpointStreamFactory.CheckpointStateOutputStream keyedStateOut = checkpointStreamFactory.createCheckpointStateOutputStream(checkpointID, 0L);
        try {
            final long offset = keyedStateOut.getPos();
            InstantiationUtil.serializeObject(keyedStateOut, oldKeyedState);
            StreamStateHandle streamStateHandle = keyedStateOut.closeAndGetHandle();
            // makes IOUtils.closeQuietly(...) ignore this
            keyedStateOut = null;
            if (null != streamStateHandle) {
                KeyGroupRangeOffsets keyGroupRangeOffsets = new KeyGroupRangeOffsets(parallelInstanceIdx, parallelInstanceIdx, new long[] { offset });
                return new MigrationKeyGroupStateHandle(keyGroupRangeOffsets, streamStateHandle);
            }
        } finally {
            IOUtils.closeQuietly(keyedStateOut);
        }
    }
    return null;
}
Also used : MemCheckpointStreamFactory(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory) MigrationKeyGroupStateHandle(org.apache.flink.migration.state.MigrationKeyGroupStateHandle) 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) MemCheckpointStreamFactory(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory) CheckpointStreamFactory(org.apache.flink.runtime.state.CheckpointStreamFactory) KeyGroupRangeOffsets(org.apache.flink.runtime.state.KeyGroupRangeOffsets)

Aggregations

MigrationKeyGroupStateHandle (org.apache.flink.migration.state.MigrationKeyGroupStateHandle)1 MigrationStreamStateHandle (org.apache.flink.migration.state.MigrationStreamStateHandle)1 CheckpointStreamFactory (org.apache.flink.runtime.state.CheckpointStreamFactory)1 KeyGroupRangeOffsets (org.apache.flink.runtime.state.KeyGroupRangeOffsets)1 MultiStreamStateHandle (org.apache.flink.runtime.state.MultiStreamStateHandle)1 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)1 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)1 MemCheckpointStreamFactory (org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory)1