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

The following examples show how to use org.apache.flink.runtime.state.KeyGroupRange. 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: CheckpointCoordinatorTestingUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
static TaskStateSnapshot mockSubtaskState(
	JobVertexID jobVertexID,
	int index,
	KeyGroupRange keyGroupRange) throws IOException {

	OperatorStateHandle partitionableState = generatePartitionableStateHandle(jobVertexID, index, 2, 8, false);
	KeyGroupsStateHandle partitionedKeyGroupState = generateKeyGroupState(jobVertexID, keyGroupRange, false);

	TaskStateSnapshot subtaskStates = spy(new TaskStateSnapshot());
	OperatorSubtaskState subtaskState = spy(new OperatorSubtaskState(
		partitionableState, null, partitionedKeyGroupState, null, null, null)
	);

	subtaskStates.putSubtaskStateByOperatorID(OperatorID.fromJobVertexID(jobVertexID), subtaskState);

	return subtaskStates;
}
 
Example #2
Source File: HeapStateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
public <K> HeapKeyedStateBackend<K> createKeyedBackend(
	TypeSerializer<K> keySerializer,
	Collection<KeyedStateHandle> stateHandles) throws Exception {
	final KeyGroupRange keyGroupRange = new KeyGroupRange(0, 15);
	final int numKeyGroups = keyGroupRange.getNumberOfKeyGroups();
	ExecutionConfig executionConfig = new ExecutionConfig();

	return new HeapKeyedStateBackendBuilder<>(
		mock(TaskKvStateRegistry.class),
		keySerializer,
		HeapStateBackendTestBase.class.getClassLoader(),
		numKeyGroups,
		keyGroupRange,
		executionConfig,
		TtlTimeProvider.DEFAULT,
		stateHandles,
		AbstractStateBackend.getCompressionDecorator(executionConfig),
		TestLocalRecoveryConfig.disabled(),
		new HeapPriorityQueueSetFactory(keyGroupRange, numKeyGroups, 128),
		async,
		new CloseableRegistry()).build();
}
 
Example #3
Source File: StateAssignmentOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Determine the subset of {@link KeyGroupsStateHandle KeyGroupsStateHandles} with correct
 * key group index for the given subtask {@link KeyGroupRange}.
 *
 * <p>This is publicly visible to be used in tests.
 */
public static List<KeyedStateHandle> getKeyedStateHandles(
	Collection<? extends KeyedStateHandle> keyedStateHandles,
	KeyGroupRange subtaskKeyGroupRange) {

	List<KeyedStateHandle> subtaskKeyedStateHandles = new ArrayList<>(keyedStateHandles.size());

	for (KeyedStateHandle keyedStateHandle : keyedStateHandles) {
		KeyedStateHandle intersectedKeyedStateHandle = keyedStateHandle.getIntersection(subtaskKeyGroupRange);

		if (intersectedKeyedStateHandle != null) {
			subtaskKeyedStateHandles.add(intersectedKeyedStateHandle);
		}
	}

	return subtaskKeyedStateHandles;
}
 
Example #4
Source File: HeapRestoreOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
HeapRestoreOperation(
	@Nonnull Collection<KeyedStateHandle> restoreStateHandles,
	StateSerializerProvider<K> keySerializerProvider,
	ClassLoader userCodeClassLoader,
	Map<String, StateTable<K, ?, ?>> registeredKVStates,
	Map<String, HeapPriorityQueueSnapshotRestoreWrapper> registeredPQStates,
	CloseableRegistry cancelStreamRegistry,
	HeapPriorityQueueSetFactory priorityQueueSetFactory,
	@Nonnull KeyGroupRange keyGroupRange,
	int numberOfKeyGroups,
	HeapSnapshotStrategy<K> snapshotStrategy,
	InternalKeyContext<K> keyContext) {
	this.restoreStateHandles = restoreStateHandles;
	this.keySerializerProvider = keySerializerProvider;
	this.userCodeClassLoader = userCodeClassLoader;
	this.registeredKVStates = registeredKVStates;
	this.registeredPQStates = registeredPQStates;
	this.cancelStreamRegistry = cancelStreamRegistry;
	this.priorityQueueSetFactory = priorityQueueSetFactory;
	this.keyGroupRange = keyGroupRange;
	this.numberOfKeyGroups = numberOfKeyGroups;
	this.snapshotStrategy = snapshotStrategy;
	this.keyContext = keyContext;
}
 
Example #5
Source File: CheckpointCoordinatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
static TaskStateSnapshot mockSubtaskState(
	JobVertexID jobVertexID,
	int index,
	KeyGroupRange keyGroupRange) throws IOException {

	OperatorStateHandle partitionableState = generatePartitionableStateHandle(jobVertexID, index, 2, 8, false);
	KeyGroupsStateHandle partitionedKeyGroupState = generateKeyGroupState(jobVertexID, keyGroupRange, false);

	TaskStateSnapshot subtaskStates = spy(new TaskStateSnapshot());
	OperatorSubtaskState subtaskState = spy(new OperatorSubtaskState(
		partitionableState, null, partitionedKeyGroupState, null)
	);

	subtaskStates.putSubtaskStateByOperatorID(OperatorID.fromJobVertexID(jobVertexID), subtaskState);

	return subtaskStates;
}
 
Example #6
Source File: MockKeyedStateBackendBuilder.java    From flink with Apache License 2.0 6 votes vote down vote up
public MockKeyedStateBackendBuilder(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	StreamCompressionDecorator keyGroupCompressionDecorator,
	CloseableRegistry cancelStreamRegistry) {
	super(
		kvStateRegistry,
		keySerializer,
		userCodeClassLoader,
		numberOfKeyGroups,
		keyGroupRange,
		executionConfig,
		ttlTimeProvider,
		stateHandles,
		keyGroupCompressionDecorator,
		cancelStreamRegistry);
}
 
Example #7
Source File: KvStateLocation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Registers a KvState instance for the given key group index.
 *
 * @param keyGroupRange  Key group range to register
 * @param kvStateId      ID of the KvState instance at the key group index.
 * @param kvStateAddress Server address of the KvState instance at the key group index.
 * @throws IndexOutOfBoundsException If key group range start < 0 or key group range end >= Number of key groups
 */
public void registerKvState(KeyGroupRange keyGroupRange, KvStateID kvStateId, InetSocketAddress kvStateAddress) {

	if (keyGroupRange.getStartKeyGroup() < 0 || keyGroupRange.getEndKeyGroup() >= numKeyGroups) {
		throw new IndexOutOfBoundsException("Key group index");
	}

	for (int kgIdx = keyGroupRange.getStartKeyGroup(); kgIdx <= keyGroupRange.getEndKeyGroup(); ++kgIdx) {

		if (kvStateIds[kgIdx] == null && kvStateAddresses[kgIdx] == null) {
			numRegisteredKeyGroups++;
		}

		kvStateIds[kgIdx] = kvStateId;
		kvStateAddresses[kgIdx] = kvStateAddress;
	}
}
 
Example #8
Source File: RocksFullSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
public RocksFullSnapshotStrategy(
	@Nonnull RocksDB db,
	@Nonnull ResourceGuard rocksDBResourceGuard,
	@Nonnull TypeSerializer<K> keySerializer,
	@Nonnull LinkedHashMap<String, RocksDbKvStateInfo> kvStateInformation,
	@Nonnull KeyGroupRange keyGroupRange,
	@Nonnegative int keyGroupPrefixBytes,
	@Nonnull LocalRecoveryConfig localRecoveryConfig,
	@Nonnull CloseableRegistry cancelStreamRegistry,
	@Nonnull StreamCompressionDecorator keyGroupCompressionDecorator) {
	super(
		DESCRIPTION,
		db,
		rocksDBResourceGuard,
		keySerializer,
		kvStateInformation,
		keyGroupRange,
		keyGroupPrefixBytes,
		localRecoveryConfig,
		cancelStreamRegistry);

	this.keyGroupCompressionDecorator = keyGroupCompressionDecorator;
}
 
Example #9
Source File: HeapPriorityQueueSet.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an empty {@link HeapPriorityQueueSet} with the requested initial capacity.
 *
 * @param elementPriorityComparator comparator for the priority of contained elements.
 * @param keyExtractor function to extract a key from the contained elements.
 * @param minimumCapacity the minimum and initial capacity of this priority queue.
 * @param keyGroupRange the key-group range of the elements in this set.
 * @param totalNumberOfKeyGroups the total number of key-groups of the job.
 */
@SuppressWarnings("unchecked")
public HeapPriorityQueueSet(
	@Nonnull PriorityComparator<T> elementPriorityComparator,
	@Nonnull KeyExtractorFunction<T> keyExtractor,
	@Nonnegative int minimumCapacity,
	@Nonnull KeyGroupRange keyGroupRange,
	@Nonnegative int totalNumberOfKeyGroups) {

	super(elementPriorityComparator, minimumCapacity);

	this.keyExtractor = keyExtractor;

	this.totalNumberOfKeyGroups = totalNumberOfKeyGroups;
	this.keyGroupRange = keyGroupRange;

	final int keyGroupsInLocalRange = keyGroupRange.getNumberOfKeyGroups();
	final int deduplicationSetSize = 1 + minimumCapacity / keyGroupsInLocalRange;
	this.deduplicationMapsByKeyGroup = new HashMap[keyGroupsInLocalRange];
	for (int i = 0; i < keyGroupsInLocalRange; ++i) {
		deduplicationMapsByKeyGroup[i] = new HashMap<>(deduplicationSetSize);
	}
}
 
Example #10
Source File: SavepointV1Serializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public static KeyedStateHandle deserializeKeyedStateHandle(DataInputStream dis) throws IOException {
	final int type = dis.readByte();
	if (NULL_HANDLE == type) {
		return null;
	} else if (KEY_GROUPS_HANDLE == type) {
		int startKeyGroup = dis.readInt();
		int numKeyGroups = dis.readInt();
		KeyGroupRange keyGroupRange = KeyGroupRange.of(startKeyGroup, startKeyGroup + numKeyGroups - 1);
		long[] offsets = new long[numKeyGroups];
		for (int i = 0; i < numKeyGroups; ++i) {
			offsets[i] = dis.readLong();
		}
		KeyGroupRangeOffsets keyGroupRangeOffsets = new KeyGroupRangeOffsets(
			keyGroupRange, offsets);
		StreamStateHandle stateHandle = deserializeStreamStateHandle(dis);
		return new KeyGroupsStateHandle(keyGroupRangeOffsets, stateHandle);
	} else {
		throw new IllegalStateException("Reading invalid KeyedStateHandle, type: " + type);
	}
}
 
Example #11
Source File: RocksDBSnapshotStrategyBase.java    From flink with Apache License 2.0 6 votes vote down vote up
public RocksDBSnapshotStrategyBase(
	@Nonnull String description,
	@Nonnull RocksDB db,
	@Nonnull ResourceGuard rocksDBResourceGuard,
	@Nonnull TypeSerializer<K> keySerializer,
	@Nonnull LinkedHashMap<String, RocksDbKvStateInfo> kvStateInformation,
	@Nonnull KeyGroupRange keyGroupRange,
	@Nonnegative int keyGroupPrefixBytes,
	@Nonnull LocalRecoveryConfig localRecoveryConfig,
	@Nonnull CloseableRegistry cancelStreamRegistry) {

	super(description);
	this.db = db;
	this.rocksDBResourceGuard = rocksDBResourceGuard;
	this.keySerializer = keySerializer;
	this.kvStateInformation = kvStateInformation;
	this.keyGroupRange = keyGroupRange;
	this.keyGroupPrefixBytes = keyGroupPrefixBytes;
	this.localRecoveryConfig = localRecoveryConfig;
	this.cancelStreamRegistry = cancelStreamRegistry;
}
 
Example #12
Source File: RocksDBSnapshotStrategyBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public RocksDBSnapshotStrategyBase(
	@Nonnull String description,
	@Nonnull RocksDB db,
	@Nonnull ResourceGuard rocksDBResourceGuard,
	@Nonnull TypeSerializer<K> keySerializer,
	@Nonnull LinkedHashMap<String, RocksDbKvStateInfo> kvStateInformation,
	@Nonnull KeyGroupRange keyGroupRange,
	@Nonnegative int keyGroupPrefixBytes,
	@Nonnull LocalRecoveryConfig localRecoveryConfig,
	@Nonnull CloseableRegistry cancelStreamRegistry) {

	super(description);
	this.db = db;
	this.rocksDBResourceGuard = rocksDBResourceGuard;
	this.keySerializer = keySerializer;
	this.kvStateInformation = kvStateInformation;
	this.keyGroupRange = keyGroupRange;
	this.keyGroupPrefixBytes = keyGroupPrefixBytes;
	this.localRecoveryConfig = localRecoveryConfig;
	this.cancelStreamRegistry = cancelStreamRegistry;
}
 
Example #13
Source File: KvStateLocationRegistry.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Notifies the registry about an unregistered KvState instance.
 *
 * @param jobVertexId JobVertexID the KvState instance belongs to
 * @param keyGroupRange Key group index the KvState instance belongs to
 * @param registrationName Name under which the KvState has been registered
 * @throws IllegalArgumentException If another operator registered the state instance
 * @throws IllegalArgumentException If the registration name is not known
 */
public void notifyKvStateUnregistered(
		JobVertexID jobVertexId,
		KeyGroupRange keyGroupRange,
		String registrationName) {

	KvStateLocation location = lookupTable.get(registrationName);

	if (location != null) {
		// Duplicate name if vertex IDs don't match
		if (!location.getJobVertexId().equals(jobVertexId)) {
			throw new IllegalArgumentException("Another operator (" +
					location.getJobVertexId() + ") registered the KvState " +
					"under '" + registrationName + "'.");
		}

		location.unregisterKvState(keyGroupRange);

		if (location.getNumRegisteredKeyGroups() == 0) {
			lookupTable.remove(registrationName);
		}
	} else {
		throw new IllegalArgumentException("Unknown registration name '" +
				registrationName + "'. " + "Probably registration/unregistration race.");
	}
}
 
Example #14
Source File: StateAssignmentOperation.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Determine the subset of {@link KeyGroupsStateHandle KeyGroupsStateHandles} with correct
 * key group index for the given subtask {@link KeyGroupRange}.
 *
 * <p>This is publicly visible to be used in tests.
 */
public static List<KeyedStateHandle> getKeyedStateHandles(
	Collection<? extends KeyedStateHandle> keyedStateHandles,
	KeyGroupRange subtaskKeyGroupRange) {

	List<KeyedStateHandle> subtaskKeyedStateHandles = new ArrayList<>(keyedStateHandles.size());

	for (KeyedStateHandle keyedStateHandle : keyedStateHandles) {
		KeyedStateHandle intersectedKeyedStateHandle = keyedStateHandle.getIntersection(subtaskKeyGroupRange);

		if (intersectedKeyedStateHandle != null) {
			subtaskKeyedStateHandles.add(intersectedKeyedStateHandle);
		}
	}

	return subtaskKeyedStateHandles;
}
 
Example #15
Source File: InternalTimerServiceImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <K, N> InternalTimerServiceImpl<K, N> createInternalTimerService(
	KeyGroupRange keyGroupsList,
	KeyContext keyContext,
	ProcessingTimeService processingTimeService,
	TypeSerializer<K> keySerializer,
	TypeSerializer<N> namespaceSerializer,
	PriorityQueueSetFactory priorityQueueSetFactory) {

	TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer);

	return new InternalTimerServiceImpl<>(
		keyGroupsList,
		keyContext,
		processingTimeService,
		createTimerQueue("__test_processing_timers", timerSerializer, priorityQueueSetFactory),
		createTimerQueue("__test_event_timers", timerSerializer, priorityQueueSetFactory));
}
 
Example #16
Source File: ActorGatewayKvStateRegistryListener.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyKvStateRegistered(
	JobID jobId,
	JobVertexID jobVertexId,
	KeyGroupRange keyGroupRange,
	String registrationName,
	KvStateID kvStateId) {

	Object msg = new KvStateMessage.NotifyKvStateRegistered(
		jobId,
		jobVertexId,
		keyGroupRange,
		registrationName,
		kvStateId,
		kvStateServerAddress);

	jobManager.tell(msg);
}
 
Example #17
Source File: RocksDBIncrementalCheckpointUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Choose the best state handle according to the {@link #STATE_HANDLE_EVALUATOR}
 * to init the initial db.
 *
 * @param restoreStateHandles The candidate state handles.
 * @param targetKeyGroupRange The target key group range.
 * @return The best candidate or null if no candidate was a good fit.
 */
@Nullable
public static KeyedStateHandle chooseTheBestStateHandleForInitial(
	@Nonnull Collection<KeyedStateHandle> restoreStateHandles,
	@Nonnull KeyGroupRange targetKeyGroupRange) {

	KeyedStateHandle bestStateHandle = null;
	double bestScore = 0;
	for (KeyedStateHandle rawStateHandle : restoreStateHandles) {
		double handleScore = STATE_HANDLE_EVALUATOR.apply(rawStateHandle, targetKeyGroupRange);
		if (handleScore > bestScore) {
			bestStateHandle = rawStateHandle;
			bestScore = handleScore;
		}
	}

	return bestStateHandle;
}
 
Example #18
Source File: RocksDBTestUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
public static <K> RocksDBKeyedStateBackend<K> createKeyedStateBackend(
		RocksDBStateBackend rocksDbBackend,
		Environment env,
		TypeSerializer<K> keySerializer) throws IOException {

	return (RocksDBKeyedStateBackend<K>) rocksDbBackend.createKeyedStateBackend(
		env,
		env.getJobID(),
		"test_op",
		keySerializer,
		1,
		new KeyGroupRange(0, 0),
		env.getTaskKvStateRegistry(),
		TtlTimeProvider.DEFAULT,
		new UnregisteredMetricsGroup(),
		Collections.emptyList(),
		new CloseableRegistry());
}
 
Example #19
Source File: InternalTimerServiceImplTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testKeyGroupStartIndexSetting() {

	int startKeyGroupIdx = 7;
	int endKeyGroupIdx = 21;
	KeyGroupRange testKeyGroupList = new KeyGroupRange(startKeyGroupIdx, endKeyGroupIdx);

	TestKeyContext keyContext = new TestKeyContext();

	TestProcessingTimeService processingTimeService = new TestProcessingTimeService();

	InternalTimerServiceImpl<Integer, String> service = createInternalTimerService(
		testKeyGroupList,
		keyContext,
		processingTimeService,
		IntSerializer.INSTANCE,
		StringSerializer.INSTANCE,
		createQueueFactory());

	Assert.assertEquals(startKeyGroupIdx, service.getLocalKeyGroupRangeStartIdx());
}
 
Example #20
Source File: MockKeyedStateBackend.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
MockKeyedStateBackend(
	TaskKvStateRegistry kvStateRegistry,
	TypeSerializer<K> keySerializer,
	ClassLoader userCodeClassLoader,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	ExecutionConfig executionConfig,
	TtlTimeProvider ttlTimeProvider,
	Map<String, Map<K, Map<Object, Object>>> stateValues,
	Map<String, StateSnapshotTransformer<Object>> stateSnapshotFilters,
	CloseableRegistry cancelStreamRegistry) {
	super(kvStateRegistry, keySerializer, userCodeClassLoader,
		numberOfKeyGroups, keyGroupRange, executionConfig, ttlTimeProvider, cancelStreamRegistry);
	this.stateValues = stateValues;
	this.stateSnapshotFilters = stateSnapshotFilters;
}
 
Example #21
Source File: KeyGroupPartitionedPriorityQueueTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private KeyGroupPartitionedPriorityQueue.PartitionQueueSetFactory<
		TestElement, KeyGroupHeapPQSet<TestElement>> newFactory(int initialCapacity) {

	return (keyGroupId, numKeyGroups, keyExtractorFunction, elementComparator) ->
		new KeyGroupHeapPQSet<>(
			elementComparator,
			keyExtractorFunction,
			initialCapacity,
			KeyGroupRange.of(keyGroupId, keyGroupId),
			numKeyGroups);
}
 
Example #22
Source File: InternalTimerServiceImplTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static int getKeyInKeyGroupRange(KeyGroupRange range, int maxParallelism) {
	Random rand = new Random(System.currentTimeMillis());
	int result = rand.nextInt();
	while (!range.contains(KeyGroupRangeAssignment.assignToKeyGroup(result, maxParallelism))) {
		result = rand.nextInt();
	}
	return result;
}
 
Example #23
Source File: InternalTimerServiceImplTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static InternalTimerServiceImpl<Integer, String> restoreTimerService(
		Map<Integer, byte[]> state,
		int snapshotVersion,
		Triggerable<Integer, String> triggerable,
		KeyContext keyContext,
		ProcessingTimeService processingTimeService,
		KeyGroupRange keyGroupsList,
		PriorityQueueSetFactory priorityQueueSetFactory) throws Exception {

	// create an empty service
	InternalTimerServiceImpl<Integer, String> service = createInternalTimerService(
		keyGroupsList,
		keyContext,
		processingTimeService,
		IntSerializer.INSTANCE,
		StringSerializer.INSTANCE,
		priorityQueueSetFactory);

	// restore the timers
	for (Integer keyGroupIndex : keyGroupsList) {
		if (state.containsKey(keyGroupIndex)) {
			try (ByteArrayInputStream inputStream = new ByteArrayInputStream(state.get(keyGroupIndex))) {
				InternalTimersSnapshot<?, ?> restoredTimersSnapshot =
					InternalTimersSnapshotReaderWriters
						.getReaderForVersion(snapshotVersion, InternalTimerServiceImplTest.class.getClassLoader())
						.readTimersSnapshot(new DataInputViewStreamWrapper(inputStream));

				service.restoreTimersForKeyGroup(restoredTimersSnapshot, keyGroupIndex);
			}
		}
	}

	// initialize the service
	service.startTimerService(IntSerializer.INSTANCE, StringSerializer.INSTANCE, triggerable);
	return service;
}
 
Example #24
Source File: KeyGroupPartitionedPriorityQueueTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public KeyGroupHeapPQSet(
	@Nonnull PriorityComparator<T> elementPriorityComparator,
	@Nonnull KeyExtractorFunction<T> keyExtractor,
	int minimumCapacity,
	@Nonnull KeyGroupRange keyGroupRange,
	int totalNumberOfKeyGroups) {
	super(elementPriorityComparator, keyExtractor, minimumCapacity, keyGroupRange, totalNumberOfKeyGroups);
	this.internalIndex = HeapPriorityQueueElement.NOT_CONTAINED;
}
 
Example #25
Source File: FsStateBackend.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend(
	Environment env,
	JobID jobID,
	String operatorIdentifier,
	TypeSerializer<K> keySerializer,
	int numberOfKeyGroups,
	KeyGroupRange keyGroupRange,
	TaskKvStateRegistry kvStateRegistry,
	TtlTimeProvider ttlTimeProvider,
	MetricGroup metricGroup,
	@Nonnull Collection<KeyedStateHandle> stateHandles,
	CloseableRegistry cancelStreamRegistry) throws BackendBuildingException {

	TaskStateManager taskStateManager = env.getTaskStateManager();
	LocalRecoveryConfig localRecoveryConfig = taskStateManager.createLocalRecoveryConfig();
	HeapPriorityQueueSetFactory priorityQueueSetFactory =
		new HeapPriorityQueueSetFactory(keyGroupRange, numberOfKeyGroups, 128);

	return new HeapKeyedStateBackendBuilder<>(
		kvStateRegistry,
		keySerializer,
		env.getUserClassLoader(),
		numberOfKeyGroups,
		keyGroupRange,
		env.getExecutionConfig(),
		ttlTimeProvider,
		stateHandles,
		AbstractStateBackend.getCompressionDecorator(env.getExecutionConfig()),
		localRecoveryConfig,
		priorityQueueSetFactory,
		isUsingAsynchronousSnapshots(),
		cancelStreamRegistry).build();
}
 
Example #26
Source File: KvStateServerHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyKvStateRegistered(JobID jobId,
		JobVertexID jobVertexId,
		KeyGroupRange keyGroupRange,
		String registrationName,
		KvStateID kvStateId) {
	this.jobVertexID = jobVertexId;
	this.keyGroupIndex = keyGroupRange;
	this.registrationName = registrationName;
	this.kvStateId = kvStateId;
}
 
Example #27
Source File: KvStateServerHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyKvStateUnregistered(JobID jobId,
		JobVertexID jobVertexId,
		KeyGroupRange keyGroupRange,
		String registrationName) {

}
 
Example #28
Source File: InternalTimeServiceManager.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
InternalTimeServiceManager(
	KeyGroupRange localKeyGroupRange,
	KeyContext keyContext,
	PriorityQueueSetFactory priorityQueueSetFactory,
	ProcessingTimeService processingTimeService, boolean useLegacySynchronousSnapshots) {

	this.localKeyGroupRange = Preconditions.checkNotNull(localKeyGroupRange);
	this.priorityQueueSetFactory = Preconditions.checkNotNull(priorityQueueSetFactory);
	this.keyContext = Preconditions.checkNotNull(keyContext);
	this.processingTimeService = Preconditions.checkNotNull(processingTimeService);
	this.useLegacySynchronousSnapshots = useLegacySynchronousSnapshots;

	this.timerServices = new HashMap<>();
}
 
Example #29
Source File: KeyGroupPartitionedPriorityQueueTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private KeyGroupPartitionedPriorityQueue.PartitionQueueSetFactory<
		TestElement, KeyGroupHeapPQSet<TestElement>> newFactory(int initialCapacity) {

	return (keyGroupId, numKeyGroups, keyExtractorFunction, elementComparator) ->
		new KeyGroupHeapPQSet<>(
			elementComparator,
			keyExtractorFunction,
			initialCapacity,
			KeyGroupRange.of(keyGroupId, keyGroupId),
			numKeyGroups);
}
 
Example #30
Source File: StreamTaskStateInitializerImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
protected <K> InternalTimeServiceManager<K> internalTimeServiceManager(
	AbstractKeyedStateBackend<K> keyedStatedBackend,
	KeyContext keyContext, //the operator
	Iterable<KeyGroupStatePartitionStreamProvider> rawKeyedStates) throws Exception {

	if (keyedStatedBackend == null) {
		return null;
	}

	final KeyGroupRange keyGroupRange = keyedStatedBackend.getKeyGroupRange();

	final InternalTimeServiceManager<K> timeServiceManager = new InternalTimeServiceManager<>(
		keyGroupRange,
		keyContext,
		keyedStatedBackend,
		processingTimeService,
		keyedStatedBackend.requiresLegacySynchronousTimerSnapshots());

	// and then initialize the timer services
	for (KeyGroupStatePartitionStreamProvider streamProvider : rawKeyedStates) {
		int keyGroupIdx = streamProvider.getKeyGroupId();

		Preconditions.checkArgument(keyGroupRange.contains(keyGroupIdx),
			"Key Group " + keyGroupIdx + " does not belong to the local range.");

		timeServiceManager.restoreStateForKeyGroup(
			streamProvider.getStream(),
			keyGroupIdx, environment.getUserClassLoader());
	}

	return timeServiceManager;
}