org.apache.flink.api.common.typeutils.TypeSerializerSerializationUtil Java Examples

The following examples show how to use org.apache.flink.api.common.typeutils.TypeSerializerSerializationUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LegacyStateMetaInfoReaders.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in, @Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final StateDescriptor.Type stateDescType = StateDescriptor.Type.values()[in.readInt()];
	final String stateName = in.readUTF();
	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> serializersAndConfigs =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE.toString(),
		stateDescType.toString());

	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotMap = new HashMap<>(2);
	serializerConfigSnapshotMap.put(StateMetaInfoSnapshot.CommonSerializerKeys.NAMESPACE_SERIALIZER.toString(),
		serializersAndConfigs.get(0).f1);
	serializerConfigSnapshotMap.put(StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
		serializersAndConfigs.get(1).f1);

	return new StateMetaInfoSnapshot(
		stateName,
		StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
		optionsMap,
		serializerConfigSnapshotMap);
}
 
Example #2
Source File: LegacyStateMetaInfoReaders.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in, @Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final StateDescriptor.Type stateDescType = StateDescriptor.Type.values()[in.readInt()];
	final String stateName = in.readUTF();
	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> serializersAndConfigs =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE.toString(),
		stateDescType.toString());

	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotMap = new HashMap<>(2);
	serializerConfigSnapshotMap.put(StateMetaInfoSnapshot.CommonSerializerKeys.NAMESPACE_SERIALIZER.toString(),
		serializersAndConfigs.get(0).f1);
	serializerConfigSnapshotMap.put(StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
		serializersAndConfigs.get(1).f1);

	return new StateMetaInfoSnapshot(
		stateName,
		StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
		optionsMap,
		serializerConfigSnapshotMap);
}
 
Example #3
Source File: LegacyStateMetaInfoReaders.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in, @Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final StateDescriptor.Type stateDescType = StateDescriptor.Type.values()[in.readInt()];
	final String stateName = in.readUTF();
	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> serializersAndConfigs =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE.toString(),
		stateDescType.toString());

	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotMap = new HashMap<>(2);
	serializerConfigSnapshotMap.put(StateMetaInfoSnapshot.CommonSerializerKeys.NAMESPACE_SERIALIZER.toString(),
		serializersAndConfigs.get(0).f1);
	serializerConfigSnapshotMap.put(StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
		serializersAndConfigs.get(1).f1);

	return new StateMetaInfoSnapshot(
		stateName,
		StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
		optionsMap,
		serializerConfigSnapshotMap);
}
 
Example #4
Source File: LegacyStateMetaInfoReaders.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in,
	@Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final StateDescriptor.Type stateDescType = StateDescriptor.Type.values()[in.readInt()];
	final String stateName = in.readUTF();

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE.toString(),
		stateDescType.toString());

	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotMap = new HashMap<>(2);
	serializerConfigSnapshotMap.put(
		StateMetaInfoSnapshot.CommonSerializerKeys.NAMESPACE_SERIALIZER.toString(),
		new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true)));
	serializerConfigSnapshotMap.put(
		StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
		new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true)));

	return new StateMetaInfoSnapshot(
		stateName,
		StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
		optionsMap,
		serializerConfigSnapshotMap);
}
 
Example #5
Source File: InternalTimersSnapshotReaderWriters.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> serializersAndConfigs =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	restoredTimersSnapshot.setKeySerializerSnapshot((TypeSerializerSnapshot<K>) serializersAndConfigs.get(0).f1);
	restoredTimersSnapshot.setNamespaceSerializerSnapshot((TypeSerializerSnapshot<N>) serializersAndConfigs.get(1).f1);
}
 
Example #6
Source File: InternalTimersSnapshotReaderWriters.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException {
	// write key / namespace serializers, and their configuration snapshots
	TypeSerializerSerializationUtil.writeSerializersAndConfigsWithResilience(
		out,
		Arrays.asList(
			Tuple2.of(keySerializer, timersSnapshot.getKeySerializerSnapshot()),
			Tuple2.of(namespaceSerializer, timersSnapshot.getNamespaceSerializerSnapshot())));
}
 
Example #7
Source File: LegacyStateMetaInfoReaders.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in,
	@Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final StateDescriptor.Type stateDescType = StateDescriptor.Type.values()[in.readInt()];
	final String stateName = in.readUTF();

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE.toString(),
		stateDescType.toString());

	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotMap = new HashMap<>(2);
	serializerConfigSnapshotMap.put(
		StateMetaInfoSnapshot.CommonSerializerKeys.NAMESPACE_SERIALIZER.toString(),
		new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true)));
	serializerConfigSnapshotMap.put(
		StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
		new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true)));

	return new StateMetaInfoSnapshot(
		stateName,
		StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
		optionsMap,
		serializerConfigSnapshotMap);
}
 
Example #8
Source File: KryoSerializerCompatibilityTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializingKryoSerializerWithoutAvro() throws Exception {
	final String resource = "serialized-kryo-serializer-1.3";

	TypeSerializer<?> serializer;

	try (InputStream in = getClass().getClassLoader().getResourceAsStream(resource)) {
		DataInputViewStreamWrapper inView = new DataInputViewStreamWrapper(in);

		serializer = TypeSerializerSerializationUtil.tryReadSerializer(inView, getClass().getClassLoader());
	}

	assertNotNull(serializer);
	assertTrue(serializer instanceof KryoSerializer);
}
 
Example #9
Source File: InternalTimersSnapshotReaderWriters.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> serializersAndConfigs =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	restoredTimersSnapshot.setKeySerializerSnapshot((TypeSerializerSnapshot<K>) serializersAndConfigs.get(0).f1);
	restoredTimersSnapshot.setNamespaceSerializerSnapshot((TypeSerializerSnapshot<N>) serializersAndConfigs.get(1).f1);
}
 
Example #10
Source File: InternalTimersSnapshotReaderWriters.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException {
	// write key / namespace serializers, and their configuration snapshots
	TypeSerializerSerializationUtil.writeSerializersAndConfigsWithResilience(
		out,
		Arrays.asList(
			Tuple2.of(keySerializer, timersSnapshot.getKeySerializerSnapshot()),
			Tuple2.of(namespaceSerializer, timersSnapshot.getNamespaceSerializerSnapshot())));
}
 
Example #11
Source File: KryoSerializerCompatibilityTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializingKryoSerializerWithoutAvro() throws Exception {
	final String resource = "serialized-kryo-serializer-1.3";

	TypeSerializer<?> serializer;

	try (InputStream in = getClass().getClassLoader().getResourceAsStream(resource)) {
		DataInputViewStreamWrapper inView = new DataInputViewStreamWrapper(in);

		serializer = TypeSerializerSerializationUtil.tryReadSerializer(inView, getClass().getClassLoader());
	}

	assertNotNull(serializer);
	assertTrue(serializer instanceof KryoSerializer);
}
 
Example #12
Source File: InternalTimersSnapshotReaderWriters.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> serializersAndConfigs =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	restoredTimersSnapshot.setKeySerializerSnapshot((TypeSerializerSnapshot<K>) serializersAndConfigs.get(0).f1);
	restoredTimersSnapshot.setNamespaceSerializerSnapshot((TypeSerializerSnapshot<N>) serializersAndConfigs.get(1).f1);
}
 
Example #13
Source File: InternalTimersSnapshotReaderWriters.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException {
	// write key / namespace serializers, and their configuration snapshots
	TypeSerializerSerializationUtil.writeSerializersAndConfigsWithResilience(
		out,
		Arrays.asList(
			Tuple2.of(keySerializer, timersSnapshot.getKeySerializerSnapshot()),
			Tuple2.of(namespaceSerializer, timersSnapshot.getNamespaceSerializerSnapshot())));
}
 
Example #14
Source File: LegacyStateMetaInfoReaders.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in,
	@Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final StateDescriptor.Type stateDescType = StateDescriptor.Type.values()[in.readInt()];
	final String stateName = in.readUTF();

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.KEYED_STATE_TYPE.toString(),
		stateDescType.toString());

	Map<String, TypeSerializerSnapshot<?>> serializerConfigSnapshotMap = new HashMap<>(2);
	serializerConfigSnapshotMap.put(
		StateMetaInfoSnapshot.CommonSerializerKeys.NAMESPACE_SERIALIZER.toString(),
		new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true)));
	serializerConfigSnapshotMap.put(
		StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
		new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true)));

	return new StateMetaInfoSnapshot(
		stateName,
		StateMetaInfoSnapshot.BackendStateType.KEY_VALUE,
		optionsMap,
		serializerConfigSnapshotMap);
}
 
Example #15
Source File: KryoSerializerCompatibilityTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializingKryoSerializerWithoutAvro() throws Exception {
	final String resource = "serialized-kryo-serializer-1.3";

	TypeSerializer<?> serializer;

	try (InputStream in = getClass().getClassLoader().getResourceAsStream(resource)) {
		DataInputViewStreamWrapper inView = new DataInputViewStreamWrapper(in);

		serializer = TypeSerializerSerializationUtil.tryReadSerializer(inView, getClass().getClassLoader());
	}

	assertNotNull(serializer);
	assertTrue(serializer instanceof KryoSerializer);
}
 
Example #16
Source File: AvroSerializerMigrationTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private static TypeSerializer<?> javaDeserialize(String base64) throws IOException {
	byte[] bytes = Base64.getMimeDecoder().decode(base64);
	DataInputDeserializer in = new DataInputDeserializer(bytes);
	return TypeSerializerSerializationUtil.tryReadSerializer(in, Thread.currentThread().getContextClassLoader());
}
 
Example #17
Source File: LegacyStateMetaInfoReaders.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in,
	@Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final String name = in.readUTF();
	final OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[in.readByte()];

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		mode.toString());

	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> stateSerializerAndConfigList =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	final int listSize = stateSerializerAndConfigList.size();
	StateMetaInfoSnapshot.BackendStateType stateType = listSize == 1 ?
		StateMetaInfoSnapshot.BackendStateType.OPERATOR : StateMetaInfoSnapshot.BackendStateType.BROADCAST;

	Map<String, TypeSerializerSnapshot<?>> serializerConfigsMap = new HashMap<>(listSize);
	switch (stateType) {
		case OPERATOR:
			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(0).f1);
			break;
		case BROADCAST:
			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.KEY_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(0).f1);

			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(1).f1);
			break;
		default:
			throw new IllegalStateException("Unknown operator state type " + stateType);
	}

	return new StateMetaInfoSnapshot(
		name,
		stateType,
		optionsMap,
		serializerConfigsMap);
}
 
Example #18
Source File: KeyedBackendSerializationProxy.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(DataInputView in) throws IOException {
	super.read(in);

	final int readVersion = getReadVersion();

	if (readVersion >= 4) {
		usingKeyGroupCompression = in.readBoolean();
	} else {
		usingKeyGroupCompression = false;
	}

	// only starting from version 3, we have the key serializer and its config snapshot written
	if (readVersion >= 6) {
		this.keySerializerSnapshot = TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(
			in, userCodeClassLoader, null);
	} else if (readVersion >= 3) {
		Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>> keySerializerAndConfig =
				TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader).get(0);
		this.keySerializerSnapshot = (TypeSerializerSnapshot<K>) keySerializerAndConfig.f1;
	} else {
		this.keySerializerSnapshot = new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true));
	}
	this.keySerializer = null;

	Integer metaInfoSnapshotVersion = META_INFO_SNAPSHOT_FORMAT_VERSION_MAPPER.get(readVersion);
	if (metaInfoSnapshotVersion == null) {
		// this should not happen; guard for the future
		throw new IOException("Cannot determine corresponding meta info snapshot version for keyed backend serialization readVersion=" + readVersion);
	}
	final StateMetaInfoReader stateMetaInfoReader = StateMetaInfoSnapshotReadersWriters.getReader(
		metaInfoSnapshotVersion,
		StateMetaInfoSnapshotReadersWriters.StateTypeHint.KEYED_STATE);

	int numKvStates = in.readShort();
	stateMetaInfoSnapshots = new ArrayList<>(numKvStates);
	for (int i = 0; i < numKvStates; i++) {
		StateMetaInfoSnapshot snapshot = stateMetaInfoReader.readStateMetaInfoSnapshot(in, userCodeClassLoader);

		stateMetaInfoSnapshots.add(snapshot);
	}
}
 
Example #19
Source File: AvroSerializerMigrationTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private static TypeSerializer<?> javaDeserialize(String base64) throws IOException {
	byte[] bytes = Base64.getMimeDecoder().decode(base64);
	DataInputDeserializer in = new DataInputDeserializer(bytes);
	return TypeSerializerSerializationUtil.tryReadSerializer(in, Thread.currentThread().getContextClassLoader());
}
 
Example #20
Source File: KeyedBackendSerializationProxy.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(DataInputView in) throws IOException {
	super.read(in);

	final int readVersion = getReadVersion();

	if (readVersion >= 4) {
		usingKeyGroupCompression = in.readBoolean();
	} else {
		usingKeyGroupCompression = false;
	}

	// only starting from version 3, we have the key serializer and its config snapshot written
	if (readVersion >= 6) {
		this.keySerializerSnapshot = TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(
			in, userCodeClassLoader, null);
	} else if (readVersion >= 3) {
		Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>> keySerializerAndConfig =
				TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader).get(0);
		this.keySerializerSnapshot = (TypeSerializerSnapshot<K>) keySerializerAndConfig.f1;
	} else {
		this.keySerializerSnapshot = new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true));
	}
	this.keySerializer = null;

	Integer metaInfoSnapshotVersion = META_INFO_SNAPSHOT_FORMAT_VERSION_MAPPER.get(readVersion);
	if (metaInfoSnapshotVersion == null) {
		// this should not happen; guard for the future
		throw new IOException("Cannot determine corresponding meta info snapshot version for keyed backend serialization readVersion=" + readVersion);
	}
	final StateMetaInfoReader stateMetaInfoReader = StateMetaInfoSnapshotReadersWriters.getReader(
		metaInfoSnapshotVersion,
		StateMetaInfoSnapshotReadersWriters.StateTypeHint.KEYED_STATE);

	int numKvStates = in.readShort();
	stateMetaInfoSnapshots = new ArrayList<>(numKvStates);
	for (int i = 0; i < numKvStates; i++) {
		StateMetaInfoSnapshot snapshot = stateMetaInfoReader.readStateMetaInfoSnapshot(in, userCodeClassLoader);

		stateMetaInfoSnapshots.add(snapshot);
	}
}
 
Example #21
Source File: LegacyStateMetaInfoReaders.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in,
	@Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final String name = in.readUTF();
	final OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[in.readByte()];

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		mode.toString());

	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> stateSerializerAndConfigList =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	final int listSize = stateSerializerAndConfigList.size();
	StateMetaInfoSnapshot.BackendStateType stateType = listSize == 1 ?
		StateMetaInfoSnapshot.BackendStateType.OPERATOR : StateMetaInfoSnapshot.BackendStateType.BROADCAST;

	Map<String, TypeSerializerSnapshot<?>> serializerConfigsMap = new HashMap<>(listSize);
	switch (stateType) {
		case OPERATOR:
			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(0).f1);
			break;
		case BROADCAST:
			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.KEY_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(0).f1);

			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(1).f1);
			break;
		default:
			throw new IllegalStateException("Unknown operator state type " + stateType);
	}

	return new StateMetaInfoSnapshot(
		name,
		stateType,
		optionsMap,
		serializerConfigsMap);
}
 
Example #22
Source File: LegacyStateMetaInfoReaders.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public StateMetaInfoSnapshot readStateMetaInfoSnapshot(
	@Nonnull DataInputView in,
	@Nonnull ClassLoader userCodeClassLoader) throws IOException {

	final String name = in.readUTF();
	final OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[in.readByte()];

	Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		mode.toString());

	List<Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>>> stateSerializerAndConfigList =
		TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader);

	final int listSize = stateSerializerAndConfigList.size();
	StateMetaInfoSnapshot.BackendStateType stateType = listSize == 1 ?
		StateMetaInfoSnapshot.BackendStateType.OPERATOR : StateMetaInfoSnapshot.BackendStateType.BROADCAST;

	Map<String, TypeSerializerSnapshot<?>> serializerConfigsMap = new HashMap<>(listSize);
	switch (stateType) {
		case OPERATOR:
			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(0).f1);
			break;
		case BROADCAST:
			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.KEY_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(0).f1);

			serializerConfigsMap.put(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				stateSerializerAndConfigList.get(1).f1);
			break;
		default:
			throw new IllegalStateException("Unknown operator state type " + stateType);
	}

	return new StateMetaInfoSnapshot(
		name,
		stateType,
		optionsMap,
		serializerConfigsMap);
}
 
Example #23
Source File: KeyedBackendSerializationProxy.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(DataInputView in) throws IOException {
	super.read(in);

	final int readVersion = getReadVersion();

	if (readVersion >= 4) {
		usingKeyGroupCompression = in.readBoolean();
	} else {
		usingKeyGroupCompression = false;
	}

	// only starting from version 3, we have the key serializer and its config snapshot written
	if (readVersion >= 6) {
		this.keySerializerSnapshot = TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(
			in, userCodeClassLoader, null);
	} else if (readVersion >= 3) {
		Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>> keySerializerAndConfig =
				TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader).get(0);
		this.keySerializerSnapshot = (TypeSerializerSnapshot<K>) keySerializerAndConfig.f1;
	} else {
		this.keySerializerSnapshot = new BackwardsCompatibleSerializerSnapshot<>(
			TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true));
	}
	this.keySerializer = null;

	Integer metaInfoSnapshotVersion = META_INFO_SNAPSHOT_FORMAT_VERSION_MAPPER.get(readVersion);
	if (metaInfoSnapshotVersion == null) {
		// this should not happen; guard for the future
		throw new IOException("Cannot determine corresponding meta info snapshot version for keyed backend serialization readVersion=" + readVersion);
	}
	final StateMetaInfoReader stateMetaInfoReader = StateMetaInfoSnapshotReadersWriters.getReader(
		metaInfoSnapshotVersion,
		StateMetaInfoSnapshotReadersWriters.StateTypeHint.KEYED_STATE);

	int numKvStates = in.readShort();
	stateMetaInfoSnapshots = new ArrayList<>(numKvStates);
	for (int i = 0; i < numKvStates; i++) {
		StateMetaInfoSnapshot snapshot = stateMetaInfoReader.readStateMetaInfoSnapshot(in, userCodeClassLoader);

		stateMetaInfoSnapshots.add(snapshot);
	}
}