Java Code Examples for org.apache.flink.runtime.checkpoint.StateAssignmentOperation#createKeyGroupPartitions()

The following examples show how to use org.apache.flink.runtime.checkpoint.StateAssignmentOperation#createKeyGroupPartitions() . 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: KeyedStateInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<KeyGroupRange> sortedKeyGroupRanges(int minNumSplits, int maxParallelism) {
	List<KeyGroupRange> keyGroups = StateAssignmentOperation.createKeyGroupPartitions(
		maxParallelism,
		Math.min(minNumSplits, maxParallelism));

	keyGroups.sort(Comparator.comparing(KeyGroupRange::getStartKeyGroup));
	return keyGroups;
}
 
Example 2
Source File: KeyedStateInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<KeyGroupRange> sortedKeyGroupRanges(int minNumSplits, int maxParallelism) {
	List<KeyGroupRange> keyGroups = StateAssignmentOperation.createKeyGroupPartitions(
		maxParallelism,
		Math.min(minNumSplits, maxParallelism));

	keyGroups.sort(Comparator.comparing(KeyGroupRange::getStartKeyGroup));
	return keyGroups;
}
 
Example 3
Source File: AbstractStreamOperatorTestHarness.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the reshaped the state handles to include only those key-group states in the local key-group range
 * and the operator states that would be assigned to the local subtask.
 */
public static OperatorSubtaskState repartitionOperatorState(
	final OperatorSubtaskState operatorStateHandles,
	final int numKeyGroups,
	final int oldParallelism,
	final int newParallelism,
	final int subtaskIndex) {

	Preconditions.checkNotNull(operatorStateHandles, "the previous operatorStateHandles should not be null.");

	// create a new OperatorStateHandles that only contains the state for our key-groups

	List<KeyGroupRange> keyGroupPartitions = StateAssignmentOperation.createKeyGroupPartitions(
		numKeyGroups,
		newParallelism);

	KeyGroupRange localKeyGroupRange = keyGroupPartitions.get(subtaskIndex);

	List<KeyedStateHandle> localManagedKeyGroupState = StateAssignmentOperation.getKeyedStateHandles(
		operatorStateHandles.getManagedKeyedState(),
		localKeyGroupRange);

	List<KeyedStateHandle> localRawKeyGroupState = StateAssignmentOperation.getKeyedStateHandles(
		operatorStateHandles.getRawKeyedState(),
		localKeyGroupRange);

	StateObjectCollection<OperatorStateHandle> managedOperatorStates = operatorStateHandles.getManagedOperatorState();
	Collection<OperatorStateHandle> localManagedOperatorState;

	if (!managedOperatorStates.isEmpty()) {
		List<List<OperatorStateHandle>> managedOperatorState =
			managedOperatorStates.stream().map(Collections::singletonList).collect(Collectors.toList());

		localManagedOperatorState = operatorStateRepartitioner.repartitionState(
			managedOperatorState,
			oldParallelism,
			newParallelism).get(subtaskIndex);
	} else {
		localManagedOperatorState = Collections.emptyList();
	}

	StateObjectCollection<OperatorStateHandle> rawOperatorStates = operatorStateHandles.getRawOperatorState();
	Collection<OperatorStateHandle> localRawOperatorState;

	if (!rawOperatorStates.isEmpty()) {
		List<List<OperatorStateHandle>> rawOperatorState =
			rawOperatorStates.stream().map(Collections::singletonList).collect(Collectors.toList());

		localRawOperatorState = operatorStateRepartitioner.repartitionState(
			rawOperatorState,
			oldParallelism,
			newParallelism).get(subtaskIndex);
	} else {
		localRawOperatorState = Collections.emptyList();
	}

	return new OperatorSubtaskState(
		new StateObjectCollection<>(nullToEmptyCollection(localManagedOperatorState)),
		new StateObjectCollection<>(nullToEmptyCollection(localRawOperatorState)),
		new StateObjectCollection<>(nullToEmptyCollection(localManagedKeyGroupState)),
		new StateObjectCollection<>(nullToEmptyCollection(localRawKeyGroupState)));
}
 
Example 4
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the reshaped the state handles to include only those key-group states in the local key-group range
 * and the operator states that would be assigned to the local subtask.
 */
public static OperatorSubtaskState repartitionOperatorState(
	final OperatorSubtaskState operatorStateHandles,
	final int numKeyGroups,
	final int oldParallelism,
	final int newParallelism,
	final int subtaskIndex) {

	Preconditions.checkNotNull(operatorStateHandles, "the previous operatorStateHandles should not be null.");

	// create a new OperatorStateHandles that only contains the state for our key-groups

	List<KeyGroupRange> keyGroupPartitions = StateAssignmentOperation.createKeyGroupPartitions(
		numKeyGroups,
		newParallelism);

	KeyGroupRange localKeyGroupRange = keyGroupPartitions.get(subtaskIndex);

	List<KeyedStateHandle> localManagedKeyGroupState = StateAssignmentOperation.getKeyedStateHandles(
		operatorStateHandles.getManagedKeyedState(),
		localKeyGroupRange);

	List<KeyedStateHandle> localRawKeyGroupState = StateAssignmentOperation.getKeyedStateHandles(
		operatorStateHandles.getRawKeyedState(),
		localKeyGroupRange);

	StateObjectCollection<OperatorStateHandle> managedOperatorStates = operatorStateHandles.getManagedOperatorState();
	Collection<OperatorStateHandle> localManagedOperatorState;

	if (!managedOperatorStates.isEmpty()) {
		List<List<OperatorStateHandle>> managedOperatorState =
			managedOperatorStates.stream().map(Collections::singletonList).collect(Collectors.toList());

		localManagedOperatorState = operatorStateRepartitioner.repartitionState(
			managedOperatorState,
			oldParallelism,
			newParallelism).get(subtaskIndex);
	} else {
		localManagedOperatorState = Collections.emptyList();
	}

	StateObjectCollection<OperatorStateHandle> rawOperatorStates = operatorStateHandles.getRawOperatorState();
	Collection<OperatorStateHandle> localRawOperatorState;

	if (!rawOperatorStates.isEmpty()) {
		List<List<OperatorStateHandle>> rawOperatorState =
			rawOperatorStates.stream().map(Collections::singletonList).collect(Collectors.toList());

		localRawOperatorState = operatorStateRepartitioner.repartitionState(
			rawOperatorState,
			oldParallelism,
			newParallelism).get(subtaskIndex);
	} else {
		localRawOperatorState = Collections.emptyList();
	}

	return new OperatorSubtaskState(
		new StateObjectCollection<>(nullToEmptyCollection(localManagedOperatorState)),
		new StateObjectCollection<>(nullToEmptyCollection(localRawOperatorState)),
		new StateObjectCollection<>(nullToEmptyCollection(localManagedKeyGroupState)),
		new StateObjectCollection<>(nullToEmptyCollection(localRawKeyGroupState)));
}
 
Example 5
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the reshaped the state handles to include only those key-group states in the local key-group range
 * and the operator states that would be assigned to the local subtask.
 */
public static OperatorSubtaskState repartitionOperatorState(
	final OperatorSubtaskState operatorStateHandles,
	final int numKeyGroups,
	final int oldParallelism,
	final int newParallelism,
	final int subtaskIndex) {

	Preconditions.checkNotNull(operatorStateHandles, "the previous operatorStateHandles should not be null.");

	// create a new OperatorStateHandles that only contains the state for our key-groups

	List<KeyGroupRange> keyGroupPartitions = StateAssignmentOperation.createKeyGroupPartitions(
		numKeyGroups,
		newParallelism);

	KeyGroupRange localKeyGroupRange = keyGroupPartitions.get(subtaskIndex);

	List<KeyedStateHandle> localManagedKeyGroupState = new ArrayList<>();
	StateAssignmentOperation.extractIntersectingState(
		operatorStateHandles.getManagedKeyedState(),
		localKeyGroupRange,
		localManagedKeyGroupState);

	List<KeyedStateHandle> localRawKeyGroupState = new ArrayList<>();
	StateAssignmentOperation.extractIntersectingState(
		operatorStateHandles.getRawKeyedState(),
		localKeyGroupRange,
		localRawKeyGroupState);

	StateObjectCollection<OperatorStateHandle> managedOperatorStates = operatorStateHandles.getManagedOperatorState();
	Collection<OperatorStateHandle> localManagedOperatorState;

	if (!managedOperatorStates.isEmpty()) {
		List<List<OperatorStateHandle>> managedOperatorState =
			managedOperatorStates.stream().map(Collections::singletonList).collect(Collectors.toList());

		localManagedOperatorState = operatorStateRepartitioner.repartitionState(
			managedOperatorState,
			oldParallelism,
			newParallelism).get(subtaskIndex);
	} else {
		localManagedOperatorState = Collections.emptyList();
	}

	StateObjectCollection<OperatorStateHandle> rawOperatorStates = operatorStateHandles.getRawOperatorState();
	Collection<OperatorStateHandle> localRawOperatorState;

	if (!rawOperatorStates.isEmpty()) {
		List<List<OperatorStateHandle>> rawOperatorState =
			rawOperatorStates.stream().map(Collections::singletonList).collect(Collectors.toList());

		localRawOperatorState = operatorStateRepartitioner.repartitionState(
			rawOperatorState,
			oldParallelism,
			newParallelism).get(subtaskIndex);
	} else {
		localRawOperatorState = Collections.emptyList();
	}

	return new OperatorSubtaskState(
		new StateObjectCollection<>(nullToEmptyCollection(localManagedOperatorState)),
		new StateObjectCollection<>(nullToEmptyCollection(localRawOperatorState)),
		new StateObjectCollection<>(nullToEmptyCollection(localManagedKeyGroupState)),
		new StateObjectCollection<>(nullToEmptyCollection(localRawKeyGroupState)));
}