Java Code Examples for org.apache.flink.runtime.checkpoint.OperatorSubtaskState#getRawOperatorState()

The following examples show how to use org.apache.flink.runtime.checkpoint.OperatorSubtaskState#getRawOperatorState() . 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: AbstractStreamOperatorTestHarness.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Takes the different {@link OperatorSubtaskState} created by calling {@link #snapshot(long, long)}
 * on different instances of {@link AbstractStreamOperatorTestHarness} (each one representing one subtask)
 * and repacks them into a single {@link OperatorSubtaskState} so that the parallelism of the test
 * can change arbitrarily (i.e. be able to scale both up and down).
 *
 * <p>After repacking the partial states, remember to use
 * {@link #repartitionOperatorState(OperatorSubtaskState, int, int, int, int)} to reshape 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. Bear in mind that for parallelism greater than one, you
 * have to use the constructor {@link #AbstractStreamOperatorTestHarness(StreamOperator, int, int, int)}.
 *
 * <p><b>NOTE: </b> each of the {@code handles} in the argument list is assumed to be from a single task of a single
 * operator (i.e. chain length of one).
 *
 * <p>For an example of how to use it, have a look at
 * {@link AbstractStreamOperatorTest#testStateAndTimerStateShufflingScalingDown()}.
 *
 * @param handles the different states to be merged.
 * @return the resulting state, or {@code null} if no partial states are specified.
 */
public static OperatorSubtaskState repackageState(OperatorSubtaskState... handles) throws Exception {

	if (handles.length < 1) {
		return null;
	} else if (handles.length == 1) {
		return handles[0];
	}

	List<OperatorStateHandle> mergedManagedOperatorState = new ArrayList<>(handles.length);
	List<OperatorStateHandle> mergedRawOperatorState = new ArrayList<>(handles.length);

	List<KeyedStateHandle> mergedManagedKeyedState = new ArrayList<>(handles.length);
	List<KeyedStateHandle> mergedRawKeyedState = new ArrayList<>(handles.length);

	for (OperatorSubtaskState handle : handles) {

		Collection<OperatorStateHandle> managedOperatorState = handle.getManagedOperatorState();
		Collection<OperatorStateHandle> rawOperatorState = handle.getRawOperatorState();
		Collection<KeyedStateHandle> managedKeyedState = handle.getManagedKeyedState();
		Collection<KeyedStateHandle> rawKeyedState = handle.getRawKeyedState();

		mergedManagedOperatorState.addAll(managedOperatorState);
		mergedRawOperatorState.addAll(rawOperatorState);
		mergedManagedKeyedState.addAll(managedKeyedState);
		mergedRawKeyedState.addAll(rawKeyedState);
	}

	return new OperatorSubtaskState(
		new StateObjectCollection<>(mergedManagedOperatorState),
		new StateObjectCollection<>(mergedRawOperatorState),
		new StateObjectCollection<>(mergedManagedKeyedState),
		new StateObjectCollection<>(mergedRawKeyedState));
}
 
Example 2
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Takes the different {@link OperatorSubtaskState} created by calling {@link #snapshot(long, long)}
 * on different instances of {@link AbstractStreamOperatorTestHarness} (each one representing one subtask)
 * and repacks them into a single {@link OperatorSubtaskState} so that the parallelism of the test
 * can change arbitrarily (i.e. be able to scale both up and down).
 *
 * <p>After repacking the partial states, remember to use
 * {@link #repartitionOperatorState(OperatorSubtaskState, int, int, int, int)} to reshape 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. Bear in mind that for parallelism greater than one, you
 * have to use the constructor {@link #AbstractStreamOperatorTestHarness(StreamOperator, int, int, int)}.
 *
 * <p><b>NOTE: </b> each of the {@code handles} in the argument list is assumed to be from a single task of a single
 * operator (i.e. chain length of one).
 *
 * <p>For an example of how to use it, have a look at
 * {@link AbstractStreamOperatorTest#testStateAndTimerStateShufflingScalingDown()}.
 *
 * @param handles the different states to be merged.
 * @return the resulting state, or {@code null} if no partial states are specified.
 */
public static OperatorSubtaskState repackageState(OperatorSubtaskState... handles) throws Exception {

	if (handles.length < 1) {
		return null;
	} else if (handles.length == 1) {
		return handles[0];
	}

	List<OperatorStateHandle> mergedManagedOperatorState = new ArrayList<>(handles.length);
	List<OperatorStateHandle> mergedRawOperatorState = new ArrayList<>(handles.length);

	List<KeyedStateHandle> mergedManagedKeyedState = new ArrayList<>(handles.length);
	List<KeyedStateHandle> mergedRawKeyedState = new ArrayList<>(handles.length);

	for (OperatorSubtaskState handle : handles) {

		Collection<OperatorStateHandle> managedOperatorState = handle.getManagedOperatorState();
		Collection<OperatorStateHandle> rawOperatorState = handle.getRawOperatorState();
		Collection<KeyedStateHandle> managedKeyedState = handle.getManagedKeyedState();
		Collection<KeyedStateHandle> rawKeyedState = handle.getRawKeyedState();

		mergedManagedOperatorState.addAll(managedOperatorState);
		mergedRawOperatorState.addAll(rawOperatorState);
		mergedManagedKeyedState.addAll(managedKeyedState);
		mergedRawKeyedState.addAll(rawKeyedState);
	}

	return new OperatorSubtaskState(
		new StateObjectCollection<>(mergedManagedOperatorState),
		new StateObjectCollection<>(mergedRawOperatorState),
		new StateObjectCollection<>(mergedManagedKeyedState),
		new StateObjectCollection<>(mergedRawKeyedState));
}
 
Example 3
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Takes the different {@link OperatorSubtaskState} created by calling {@link #snapshot(long, long)}
 * on different instances of {@link AbstractStreamOperatorTestHarness} (each one representing one subtask)
 * and repacks them into a single {@link OperatorSubtaskState} so that the parallelism of the test
 * can change arbitrarily (i.e. be able to scale both up and down).
 *
 * <p>After repacking the partial states, remember to use
 * {@link #repartitionOperatorState(OperatorSubtaskState, int, int, int, int)} to reshape 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. Bear in mind that for parallelism greater than one, you
 * have to use the constructor {@link #AbstractStreamOperatorTestHarness(StreamOperator, int, int, int)}.
 *
 * <p><b>NOTE: </b> each of the {@code handles} in the argument list is assumed to be from a single task of a single
 * operator (i.e. chain length of one).
 *
 * <p>For an example of how to use it, have a look at
 * {@link AbstractStreamOperatorTest#testStateAndTimerStateShufflingScalingDown()}.
 *
 * @param handles the different states to be merged.
 * @return the resulting state, or {@code null} if no partial states are specified.
 */
public static OperatorSubtaskState repackageState(OperatorSubtaskState... handles) throws Exception {

	if (handles.length < 1) {
		return null;
	} else if (handles.length == 1) {
		return handles[0];
	}

	List<OperatorStateHandle> mergedManagedOperatorState = new ArrayList<>(handles.length);
	List<OperatorStateHandle> mergedRawOperatorState = new ArrayList<>(handles.length);

	List<KeyedStateHandle> mergedManagedKeyedState = new ArrayList<>(handles.length);
	List<KeyedStateHandle> mergedRawKeyedState = new ArrayList<>(handles.length);

	for (OperatorSubtaskState handle : handles) {

		Collection<OperatorStateHandle> managedOperatorState = handle.getManagedOperatorState();
		Collection<OperatorStateHandle> rawOperatorState = handle.getRawOperatorState();
		Collection<KeyedStateHandle> managedKeyedState = handle.getManagedKeyedState();
		Collection<KeyedStateHandle> rawKeyedState = handle.getRawKeyedState();

		mergedManagedOperatorState.addAll(managedOperatorState);
		mergedRawOperatorState.addAll(rawOperatorState);
		mergedManagedKeyedState.addAll(managedKeyedState);
		mergedRawKeyedState.addAll(rawKeyedState);
	}

	return new OperatorSubtaskState(
		new StateObjectCollection<>(mergedManagedOperatorState),
		new StateObjectCollection<>(mergedRawOperatorState),
		new StateObjectCollection<>(mergedManagedKeyedState),
		new StateObjectCollection<>(mergedRawKeyedState));
}
 
Example 4
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 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 = 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 6
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)));
}