如何在Flink的迭代DataStream循环中处理时间戳?
例如,这是Flink中的简单迭代循环的示例,其中反馈循环与输入流的类型不同:
DataStream<MyInput> inputStream = env.addSource(new MyInputSourceFunction());
IterativeStream.ConnectedIterativeStreams<MyInput, MyFeedback> iterativeStream = inputStream.iterate().withFeedbackType(MyFeedback.class);
// define an output tag so we can emit feedback objects via a side output
final OutputTag<MyFeedback> outputTag = new OutputTag<MyFeedback>("feedback-output"){};
// now do some processing
SingleOutputStreamOperator<MyOutput> combinedStreams = iterativeStream.process(new CoProcessFunction<MyInput, MyFeedback, MyOutput>() {
@Override
public void processElement1(MyInput value, Context ctx, Collector<MyOutput> out) throws Exception {
// do some processing of the stream of MyInput values
// emit MyOutput values downstream by calling out.collect()
out.collect(someInstanceOfMyOutput);
}
@Override
public void processElement2(MyFeedback value, Context ctx, Collector<MyOutput> out) throws Exception {
// do some more processing on the feedback classes
// emit feedback items
ctx.output(outputTag, someInstanceOfMyFeedback);
}
});
iterativeStream.closeWith(combinedStreams.getSideOutput(outputTag));
我的问题围绕Flink如何在反馈循环中使用时间戳:
ConnectedIterativeStreams
中,Flink如何处理常规输入和反馈对象流中输入对象的排序?如果我将一个对象放到反馈循环中,那么相对于常规的输入对象流,循环的开头何时可以看到它?答案 0 :(得分:0)
AFAICT,Flink对输入对象的顺序不提供任何保证。在Flink中尝试对群集算法使用迭代时,我遇到了这种情况,因为质心更新无法及时得到处理。我发现的唯一解决方案是从本质上创建传入事件和质心更新的单个(非离子化)流,而不是使用辅助流。
仅供参考,this proposal可以解决某些迭代的缺点。