Search in sources :

Example 1 with MigrationRestoreSnapshot

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

the class HeapKeyedStateBackend method restoreOldSavepointKeyedState.

@SuppressWarnings({ "unchecked", "rawtypes", "DeprecatedIsStillUsed" })
@Deprecated
private void restoreOldSavepointKeyedState(Collection<KeyGroupsStateHandle> stateHandles) throws IOException, ClassNotFoundException {
    if (stateHandles.isEmpty()) {
        return;
    }
    Preconditions.checkState(1 == stateHandles.size(), "Only one element expected here.");
    HashMap<String, KvStateSnapshot<K, ?, ?, ?>> namedStates;
    try (FSDataInputStream inputStream = stateHandles.iterator().next().openInputStream()) {
        namedStates = InstantiationUtil.deserializeObject(inputStream, userCodeClassLoader);
    }
    for (Map.Entry<String, KvStateSnapshot<K, ?, ?, ?>> nameToState : namedStates.entrySet()) {
        final String stateName = nameToState.getKey();
        final KvStateSnapshot<K, ?, ?, ?> genericSnapshot = nameToState.getValue();
        if (genericSnapshot instanceof MigrationRestoreSnapshot) {
            MigrationRestoreSnapshot<K, ?, ?> stateSnapshot = (MigrationRestoreSnapshot<K, ?, ?>) genericSnapshot;
            final StateTable rawResultMap = stateSnapshot.deserialize(stateName, this);
            // add named state to the backend
            stateTables.put(stateName, rawResultMap);
        } else {
            throw new IllegalStateException("Unknown state: " + genericSnapshot);
        }
    }
}
Also used : MigrationRestoreSnapshot(org.apache.flink.migration.runtime.state.memory.MigrationRestoreSnapshot) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) KvStateSnapshot(org.apache.flink.migration.runtime.state.KvStateSnapshot) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1 KvStateSnapshot (org.apache.flink.migration.runtime.state.KvStateSnapshot)1 MigrationRestoreSnapshot (org.apache.flink.migration.runtime.state.memory.MigrationRestoreSnapshot)1