Java Code Examples for org.apache.flink.runtime.state.RegisteredPriorityQueueStateBackendMetaInfo#getPreviousElementSerializer()

The following examples show how to use org.apache.flink.runtime.state.RegisteredPriorityQueueStateBackendMetaInfo#getPreviousElementSerializer() . 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: RocksDBPriorityQueueSetFactory.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Nonnull
private <T> RocksDBKeyedStateBackend.RocksDbKvStateInfo tryRegisterPriorityQueueMetaInfo(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	RocksDBKeyedStateBackend.RocksDbKvStateInfo stateInfo = kvStateInformation.get(stateName);

	if (stateInfo == null) {
		// Currently this class is for timer service and TTL feature is not applicable here,
		// so no need to register compact filter when creating column family
		RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo =
			new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer);
		stateInfo = RocksDBOperationUtils.createStateInfo(metaInfo, db, columnFamilyOptionsFactory, null);
		RocksDBOperationUtils.registerKvStateInformation(kvStateInformation, nativeMetricMonitor, stateName, stateInfo);
	} else {
		// TODO we implement the simple way of supporting the current functionality, mimicking keyed state
		// because this should be reworked in FLINK-9376 and then we should have a common algorithm over
		// StateMetaInfoSnapshot that avoids this code duplication.

		@SuppressWarnings("unchecked")
		RegisteredPriorityQueueStateBackendMetaInfo<T> castedMetaInfo =
			(RegisteredPriorityQueueStateBackendMetaInfo<T>) stateInfo.metaInfo;

		TypeSerializer<T> previousElementSerializer = castedMetaInfo.getPreviousElementSerializer();

		if (previousElementSerializer != byteOrderedElementSerializer) {
			TypeSerializerSchemaCompatibility<T> compatibilityResult =
				castedMetaInfo.updateElementSerializer(byteOrderedElementSerializer);

			// Since priority queue elements are written into RocksDB
			// as keys prefixed with the key group and namespace, we do not support
			// migrating them. Therefore, here we only check for incompatibility.
			if (compatibilityResult.isIncompatible()) {
				throw new FlinkRuntimeException(
					new StateMigrationException("The new priority queue serializer must not be incompatible."));
			}

			// update meta info with new serializer
			stateInfo = new RocksDBKeyedStateBackend.RocksDbKvStateInfo(
				stateInfo.columnFamilyHandle,
				new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer));
			kvStateInformation.put(stateName, stateInfo);
		}
	}

	return stateInfo;
}
 
Example 2
Source File: RocksDBPriorityQueueSetFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nonnull
private <T> RocksDBKeyedStateBackend.RocksDbKvStateInfo tryRegisterPriorityQueueMetaInfo(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	RocksDBKeyedStateBackend.RocksDbKvStateInfo stateInfo = kvStateInformation.get(stateName);

	if (stateInfo == null) {
		// Currently this class is for timer service and TTL feature is not applicable here,
		// so no need to register compact filter when creating column family
		RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo =
			new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer);
		stateInfo = RocksDBOperationUtils.createStateInfo(metaInfo, db, columnFamilyOptionsFactory, null);
		RocksDBOperationUtils.registerKvStateInformation(kvStateInformation, nativeMetricMonitor, stateName, stateInfo);
	} else {
		// TODO we implement the simple way of supporting the current functionality, mimicking keyed state
		// because this should be reworked in FLINK-9376 and then we should have a common algorithm over
		// StateMetaInfoSnapshot that avoids this code duplication.

		@SuppressWarnings("unchecked")
		RegisteredPriorityQueueStateBackendMetaInfo<T> castedMetaInfo =
			(RegisteredPriorityQueueStateBackendMetaInfo<T>) stateInfo.metaInfo;

		TypeSerializer<T> previousElementSerializer = castedMetaInfo.getPreviousElementSerializer();

		if (previousElementSerializer != byteOrderedElementSerializer) {
			TypeSerializerSchemaCompatibility<T> compatibilityResult =
				castedMetaInfo.updateElementSerializer(byteOrderedElementSerializer);

			// Since priority queue elements are written into RocksDB
			// as keys prefixed with the key group and namespace, we do not support
			// migrating them. Therefore, here we only check for incompatibility.
			if (compatibilityResult.isIncompatible()) {
				throw new FlinkRuntimeException(
					new StateMigrationException("The new priority queue serializer must not be incompatible."));
			}

			// update meta info with new serializer
			stateInfo = new RocksDBKeyedStateBackend.RocksDbKvStateInfo(
				stateInfo.columnFamilyHandle,
				new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer));
			kvStateInformation.put(stateName, stateInfo);
		}
	}

	return stateInfo;
}
 
Example 3
Source File: RocksDBPriorityQueueSetFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nonnull
private <T> RocksDBKeyedStateBackend.RocksDbKvStateInfo tryRegisterPriorityQueueMetaInfo(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	RocksDBKeyedStateBackend.RocksDbKvStateInfo stateInfo = kvStateInformation.get(stateName);

	if (stateInfo == null) {
		// Currently this class is for timer service and TTL feature is not applicable here,
		// so no need to register compact filter when creating column family
		RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo =
			new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer);
		stateInfo = RocksDBOperationUtils.createStateInfo(metaInfo, db, columnFamilyOptionsFactory, null);
		RocksDBOperationUtils.registerKvStateInformation(kvStateInformation, nativeMetricMonitor, stateName, stateInfo);
	} else {
		// TODO we implement the simple way of supporting the current functionality, mimicking keyed state
		// because this should be reworked in FLINK-9376 and then we should have a common algorithm over
		// StateMetaInfoSnapshot that avoids this code duplication.

		@SuppressWarnings("unchecked")
		RegisteredPriorityQueueStateBackendMetaInfo<T> castedMetaInfo =
			(RegisteredPriorityQueueStateBackendMetaInfo<T>) stateInfo.metaInfo;

		TypeSerializer<T> previousElementSerializer = castedMetaInfo.getPreviousElementSerializer();

		if (previousElementSerializer != byteOrderedElementSerializer) {
			TypeSerializerSchemaCompatibility<T> compatibilityResult =
				castedMetaInfo.updateElementSerializer(byteOrderedElementSerializer);

			// Since priority queue elements are written into RocksDB
			// as keys prefixed with the key group and namespace, we do not support
			// migrating them. Therefore, here we only check for incompatibility.
			if (compatibilityResult.isIncompatible()) {
				throw new FlinkRuntimeException(
					new StateMigrationException("The new priority queue serializer must not be incompatible."));
			}

			// update meta info with new serializer
			stateInfo = new RocksDBKeyedStateBackend.RocksDbKvStateInfo(
				stateInfo.columnFamilyHandle,
				new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer));
			kvStateInformation.put(stateName, stateInfo);
		}
	}

	return stateInfo;
}