org.apache.flink.runtime.state.PriorityComparable Java Examples

The following examples show how to use org.apache.flink.runtime.state.PriorityComparable. 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: HeapRestoreOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
private <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> void createInternal(
	RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo) {

	final String stateName = metaInfo.getName();
	final HeapPriorityQueueSet<T> priorityQueue = priorityQueueSetFactory.create(
		stateName,
		metaInfo.getElementSerializer());

	HeapPriorityQueueSnapshotRestoreWrapper<T> wrapper =
		new HeapPriorityQueueSnapshotRestoreWrapper<>(
			priorityQueue,
			metaInfo,
			KeyExtractorFunction.forKeyedObjects(),
			keyGroupRange,
			numberOfKeyGroups);

	registeredPQStates.put(stateName, wrapper);
}
 
Example #2
Source File: HeapKeyedStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T> createInternal(
	RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo) {

	final String stateName = metaInfo.getName();
	final HeapPriorityQueueSet<T> priorityQueue = priorityQueueSetFactory.create(
		stateName,
		metaInfo.getElementSerializer());

	HeapPriorityQueueSnapshotRestoreWrapper<T> wrapper =
		new HeapPriorityQueueSnapshotRestoreWrapper<>(
			priorityQueue,
			metaInfo,
			KeyExtractorFunction.forKeyedObjects(),
			keyGroupRange,
			numberOfKeyGroups);

	registeredPQStates.put(stateName, wrapper);
	return priorityQueue;
}
 
Example #3
Source File: HeapKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
private <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T> createInternal(
	RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo) {

	final String stateName = metaInfo.getName();
	final HeapPriorityQueueSet<T> priorityQueue = priorityQueueSetFactory.create(
		stateName,
		metaInfo.getElementSerializer());

	HeapPriorityQueueSnapshotRestoreWrapper<T> wrapper =
		new HeapPriorityQueueSnapshotRestoreWrapper<>(
			priorityQueue,
			metaInfo,
			KeyExtractorFunction.forKeyedObjects(),
			keyGroupRange,
			numberOfKeyGroups);

	registeredPQStates.put(stateName, wrapper);
	return priorityQueue;
}
 
Example #4
Source File: HeapRestoreOperation.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> void createInternal(
	RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo) {

	final String stateName = metaInfo.getName();
	final HeapPriorityQueueSet<T> priorityQueue = priorityQueueSetFactory.create(
		stateName,
		metaInfo.getElementSerializer());

	HeapPriorityQueueSnapshotRestoreWrapper<T> wrapper =
		new HeapPriorityQueueSnapshotRestoreWrapper<>(
			priorityQueue,
			metaInfo,
			KeyExtractorFunction.forKeyedObjects(),
			keyGroupRange,
			numberOfKeyGroups);

	registeredPQStates.put(stateName, wrapper);
}
 
Example #5
Source File: HeapKeyedStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T> createInternal(
	RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo) {

	final String stateName = metaInfo.getName();
	final HeapPriorityQueueSet<T> priorityQueue = priorityQueueSetFactory.create(
		stateName,
		metaInfo.getElementSerializer());

	HeapPriorityQueueSnapshotRestoreWrapper<T> wrapper =
		new HeapPriorityQueueSnapshotRestoreWrapper<>(
			priorityQueue,
			metaInfo,
			KeyExtractorFunction.forKeyedObjects(),
			keyGroupRange,
			numberOfKeyGroups);

	registeredPQStates.put(stateName, wrapper);
	return priorityQueue;
}
 
Example #6
Source File: HeapRestoreOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
private <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> void createInternal(
	RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo) {

	final String stateName = metaInfo.getName();
	final HeapPriorityQueueSet<T> priorityQueue = priorityQueueSetFactory.create(
		stateName,
		metaInfo.getElementSerializer());

	HeapPriorityQueueSnapshotRestoreWrapper<T> wrapper =
		new HeapPriorityQueueSnapshotRestoreWrapper<>(
			priorityQueue,
			metaInfo,
			KeyExtractorFunction.forKeyedObjects(),
			keyGroupRange,
			numberOfKeyGroups);

	registeredPQStates.put(stateName, wrapper);
}
 
Example #7
Source File: MockKeyedStateBackend.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
	return new HeapPriorityQueueSet<>(
		PriorityComparator.forPriorityComparableObjects(),
		KeyExtractorFunction.forKeyedObjects(),
		0,
		keyGroupRange,
		0);
}
 
Example #8
Source File: RocksDBPriorityQueueSetFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(@Nonnull String stateName, @Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	final RocksDBKeyedStateBackend.RocksDbKvStateInfo stateCFHandle =
		tryRegisterPriorityQueueMetaInfo(stateName, byteOrderedElementSerializer);

	final ColumnFamilyHandle columnFamilyHandle = stateCFHandle.columnFamilyHandle;

	return new KeyGroupPartitionedPriorityQueue<>(
		KeyExtractorFunction.forKeyedObjects(),
		PriorityComparator.forPriorityComparableObjects(),
		new KeyGroupPartitionedPriorityQueue.PartitionQueueSetFactory<T, RocksDBCachingPriorityQueueSet<T>>() {
			@Nonnull
			@Override
			public RocksDBCachingPriorityQueueSet<T> create(
				int keyGroupId,
				int numKeyGroups,
				@Nonnull KeyExtractorFunction<T> keyExtractor,
				@Nonnull PriorityComparator<T> elementPriorityComparator) {
				TreeOrderedSetCache orderedSetCache = new TreeOrderedSetCache(DEFAULT_CACHES_SIZE);
				return new RocksDBCachingPriorityQueueSet<>(
					keyGroupId,
					keyGroupPrefixBytes,
					db,
					columnFamilyHandle,
					byteOrderedElementSerializer,
					sharedElementOutView,
					sharedElementInView,
					writeBatchWrapper,
					orderedSetCache
				);
			}
		},
		keyGroupRange,
		numberOfKeyGroups);
}
 
Example #9
Source File: HeapKeyedStateBackend.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T> create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	final HeapPriorityQueueSnapshotRestoreWrapper existingState = registeredPQStates.get(stateName);

	if (existingState != null) {
		// 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.

		TypeSerializerSchemaCompatibility<T> compatibilityResult =
			existingState.getMetaInfo().updateElementSerializer(byteOrderedElementSerializer);

		if (compatibilityResult.isIncompatible()) {
			throw new FlinkRuntimeException(new StateMigrationException("For heap backends, the new priority queue serializer must not be incompatible."));
		} else {
			registeredPQStates.put(
				stateName,
				existingState.forUpdatedSerializer(byteOrderedElementSerializer));
		}

		return existingState.getPriorityQueue();
	} else {
		final RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo =
			new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer);
		return createInternal(metaInfo);
	}
}
 
Example #10
Source File: HeapPriorityQueueSetFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> HeapPriorityQueueSet<T> create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	return new HeapPriorityQueueSet<>(
		PriorityComparator.forPriorityComparableObjects(),
		KeyExtractorFunction.forKeyedObjects(),
		minimumCapacity,
		keyGroupRange,
		totalKeyGroups);
}
 
Example #11
Source File: RocksDBKeyedStateBackend.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
	return priorityQueueFactory.create(stateName, byteOrderedElementSerializer);
}
 
Example #12
Source File: RocksDBPriorityQueueSetFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(@Nonnull String stateName, @Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	final RocksDBKeyedStateBackend.RocksDbKvStateInfo stateCFHandle =
		tryRegisterPriorityQueueMetaInfo(stateName, byteOrderedElementSerializer);

	final ColumnFamilyHandle columnFamilyHandle = stateCFHandle.columnFamilyHandle;

	return new KeyGroupPartitionedPriorityQueue<>(
		KeyExtractorFunction.forKeyedObjects(),
		PriorityComparator.forPriorityComparableObjects(),
		new KeyGroupPartitionedPriorityQueue.PartitionQueueSetFactory<T, RocksDBCachingPriorityQueueSet<T>>() {
			@Nonnull
			@Override
			public RocksDBCachingPriorityQueueSet<T> create(
				int keyGroupId,
				int numKeyGroups,
				@Nonnull KeyExtractorFunction<T> keyExtractor,
				@Nonnull PriorityComparator<T> elementPriorityComparator) {
				TreeOrderedSetCache orderedSetCache = new TreeOrderedSetCache(DEFAULT_CACHES_SIZE);
				return new RocksDBCachingPriorityQueueSet<>(
					keyGroupId,
					keyGroupPrefixBytes,
					db,
					readOptions,
					columnFamilyHandle,
					byteOrderedElementSerializer,
					sharedElementOutView,
					sharedElementInView,
					writeBatchWrapper,
					orderedSetCache
				);
			}
		},
		keyGroupRange,
		numberOfKeyGroups);
}
 
Example #13
Source File: ReductionsTest.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed>
    KeyGroupedInternalPriorityQueue<T> create(
        @Nonnull String stateName, @Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
  throw new UnsupportedOperationException();
}
 
Example #14
Source File: ReductionsTest.java    From stateful-functions with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed>
    KeyGroupedInternalPriorityQueue<T> create(
        @Nonnull String stateName, @Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
  throw new UnsupportedOperationException();
}
 
Example #15
Source File: MockKeyedStateBackend.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
	return new HeapPriorityQueueSet<>(
		PriorityComparator.forPriorityComparableObjects(),
		KeyExtractorFunction.forKeyedObjects(),
		0,
		keyGroupRange,
		0);
}
 
Example #16
Source File: HeapKeyedStateBackend.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T> create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	final HeapPriorityQueueSnapshotRestoreWrapper existingState = registeredPQStates.get(stateName);

	if (existingState != null) {
		// 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.

		TypeSerializerSchemaCompatibility<T> compatibilityResult =
			existingState.getMetaInfo().updateElementSerializer(byteOrderedElementSerializer);

		if (compatibilityResult.isIncompatible()) {
			throw new FlinkRuntimeException(new StateMigrationException("For heap backends, the new priority queue serializer must not be incompatible."));
		} else {
			registeredPQStates.put(
				stateName,
				existingState.forUpdatedSerializer(byteOrderedElementSerializer));
		}

		return existingState.getPriorityQueue();
	} else {
		final RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo =
			new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer);
		return createInternal(metaInfo);
	}
}
 
Example #17
Source File: HeapPriorityQueueSetFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> HeapPriorityQueueSet<T> create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	return new HeapPriorityQueueSet<>(
		PriorityComparator.forPriorityComparableObjects(),
		KeyExtractorFunction.forKeyedObjects(),
		minimumCapacity,
		keyGroupRange,
		totalKeyGroups);
}
 
Example #18
Source File: RocksDBKeyedStateBackend.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
	return priorityQueueFactory.create(stateName, byteOrderedElementSerializer);
}
 
Example #19
Source File: RocksDBPriorityQueueSetFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(@Nonnull String stateName, @Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	final RocksDBKeyedStateBackend.RocksDbKvStateInfo stateCFHandle =
		tryRegisterPriorityQueueMetaInfo(stateName, byteOrderedElementSerializer);

	final ColumnFamilyHandle columnFamilyHandle = stateCFHandle.columnFamilyHandle;

	return new KeyGroupPartitionedPriorityQueue<>(
		KeyExtractorFunction.forKeyedObjects(),
		PriorityComparator.forPriorityComparableObjects(),
		new KeyGroupPartitionedPriorityQueue.PartitionQueueSetFactory<T, RocksDBCachingPriorityQueueSet<T>>() {
			@Nonnull
			@Override
			public RocksDBCachingPriorityQueueSet<T> create(
				int keyGroupId,
				int numKeyGroups,
				@Nonnull KeyExtractorFunction<T> keyExtractor,
				@Nonnull PriorityComparator<T> elementPriorityComparator) {
				TreeOrderedSetCache orderedSetCache = new TreeOrderedSetCache(DEFAULT_CACHES_SIZE);
				return new RocksDBCachingPriorityQueueSet<>(
					keyGroupId,
					keyGroupPrefixBytes,
					db,
					columnFamilyHandle,
					byteOrderedElementSerializer,
					sharedElementOutView,
					sharedElementInView,
					writeBatchWrapper,
					orderedSetCache
				);
			}
		},
		keyGroupRange,
		numberOfKeyGroups);
}
 
Example #20
Source File: MockKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
	return new HeapPriorityQueueSet<>(
		PriorityComparator.forPriorityComparableObjects(),
		KeyExtractorFunction.forKeyedObjects(),
		0,
		keyGroupRange,
		0);
}
 
Example #21
Source File: HeapKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T> create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	final HeapPriorityQueueSnapshotRestoreWrapper existingState = registeredPQStates.get(stateName);

	if (existingState != null) {
		// 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.

		TypeSerializerSchemaCompatibility<T> compatibilityResult =
			existingState.getMetaInfo().updateElementSerializer(byteOrderedElementSerializer);

		if (compatibilityResult.isIncompatible()) {
			throw new FlinkRuntimeException(new StateMigrationException("For heap backends, the new priority queue serializer must not be incompatible."));
		} else {
			registeredPQStates.put(
				stateName,
				existingState.forUpdatedSerializer(byteOrderedElementSerializer));
		}

		return existingState.getPriorityQueue();
	} else {
		final RegisteredPriorityQueueStateBackendMetaInfo<T> metaInfo =
			new RegisteredPriorityQueueStateBackendMetaInfo<>(stateName, byteOrderedElementSerializer);
		return createInternal(metaInfo);
	}
}
 
Example #22
Source File: HeapPriorityQueueSetFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> HeapPriorityQueueSet<T> create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {

	return new HeapPriorityQueueSet<>(
		PriorityComparator.forPriorityComparableObjects(),
		KeyExtractorFunction.forKeyedObjects(),
		minimumCapacity,
		keyGroupRange,
		totalKeyGroups);
}
 
Example #23
Source File: RocksDBKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <T extends HeapPriorityQueueElement & PriorityComparable & Keyed> KeyGroupedInternalPriorityQueue<T>
create(
	@Nonnull String stateName,
	@Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
	return priorityQueueFactory.create(stateName, byteOrderedElementSerializer);
}