Java Code Examples for org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo#updateStateSerializer()

The following examples show how to use org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo#updateStateSerializer() . 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: RocksDBKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private <N, S extends State, SV> RegisteredKeyValueStateBackendMetaInfo<N, SV> updateRestoredStateMetaInfo(
	Tuple2<ColumnFamilyHandle, RegisteredKeyValueStateBackendMetaInfo<N, SV>> oldStateInfo,
	StateDescriptor<S, SV> stateDesc,
	TypeSerializer<N> namespaceSerializer,
	TypeSerializer<SV> stateSerializer) throws Exception {

	@SuppressWarnings("unchecked")
	RegisteredKeyValueStateBackendMetaInfo<N, SV> restoredKvStateMetaInfo = oldStateInfo.f1;

	TypeSerializerSchemaCompatibility<N> s = restoredKvStateMetaInfo.updateNamespaceSerializer(namespaceSerializer);
	if (s.isCompatibleAfterMigration() || s.isIncompatible()) {
		throw new StateMigrationException("The new namespace serializer must be compatible.");
	}

	restoredKvStateMetaInfo.checkStateMetaInfo(stateDesc);

	TypeSerializerSchemaCompatibility<SV> newStateSerializerCompatibility =
		restoredKvStateMetaInfo.updateStateSerializer(stateSerializer);
	if (newStateSerializerCompatibility.isCompatibleAfterMigration()) {
		migrateStateValues(stateDesc, oldStateInfo);
	} else if (newStateSerializerCompatibility.isIncompatible()) {
		throw new StateMigrationException("The new state serializer cannot be incompatible.");
	}

	return restoredKvStateMetaInfo;
}
 
Example 2
Source File: RocksDBKeyedStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
private <N, S extends State, SV> RegisteredKeyValueStateBackendMetaInfo<N, SV> updateRestoredStateMetaInfo(
	Tuple2<ColumnFamilyHandle, RegisteredKeyValueStateBackendMetaInfo<N, SV>> oldStateInfo,
	StateDescriptor<S, SV> stateDesc,
	TypeSerializer<N> namespaceSerializer,
	TypeSerializer<SV> stateSerializer) throws Exception {

	@SuppressWarnings("unchecked")
	RegisteredKeyValueStateBackendMetaInfo<N, SV> restoredKvStateMetaInfo = oldStateInfo.f1;

	TypeSerializerSchemaCompatibility<N> s = restoredKvStateMetaInfo.updateNamespaceSerializer(namespaceSerializer);
	if (s.isCompatibleAfterMigration() || s.isIncompatible()) {
		throw new StateMigrationException("The new namespace serializer must be compatible.");
	}

	restoredKvStateMetaInfo.checkStateMetaInfo(stateDesc);

	TypeSerializerSchemaCompatibility<SV> newStateSerializerCompatibility =
		restoredKvStateMetaInfo.updateStateSerializer(stateSerializer);
	if (newStateSerializerCompatibility.isCompatibleAfterMigration()) {
		migrateStateValues(stateDesc, oldStateInfo);
	} else if (newStateSerializerCompatibility.isIncompatible()) {
		throw new StateMigrationException("The new state serializer cannot be incompatible.");
	}

	return restoredKvStateMetaInfo;
}
 
Example 3
Source File: RocksDBKeyedStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
private <N, S extends State, SV> RegisteredKeyValueStateBackendMetaInfo<N, SV> updateRestoredStateMetaInfo(
	Tuple2<ColumnFamilyHandle, RegisteredKeyValueStateBackendMetaInfo<N, SV>> oldStateInfo,
	StateDescriptor<S, SV> stateDesc,
	TypeSerializer<N> namespaceSerializer,
	TypeSerializer<SV> stateSerializer) throws Exception {

	@SuppressWarnings("unchecked")
	RegisteredKeyValueStateBackendMetaInfo<N, SV> restoredKvStateMetaInfo = oldStateInfo.f1;

	TypeSerializerSchemaCompatibility<N> s = restoredKvStateMetaInfo.updateNamespaceSerializer(namespaceSerializer);
	if (s.isCompatibleAfterMigration() || s.isIncompatible()) {
		throw new StateMigrationException("The new namespace serializer must be compatible.");
	}

	restoredKvStateMetaInfo.checkStateMetaInfo(stateDesc);

	TypeSerializerSchemaCompatibility<SV> newStateSerializerCompatibility =
		restoredKvStateMetaInfo.updateStateSerializer(stateSerializer);
	if (newStateSerializerCompatibility.isCompatibleAfterMigration()) {
		migrateStateValues(stateDesc, oldStateInfo);
	} else if (newStateSerializerCompatibility.isIncompatible()) {
		throw new StateMigrationException("The new state serializer cannot be incompatible.");
	}

	return restoredKvStateMetaInfo;
}
 
Example 4
Source File: HeapKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private <N, V> StateTable<K, N, V> tryRegisterStateTable(
	TypeSerializer<N> namespaceSerializer,
	StateDescriptor<?, V> stateDesc,
	@Nonnull StateSnapshotTransformFactory<V> snapshotTransformFactory) throws StateMigrationException {

	@SuppressWarnings("unchecked")
	StateTable<K, N, V> stateTable = (StateTable<K, N, V>) registeredKVStates.get(stateDesc.getName());

	TypeSerializer<V> newStateSerializer = stateDesc.getSerializer();

	if (stateTable != null) {
		RegisteredKeyValueStateBackendMetaInfo<N, V> restoredKvMetaInfo = stateTable.getMetaInfo();

		restoredKvMetaInfo.updateSnapshotTransformFactory(snapshotTransformFactory);

		TypeSerializerSchemaCompatibility<N> namespaceCompatibility =
			restoredKvMetaInfo.updateNamespaceSerializer(namespaceSerializer);
		if (namespaceCompatibility.isCompatibleAfterMigration() || namespaceCompatibility.isIncompatible()) {
			throw new StateMigrationException("For heap backends, the new namespace serializer must be compatible.");
		}

		restoredKvMetaInfo.checkStateMetaInfo(stateDesc);

		TypeSerializerSchemaCompatibility<V> stateCompatibility =
			restoredKvMetaInfo.updateStateSerializer(newStateSerializer);

		if (stateCompatibility.isIncompatible()) {
			throw new StateMigrationException("For heap backends, the new state serializer must not be incompatible.");
		}

		stateTable.setMetaInfo(restoredKvMetaInfo);
	} else {
		RegisteredKeyValueStateBackendMetaInfo<N, V> newMetaInfo = new RegisteredKeyValueStateBackendMetaInfo<>(
			stateDesc.getType(),
			stateDesc.getName(),
			namespaceSerializer,
			newStateSerializer,
			snapshotTransformFactory);

		stateTable = snapshotStrategy.newStateTable(this, newMetaInfo);
		registeredKVStates.put(stateDesc.getName(), stateTable);
	}

	return stateTable;
}
 
Example 5
Source File: HeapKeyedStateBackend.java    From flink with Apache License 2.0 4 votes vote down vote up
private <N, V> StateTable<K, N, V> tryRegisterStateTable(
	TypeSerializer<N> namespaceSerializer,
	StateDescriptor<?, V> stateDesc,
	@Nonnull StateSnapshotTransformFactory<V> snapshotTransformFactory) throws StateMigrationException {

	@SuppressWarnings("unchecked")
	StateTable<K, N, V> stateTable = (StateTable<K, N, V>) registeredKVStates.get(stateDesc.getName());

	TypeSerializer<V> newStateSerializer = stateDesc.getSerializer();

	if (stateTable != null) {
		RegisteredKeyValueStateBackendMetaInfo<N, V> restoredKvMetaInfo = stateTable.getMetaInfo();

		restoredKvMetaInfo.updateSnapshotTransformFactory(snapshotTransformFactory);

		TypeSerializerSchemaCompatibility<N> namespaceCompatibility =
			restoredKvMetaInfo.updateNamespaceSerializer(namespaceSerializer);
		if (namespaceCompatibility.isCompatibleAfterMigration() || namespaceCompatibility.isIncompatible()) {
			throw new StateMigrationException("For heap backends, the new namespace serializer must be compatible.");
		}

		restoredKvMetaInfo.checkStateMetaInfo(stateDesc);

		TypeSerializerSchemaCompatibility<V> stateCompatibility =
			restoredKvMetaInfo.updateStateSerializer(newStateSerializer);

		if (stateCompatibility.isIncompatible()) {
			throw new StateMigrationException("For heap backends, the new state serializer must not be incompatible.");
		}

		stateTable.setMetaInfo(restoredKvMetaInfo);
	} else {
		RegisteredKeyValueStateBackendMetaInfo<N, V> newMetaInfo = new RegisteredKeyValueStateBackendMetaInfo<>(
			stateDesc.getType(),
			stateDesc.getName(),
			namespaceSerializer,
			newStateSerializer,
			snapshotTransformFactory);

		stateTable = snapshotStrategy.newStateTable(keyContext, newMetaInfo, keySerializer);
		registeredKVStates.put(stateDesc.getName(), stateTable);
	}

	return stateTable;
}
 
Example 6
Source File: HeapKeyedStateBackend.java    From flink with Apache License 2.0 4 votes vote down vote up
private <N, V> StateTable<K, N, V> tryRegisterStateTable(
	TypeSerializer<N> namespaceSerializer,
	StateDescriptor<?, V> stateDesc,
	@Nonnull StateSnapshotTransformFactory<V> snapshotTransformFactory) throws StateMigrationException {

	@SuppressWarnings("unchecked")
	StateTable<K, N, V> stateTable = (StateTable<K, N, V>) registeredKVStates.get(stateDesc.getName());

	TypeSerializer<V> newStateSerializer = stateDesc.getSerializer();

	if (stateTable != null) {
		RegisteredKeyValueStateBackendMetaInfo<N, V> restoredKvMetaInfo = stateTable.getMetaInfo();

		restoredKvMetaInfo.updateSnapshotTransformFactory(snapshotTransformFactory);

		TypeSerializerSchemaCompatibility<N> namespaceCompatibility =
			restoredKvMetaInfo.updateNamespaceSerializer(namespaceSerializer);
		if (namespaceCompatibility.isCompatibleAfterMigration() || namespaceCompatibility.isIncompatible()) {
			throw new StateMigrationException("For heap backends, the new namespace serializer must be compatible.");
		}

		restoredKvMetaInfo.checkStateMetaInfo(stateDesc);

		TypeSerializerSchemaCompatibility<V> stateCompatibility =
			restoredKvMetaInfo.updateStateSerializer(newStateSerializer);

		if (stateCompatibility.isIncompatible()) {
			throw new StateMigrationException("For heap backends, the new state serializer must not be incompatible.");
		}

		stateTable.setMetaInfo(restoredKvMetaInfo);
	} else {
		RegisteredKeyValueStateBackendMetaInfo<N, V> newMetaInfo = new RegisteredKeyValueStateBackendMetaInfo<>(
			stateDesc.getType(),
			stateDesc.getName(),
			namespaceSerializer,
			newStateSerializer,
			snapshotTransformFactory);

		stateTable = snapshotStrategy.newStateTable(keyContext, newMetaInfo, keySerializer);
		registeredKVStates.put(stateDesc.getName(), stateTable);
	}

	return stateTable;
}