本文整理汇总了Java中org.apache.flink.streaming.runtime.tasks.OperatorStateHandles.getManagedKeyedState方法的典型用法代码示例。如果您正苦于以下问题:Java OperatorStateHandles.getManagedKeyedState方法的具体用法?Java OperatorStateHandles.getManagedKeyedState怎么用?Java OperatorStateHandles.getManagedKeyedState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.streaming.runtime.tasks.OperatorStateHandles
的用法示例。
在下文中一共展示了OperatorStateHandles.getManagedKeyedState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeState
import org.apache.flink.streaming.runtime.tasks.OperatorStateHandles; //导入方法依赖的package包/类
@Override
public void initializeState(OperatorStateHandles operatorStateHandles) throws Exception {
if (restoredKeyedState != null) {
restoredKeyedState = operatorStateHandles.getManagedKeyedState();
}
super.initializeState(operatorStateHandles);
}
示例2: initializeState
import org.apache.flink.streaming.runtime.tasks.OperatorStateHandles; //导入方法依赖的package包/类
@Override
public void initializeState(OperatorStateHandles operatorStateHandles) throws Exception {
if (operatorStateHandles != null) {
int numKeyGroups = getEnvironment().getTaskInfo().getMaxNumberOfParallelSubtasks();
int numSubtasks = getEnvironment().getTaskInfo().getNumberOfParallelSubtasks();
int subtaskIndex = getEnvironment().getTaskInfo().getIndexOfThisSubtask();
// create a new OperatorStateHandles that only contains the state for our key-groups
List<KeyGroupRange> keyGroupPartitions = StateAssignmentOperation.createKeyGroupPartitions(
numKeyGroups,
numSubtasks);
KeyGroupRange localKeyGroupRange =
keyGroupPartitions.get(subtaskIndex);
restoredKeyedState = null;
Collection<KeyedStateHandle> managedKeyedState = operatorStateHandles.getManagedKeyedState();
if (managedKeyedState != null) {
// if we have migration handles, don't reshuffle state and preserve
// the migration tag
if (hasMigrationHandles(managedKeyedState)) {
List<KeyedStateHandle> result = new ArrayList<>(managedKeyedState.size());
result.addAll(managedKeyedState);
restoredKeyedState = result;
} else {
restoredKeyedState = StateAssignmentOperation.getKeyedStateHandles(
managedKeyedState,
localKeyGroupRange);
}
}
}
super.initializeState(operatorStateHandles);
}
示例3: initializeState
import org.apache.flink.streaming.runtime.tasks.OperatorStateHandles; //导入方法依赖的package包/类
/**
* Calls {@link org.apache.flink.streaming.api.operators.StreamOperator#initializeState(OperatorSubtaskState)}.
* Calls {@link org.apache.flink.streaming.api.operators.StreamOperator#setup(StreamTask, StreamConfig, Output)}
* if it was not called before.
*
* <p>This will 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.
*/
public void initializeState(OperatorStateHandles operatorStateHandles) throws Exception {
if (!setupCalled) {
setup();
}
if (operatorStateHandles != null) {
int numKeyGroups = getEnvironment().getTaskInfo().getMaxNumberOfParallelSubtasks();
int numSubtasks = getEnvironment().getTaskInfo().getNumberOfParallelSubtasks();
int subtaskIndex = getEnvironment().getTaskInfo().getIndexOfThisSubtask();
// create a new OperatorStateHandles that only contains the state for our key-groups
List<KeyGroupRange> keyGroupPartitions = StateAssignmentOperation.createKeyGroupPartitions(
numKeyGroups,
numSubtasks);
KeyGroupRange localKeyGroupRange =
keyGroupPartitions.get(subtaskIndex);
List<KeyedStateHandle> localManagedKeyGroupState = null;
if (operatorStateHandles.getManagedKeyedState() != null) {
localManagedKeyGroupState = StateAssignmentOperation.getKeyedStateHandles(
operatorStateHandles.getManagedKeyedState(),
localKeyGroupRange);
}
List<KeyedStateHandle> localRawKeyGroupState = null;
if (operatorStateHandles.getRawKeyedState() != null) {
localRawKeyGroupState = StateAssignmentOperation.getKeyedStateHandles(
operatorStateHandles.getRawKeyedState(),
localKeyGroupRange);
}
List<OperatorStateHandle> managedOperatorState = new ArrayList<>();
if (operatorStateHandles.getManagedOperatorState() != null) {
managedOperatorState.addAll(operatorStateHandles.getManagedOperatorState());
}
Collection<OperatorStateHandle> localManagedOperatorState = operatorStateRepartitioner.repartitionState(
managedOperatorState,
numSubtasks).get(subtaskIndex);
List<OperatorStateHandle> rawOperatorState = new ArrayList<>();
if (operatorStateHandles.getRawOperatorState() != null) {
rawOperatorState.addAll(operatorStateHandles.getRawOperatorState());
}
Collection<OperatorStateHandle> localRawOperatorState = operatorStateRepartitioner.repartitionState(
rawOperatorState,
numSubtasks).get(subtaskIndex);
OperatorSubtaskState massagedOperatorStateHandles = new OperatorSubtaskState(
nullToEmptyCollection(localManagedOperatorState),
nullToEmptyCollection(localRawOperatorState),
nullToEmptyCollection(localManagedKeyGroupState),
nullToEmptyCollection(localRawKeyGroupState));
operator.initializeState(massagedOperatorStateHandles);
} else {
operator.initializeState(null);
}
initializeCalled = true;
}
示例4: repackageState
import org.apache.flink.streaming.runtime.tasks.OperatorStateHandles; //导入方法依赖的package包/类
/**
* Takes the different {@link OperatorStateHandles} 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 OperatorStateHandles} 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, use {@link #initializeState(OperatorStateHandles)} to initialize
* a new instance with the resulting state. 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 OperatorStateHandles repackageState(OperatorStateHandles... 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 (OperatorStateHandles handle: handles) {
Collection<OperatorStateHandle> managedOperatorState = handle.getManagedOperatorState();
Collection<OperatorStateHandle> rawOperatorState = handle.getRawOperatorState();
Collection<KeyedStateHandle> managedKeyedState = handle.getManagedKeyedState();
Collection<KeyedStateHandle> rawKeyedState = handle.getRawKeyedState();
if (managedOperatorState != null) {
mergedManagedOperatorState.addAll(managedOperatorState);
}
if (rawOperatorState != null) {
mergedRawOperatorState.addAll(rawOperatorState);
}
if (managedKeyedState != null) {
mergedManagedKeyedState.addAll(managedKeyedState);
}
if (rawKeyedState != null) {
mergedRawKeyedState.addAll(rawKeyedState);
}
}
return new OperatorStateHandles(
0,
mergedManagedKeyedState,
mergedRawKeyedState,
mergedManagedOperatorState,
mergedRawOperatorState);
}