use of org.apache.flink.api.common.typeutils.base.VoidSerializer in project flink by apache.
the class AbstractMigrationRestoreStrategy method deserialize.
@Override
public StateTable<K, N, S> deserialize(String stateName, HeapKeyedStateBackend<K> stateBackend) throws IOException {
Preconditions.checkNotNull(stateName, "State name is null. Cannot deserialize snapshot.");
Preconditions.checkNotNull(stateBackend, "State backend is null. Cannot deserialize snapshot.");
final KeyGroupRange keyGroupRange = stateBackend.getKeyGroupRange();
Preconditions.checkState(1 == keyGroupRange.getNumberOfKeyGroups(), "Unexpected number of key-groups for restoring from Flink 1.1");
TypeSerializer<N> patchedNamespaceSerializer = this.namespaceSerializer;
if (patchedNamespaceSerializer instanceof VoidSerializer) {
patchedNamespaceSerializer = (TypeSerializer<N>) VoidNamespaceSerializer.INSTANCE;
}
RegisteredBackendStateMetaInfo<N, S> registeredBackendStateMetaInfo = new RegisteredBackendStateMetaInfo<>(StateDescriptor.Type.UNKNOWN, stateName, patchedNamespaceSerializer, stateSerializer);
final StateTable<K, N, S> stateTable = stateBackend.newStateTable(registeredBackendStateMetaInfo);
final DataInputView inView = openDataInputView();
final int keyGroup = keyGroupRange.getStartKeyGroup();
final int numNamespaces = inView.readInt();
for (int i = 0; i < numNamespaces; i++) {
N namespace = namespaceSerializer.deserialize(inView);
if (null == namespace) {
namespace = (N) VoidNamespace.INSTANCE;
}
final int numKV = inView.readInt();
for (int j = 0; j < numKV; j++) {
K key = keySerializer.deserialize(inView);
S value = stateSerializer.deserialize(inView);
stateTable.put(key, keyGroup, namespace, value);
}
}
return stateTable;
}
Aggregations