Java Code Examples for org.apache.flink.runtime.state.OperatorStateHandle#Mode

The following examples show how to use org.apache.flink.runtime.state.OperatorStateHandle#Mode . 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: SavepointV1Serializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static OperatorStateHandle deserializeOperatorStateHandle(
		DataInputStream dis) throws IOException {

	final int type = dis.readByte();
	if (NULL_HANDLE == type) {
		return null;
	} else if (PARTITIONABLE_OPERATOR_STATE_HANDLE == type) {
		int mapSize = dis.readInt();
		Map<String, OperatorStateHandle.StateMetaInfo> offsetsMap = new HashMap<>(mapSize);
		for (int i = 0; i < mapSize; ++i) {
			String key = dis.readUTF();

			int modeOrdinal = dis.readByte();
			OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[modeOrdinal];

			long[] offsets = new long[dis.readInt()];
			for (int j = 0; j < offsets.length; ++j) {
				offsets[j] = dis.readLong();
			}

			OperatorStateHandle.StateMetaInfo metaInfo =
					new OperatorStateHandle.StateMetaInfo(offsets, mode);
			offsetsMap.put(key, metaInfo);
		}
		StreamStateHandle stateHandle = deserializeStreamStateHandle(dis);
		return new OperatorStreamStateHandle(offsetsMap, stateHandle);
	} else {
		throw new IllegalStateException("Reading invalid OperatorStateHandle, type: " + type);
	}
}
 
Example 2
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 3
Source File: MetadataV2V3SerializerBase.java    From flink with Apache License 2.0 5 votes vote down vote up
OperatorStateHandle deserializeOperatorStateHandle(
		DataInputStream dis,
		@Nullable DeserializationContext context) throws IOException {

	final int type = dis.readByte();
	if (NULL_HANDLE == type) {
		return null;
	} else if (PARTITIONABLE_OPERATOR_STATE_HANDLE == type) {
		int mapSize = dis.readInt();
		Map<String, OperatorStateHandle.StateMetaInfo> offsetsMap = new HashMap<>(mapSize);
		for (int i = 0; i < mapSize; ++i) {
			String key = dis.readUTF();

			int modeOrdinal = dis.readByte();
			OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[modeOrdinal];

			long[] offsets = new long[dis.readInt()];
			for (int j = 0; j < offsets.length; ++j) {
				offsets[j] = dis.readLong();
			}

			OperatorStateHandle.StateMetaInfo metaInfo =
					new OperatorStateHandle.StateMetaInfo(offsets, mode);
			offsetsMap.put(key, metaInfo);
		}
		StreamStateHandle stateHandle = deserializeStreamStateHandle(dis, context);
		return new OperatorStreamStateHandle(offsetsMap, stateHandle);
	} else {
		throw new IllegalStateException("Reading invalid OperatorStateHandle, type: " + type);
	}
}
 
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 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 5
Source File: SavepointV1Serializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static OperatorStateHandle deserializeOperatorStateHandle(
		DataInputStream dis) throws IOException {

	final int type = dis.readByte();
	if (NULL_HANDLE == type) {
		return null;
	} else if (PARTITIONABLE_OPERATOR_STATE_HANDLE == type) {
		int mapSize = dis.readInt();
		Map<String, OperatorStateHandle.StateMetaInfo> offsetsMap = new HashMap<>(mapSize);
		for (int i = 0; i < mapSize; ++i) {
			String key = dis.readUTF();

			int modeOrdinal = dis.readByte();
			OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[modeOrdinal];

			long[] offsets = new long[dis.readInt()];
			for (int j = 0; j < offsets.length; ++j) {
				offsets[j] = dis.readLong();
			}

			OperatorStateHandle.StateMetaInfo metaInfo =
					new OperatorStateHandle.StateMetaInfo(offsets, mode);
			offsetsMap.put(key, metaInfo);
		}
		StreamStateHandle stateHandle = deserializeStreamStateHandle(dis);
		return new OperatorStreamStateHandle(offsetsMap, stateHandle);
	} else {
		throw new IllegalStateException("Reading invalid OperatorStateHandle, type: " + type);
	}
}
 
Example 6
Source File: SavepointV2Serializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static OperatorStateHandle deserializeOperatorStateHandle(
		DataInputStream dis) throws IOException {

	final int type = dis.readByte();
	if (NULL_HANDLE == type) {
		return null;
	} else if (PARTITIONABLE_OPERATOR_STATE_HANDLE == type) {
		int mapSize = dis.readInt();
		Map<String, OperatorStateHandle.StateMetaInfo> offsetsMap = new HashMap<>(mapSize);
		for (int i = 0; i < mapSize; ++i) {
			String key = dis.readUTF();

			int modeOrdinal = dis.readByte();
			OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[modeOrdinal];

			long[] offsets = new long[dis.readInt()];
			for (int j = 0; j < offsets.length; ++j) {
				offsets[j] = dis.readLong();
			}

			OperatorStateHandle.StateMetaInfo metaInfo =
					new OperatorStateHandle.StateMetaInfo(offsets, mode);
			offsetsMap.put(key, metaInfo);
		}
		StreamStateHandle stateHandle = deserializeStreamStateHandle(dis);
		return new OperatorStreamStateHandle(offsetsMap, stateHandle);
	} else {
		throw new IllegalStateException("Reading invalid OperatorStateHandle, type: " + type);
	}
}
 
Example 7
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 8
Source File: SavepointV2Serializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static OperatorStateHandle deserializeOperatorStateHandle(
		DataInputStream dis) throws IOException {

	final int type = dis.readByte();
	if (NULL_HANDLE == type) {
		return null;
	} else if (PARTITIONABLE_OPERATOR_STATE_HANDLE == type) {
		int mapSize = dis.readInt();
		Map<String, OperatorStateHandle.StateMetaInfo> offsetsMap = new HashMap<>(mapSize);
		for (int i = 0; i < mapSize; ++i) {
			String key = dis.readUTF();

			int modeOrdinal = dis.readByte();
			OperatorStateHandle.Mode mode = OperatorStateHandle.Mode.values()[modeOrdinal];

			long[] offsets = new long[dis.readInt()];
			for (int j = 0; j < offsets.length; ++j) {
				offsets[j] = dis.readLong();
			}

			OperatorStateHandle.StateMetaInfo metaInfo =
					new OperatorStateHandle.StateMetaInfo(offsets, mode);
			offsetsMap.put(key, metaInfo);
		}
		StreamStateHandle stateHandle = deserializeStreamStateHandle(dis);
		return new OperatorStreamStateHandle(offsetsMap, stateHandle);
	} else {
		throw new IllegalStateException("Reading invalid OperatorStateHandle, type: " + type);
	}
}
 
Example 9
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 10
Source File: RoundRobinOperatorStateRepartitioner.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>> getByMode(
		OperatorStateHandle.Mode mode) {
	return byMode.get(mode);
}
 
Example 11
Source File: RoundRobinOperatorStateRepartitioner.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Group by the different named states.
 */
@SuppressWarnings("unchecked, rawtype")
private GroupByStateNameResults groupByStateMode(List<List<OperatorStateHandle>> previousParallelSubtaskStates) {

	//Reorganize: group by (State Name -> StreamStateHandle + StateMetaInfo)
	EnumMap<OperatorStateHandle.Mode,
			Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>>> nameToStateByMode =
			new EnumMap<>(OperatorStateHandle.Mode.class);

	for (OperatorStateHandle.Mode mode : OperatorStateHandle.Mode.values()) {

		nameToStateByMode.put(
				mode,
				new HashMap<>());
	}

	for (List<OperatorStateHandle> previousParallelSubtaskState : previousParallelSubtaskStates) {
		for (OperatorStateHandle operatorStateHandle : previousParallelSubtaskState) {

			if (operatorStateHandle == null) {
				continue;
			}

			final Set<Map.Entry<String, OperatorStateHandle.StateMetaInfo>> partitionOffsetEntries =
				operatorStateHandle.getStateNameToPartitionOffsets().entrySet();

			for (Map.Entry<String, OperatorStateHandle.StateMetaInfo> e : partitionOffsetEntries) {
				OperatorStateHandle.StateMetaInfo metaInfo = e.getValue();

				Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>> nameToState =
					nameToStateByMode.get(metaInfo.getDistributionMode());

				List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>> stateLocations =
					nameToState.computeIfAbsent(
						e.getKey(),
						k -> new ArrayList<>(previousParallelSubtaskStates.size() * partitionOffsetEntries.size()));

				stateLocations.add(Tuple2.of(operatorStateHandle.getDelegateStateHandle(), e.getValue()));
			}
		}
	}

	return new GroupByStateNameResults(nameToStateByMode);
}
 
Example 12
Source File: RoundRobinOperatorStateRepartitioner.java    From flink with Apache License 2.0 4 votes vote down vote up
GroupByStateNameResults(
		EnumMap<OperatorStateHandle.Mode,
				Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>>> byMode) {
	this.byMode = Preconditions.checkNotNull(byMode);
}
 
Example 13
Source File: RoundRobinOperatorStateRepartitioner.java    From flink with Apache License 2.0 4 votes vote down vote up
public Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>> getByMode(
		OperatorStateHandle.Mode mode) {
	return byMode.get(mode);
}
 
Example 14
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 15
Source File: RoundRobinOperatorStateRepartitioner.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
GroupByStateNameResults(
		EnumMap<OperatorStateHandle.Mode,
				Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>>> byMode) {
	this.byMode = Preconditions.checkNotNull(byMode);
}
 
Example 16
Source File: RoundRobinOperatorStateRepartitioner.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Group by the different named states.
 */
@SuppressWarnings("unchecked, rawtype")
private GroupByStateNameResults groupByStateMode(List<List<OperatorStateHandle>> previousParallelSubtaskStates) {

	//Reorganize: group by (State Name -> StreamStateHandle + StateMetaInfo)
	EnumMap<OperatorStateHandle.Mode,
			Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>>> nameToStateByMode =
			new EnumMap<>(OperatorStateHandle.Mode.class);

	for (OperatorStateHandle.Mode mode : OperatorStateHandle.Mode.values()) {

		nameToStateByMode.put(
				mode,
				new HashMap<>());
	}

	for (List<OperatorStateHandle> previousParallelSubtaskState : previousParallelSubtaskStates) {
		for (OperatorStateHandle operatorStateHandle : previousParallelSubtaskState) {

			if (operatorStateHandle == null) {
				continue;
			}

			final Set<Map.Entry<String, OperatorStateHandle.StateMetaInfo>> partitionOffsetEntries =
				operatorStateHandle.getStateNameToPartitionOffsets().entrySet();

			for (Map.Entry<String, OperatorStateHandle.StateMetaInfo> e : partitionOffsetEntries) {
				OperatorStateHandle.StateMetaInfo metaInfo = e.getValue();

				Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>> nameToState =
					nameToStateByMode.get(metaInfo.getDistributionMode());

				List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>> stateLocations =
					nameToState.computeIfAbsent(
						e.getKey(),
						k -> new ArrayList<>(previousParallelSubtaskStates.size() * partitionOffsetEntries.size()));

				stateLocations.add(Tuple2.of(operatorStateHandle.getDelegateStateHandle(), e.getValue()));
			}
		}
	}

	return new GroupByStateNameResults(nameToStateByMode);
}
 
Example 17
Source File: RoundRobinOperatorStateRepartitioner.java    From flink with Apache License 2.0 4 votes vote down vote up
GroupByStateNameResults(
		EnumMap<OperatorStateHandle.Mode,
				Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>>> byMode) {
	this.byMode = Preconditions.checkNotNull(byMode);
}
 
Example 18
Source File: RoundRobinOperatorStateRepartitioner.java    From flink with Apache License 2.0 4 votes vote down vote up
public Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>> getByMode(
		OperatorStateHandle.Mode mode) {
	return byMode.get(mode);
}
 
Example 19
Source File: RoundRobinOperatorStateRepartitioner.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Group by the different named states.
 */
@SuppressWarnings("unchecked, rawtype")
private GroupByStateNameResults groupByStateMode(List<List<OperatorStateHandle>> previousParallelSubtaskStates) {

	//Reorganize: group by (State Name -> StreamStateHandle + StateMetaInfo)
	EnumMap<OperatorStateHandle.Mode,
			Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>>> nameToStateByMode =
			new EnumMap<>(OperatorStateHandle.Mode.class);

	for (OperatorStateHandle.Mode mode : OperatorStateHandle.Mode.values()) {

		nameToStateByMode.put(
				mode,
				new HashMap<>());
	}

	for (List<OperatorStateHandle> previousParallelSubtaskState : previousParallelSubtaskStates) {
		for (OperatorStateHandle operatorStateHandle : previousParallelSubtaskState) {

			if (operatorStateHandle == null) {
				continue;
			}

			final Set<Map.Entry<String, OperatorStateHandle.StateMetaInfo>> partitionOffsetEntries =
				operatorStateHandle.getStateNameToPartitionOffsets().entrySet();

			for (Map.Entry<String, OperatorStateHandle.StateMetaInfo> e : partitionOffsetEntries) {
				OperatorStateHandle.StateMetaInfo metaInfo = e.getValue();

				Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>> nameToState =
					nameToStateByMode.get(metaInfo.getDistributionMode());

				List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>> stateLocations =
					nameToState.computeIfAbsent(
						e.getKey(),
						k -> new ArrayList<>(previousParallelSubtaskStates.size() * partitionOffsetEntries.size()));

				stateLocations.add(Tuple2.of(operatorStateHandle.getDelegateStateHandle(), e.getValue()));
			}
		}
	}

	return new GroupByStateNameResults(nameToStateByMode);
}
 
Example 20
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);
}