【问题标题】:How does Flink treat timestamps within iterative loops?Flink 如何处理迭代循环中的时间戳?
【发布时间】:2019-06-10 11:50:48
【问题描述】:

在 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 如何处理常规输入和反馈对象流中输入对象的排序?如果我将一个对象发射到反馈循环中,相对于输入对象的常规流,循环的头部何时会看到它?
  • 使用事件时间处理时行为有何变化?

【问题讨论】:

    标签: apache-flink flink-streaming


    【解决方案1】:

    AFAICT,Flink 不对输入对象的顺序提供任何保证。我在尝试在 Flink 中对聚类算法使用迭代时遇到了这个问题,其中质心更新没有得到及时处理。我发现的唯一解决方案基本上是创建传入事件和质心更新的单个(联合)流,而不是使用协同流。

    仅供参考,this proposal 可以解决迭代的一些缺点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      • 2021-05-04
      • 1970-01-01
      • 2021-06-29
      • 2018-01-01
      • 1970-01-01
      • 2017-02-03
      相关资源
      最近更新 更多