如果我们在 KeyedStream#process 的 KeyedProcessFunction 中填充状态对象,例如
new KeyedProcessFunction<String, Rule, Rule>() {
private MapState<String, ArrayList<Rule>> rulesState;
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
rulesState = getRuntimeContext().getMapState(Descriptors.rulesPerCustomerDescriptor);
}
@Override
public void processElement(Rule value, KeyedProcessFunction<String, Rule, Rule>.Context ctx, Collector<Rule> out) throws Exception {
out.collect(value);
rulesState.put();
}
});
如果另一个 KeyedStream#process 方法都使用相同的键进行分区,我们会从另一个 KeyedStream#process 方法中获得相同的状态对象吗?
不。状态对于建立状态的特定运营商而言是本地的。无法从其他任何地方访问它。