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

The following examples show how to use org.apache.flink.api.common.typeutils.BackwardsCompatibleSerializerSnapshot. 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: InternalTimersSnapshotReaderWriters.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	DataInputViewStream dis = new DataInputViewStream(in);
	try {
		final TypeSerializer<K> keySerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);
		final TypeSerializer<N> namespaceSerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);

		restoredTimersSnapshot.setKeySerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(keySerializer));
		restoredTimersSnapshot.setNamespaceSerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(namespaceSerializer));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	}
}
 
Example #2
Source File: InternalTimersSnapshotReaderWriters.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	DataInputViewStream dis = new DataInputViewStream(in);
	try {
		final TypeSerializer<K> keySerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);
		final TypeSerializer<N> namespaceSerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);

		restoredTimersSnapshot.setKeySerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(keySerializer));
		restoredTimersSnapshot.setNamespaceSerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(namespaceSerializer));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	}
}
 
Example #3
Source File: InternalTimersSnapshotReaderWriters.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void restoreKeyAndNamespaceSerializers(
		InternalTimersSnapshot<K, N> restoredTimersSnapshot,
		DataInputView in) throws IOException {

	DataInputViewStream dis = new DataInputViewStream(in);
	try {
		final TypeSerializer<K> keySerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);
		final TypeSerializer<N> namespaceSerializer = InstantiationUtil.deserializeObject(dis, userCodeClassLoader, true);

		restoredTimersSnapshot.setKeySerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(keySerializer));
		restoredTimersSnapshot.setNamespaceSerializerSnapshot(new BackwardsCompatibleSerializerSnapshot<>(namespaceSerializer));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	}
}
 
Example #4
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 #5
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 String name = in.readUTF();
	final OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[in.readByte()];
	final Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		mode.toString());

	DataInputViewStream dis = new DataInputViewStream(in);
	ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();

	try (
		InstantiationUtil.FailureTolerantObjectInputStream ois =
			new InstantiationUtil.FailureTolerantObjectInputStream(dis, userCodeClassLoader)) {
		Thread.currentThread().setContextClassLoader(userCodeClassLoader);
		TypeSerializer<?> stateSerializer = (TypeSerializer<?>) ois.readObject();
		return new StateMetaInfoSnapshot(
			name,
			StateMetaInfoSnapshot.BackendStateType.OPERATOR,
			optionsMap,
			Collections.singletonMap(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				new BackwardsCompatibleSerializerSnapshot<>(stateSerializer)));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	} finally {
		Thread.currentThread().setContextClassLoader(previousClassLoader);
	}
}
 
Example #6
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 #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 String name = in.readUTF();
	final OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[in.readByte()];
	final Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		mode.toString());

	DataInputViewStream dis = new DataInputViewStream(in);
	ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();

	try (
		InstantiationUtil.FailureTolerantObjectInputStream ois =
			new InstantiationUtil.FailureTolerantObjectInputStream(dis, userCodeClassLoader)) {
		Thread.currentThread().setContextClassLoader(userCodeClassLoader);
		TypeSerializer<?> stateSerializer = (TypeSerializer<?>) ois.readObject();
		return new StateMetaInfoSnapshot(
			name,
			StateMetaInfoSnapshot.BackendStateType.OPERATOR,
			optionsMap,
			Collections.singletonMap(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				new BackwardsCompatibleSerializerSnapshot<>(stateSerializer)));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	} finally {
		Thread.currentThread().setContextClassLoader(previousClassLoader);
	}
}
 
Example #8
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 #9
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 String name = in.readUTF();
	final OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[in.readByte()];
	final Map<String, String> optionsMap = Collections.singletonMap(
		StateMetaInfoSnapshot.CommonOptionsKeys.OPERATOR_STATE_DISTRIBUTION_MODE.toString(),
		mode.toString());

	DataInputViewStream dis = new DataInputViewStream(in);
	ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();

	try (
		InstantiationUtil.FailureTolerantObjectInputStream ois =
			new InstantiationUtil.FailureTolerantObjectInputStream(dis, userCodeClassLoader)) {
		Thread.currentThread().setContextClassLoader(userCodeClassLoader);
		TypeSerializer<?> stateSerializer = (TypeSerializer<?>) ois.readObject();
		return new StateMetaInfoSnapshot(
			name,
			StateMetaInfoSnapshot.BackendStateType.OPERATOR,
			optionsMap,
			Collections.singletonMap(
				StateMetaInfoSnapshot.CommonSerializerKeys.VALUE_SERIALIZER.toString(),
				new BackwardsCompatibleSerializerSnapshot<>(stateSerializer)));
	} catch (ClassNotFoundException exception) {
		throw new IOException(exception);
	} finally {
		Thread.currentThread().setContextClassLoader(previousClassLoader);
	}
}
 
Example #10
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 #11
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 #12
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);
	}
}