Search in sources :

Example 1 with UnloadableDummyTypeSerializer

use of org.apache.flink.api.common.typeutils.UnloadableDummyTypeSerializer in project flink by apache.

the class OperatorStateRestoreOperation method restore.

@Override
public Void restore() throws Exception {
    if (stateHandles.isEmpty()) {
        return null;
    }
    for (OperatorStateHandle stateHandle : stateHandles) {
        if (stateHandle == null) {
            continue;
        }
        FSDataInputStream in = stateHandle.openInputStream();
        closeStreamOnCancelRegistry.registerCloseable(in);
        ClassLoader restoreClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(userClassloader);
            OperatorBackendSerializationProxy backendSerializationProxy = new OperatorBackendSerializationProxy(userClassloader);
            backendSerializationProxy.read(new DataInputViewStreamWrapper(in));
            List<StateMetaInfoSnapshot> restoredOperatorMetaInfoSnapshots = backendSerializationProxy.getOperatorStateMetaInfoSnapshots();
            // Recreate all PartitionableListStates from the meta info
            for (StateMetaInfoSnapshot restoredSnapshot : restoredOperatorMetaInfoSnapshots) {
                final RegisteredOperatorStateBackendMetaInfo<?> restoredMetaInfo = new RegisteredOperatorStateBackendMetaInfo<>(restoredSnapshot);
                if (restoredMetaInfo.getPartitionStateSerializer() instanceof UnloadableDummyTypeSerializer) {
                    throw new IOException("Unable to restore operator state [" + restoredSnapshot.getName() + "]." + " The previous typeSerializer of the operator state must be present; the typeSerializer could" + " have been removed from the classpath, or its implementation have changed and could" + " not be loaded. This is a temporary restriction that will be fixed in future versions.");
                }
                PartitionableListState<?> listState = registeredOperatorStates.get(restoredSnapshot.getName());
                if (null == listState) {
                    listState = new PartitionableListState<>(restoredMetaInfo);
                    registeredOperatorStates.put(listState.getStateMetaInfo().getName(), listState);
                } else {
                // TODO with eager state registration in place, check here for
                // typeSerializer migration strategies
                }
            }
            // ... and then get back the broadcast state.
            List<StateMetaInfoSnapshot> restoredBroadcastMetaInfoSnapshots = backendSerializationProxy.getBroadcastStateMetaInfoSnapshots();
            for (StateMetaInfoSnapshot restoredSnapshot : restoredBroadcastMetaInfoSnapshots) {
                final RegisteredBroadcastStateBackendMetaInfo<?, ?> restoredMetaInfo = new RegisteredBroadcastStateBackendMetaInfo<>(restoredSnapshot);
                if (restoredMetaInfo.getKeySerializer() instanceof UnloadableDummyTypeSerializer || restoredMetaInfo.getValueSerializer() instanceof UnloadableDummyTypeSerializer) {
                    throw new IOException("Unable to restore broadcast state [" + restoredSnapshot.getName() + "]." + " The previous key and value serializers of the state must be present; the serializers could" + " have been removed from the classpath, or their implementations have changed and could" + " not be loaded. This is a temporary restriction that will be fixed in future versions.");
                }
                BackendWritableBroadcastState<?, ?> broadcastState = registeredBroadcastStates.get(restoredSnapshot.getName());
                if (broadcastState == null) {
                    broadcastState = new HeapBroadcastState<>(restoredMetaInfo);
                    registeredBroadcastStates.put(broadcastState.getStateMetaInfo().getName(), broadcastState);
                } else {
                // TODO with eager state registration in place, check here for
                // typeSerializer migration strategies
                }
            }
            // Restore all the states
            for (Map.Entry<String, OperatorStateHandle.StateMetaInfo> nameToOffsets : stateHandle.getStateNameToPartitionOffsets().entrySet()) {
                final String stateName = nameToOffsets.getKey();
                PartitionableListState<?> listStateForName = registeredOperatorStates.get(stateName);
                if (listStateForName == null) {
                    BackendWritableBroadcastState<?, ?> broadcastStateForName = registeredBroadcastStates.get(stateName);
                    Preconditions.checkState(broadcastStateForName != null, "Found state without " + "corresponding meta info: " + stateName);
                    deserializeBroadcastStateValues(broadcastStateForName, in, nameToOffsets.getValue());
                } else {
                    deserializeOperatorStateValues(listStateForName, in, nameToOffsets.getValue());
                }
            }
        } finally {
            Thread.currentThread().setContextClassLoader(restoreClassLoader);
            if (closeStreamOnCancelRegistry.unregisterCloseable(in)) {
                IOUtils.closeQuietly(in);
            }
        }
    }
    return null;
}
Also used : UnloadableDummyTypeSerializer(org.apache.flink.api.common.typeutils.UnloadableDummyTypeSerializer) StateMetaInfoSnapshot(org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot) IOException(java.io.IOException) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 Map (java.util.Map)1 UnloadableDummyTypeSerializer (org.apache.flink.api.common.typeutils.UnloadableDummyTypeSerializer)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1 DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)1 StateMetaInfoSnapshot (org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot)1