版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yangguosb/article/details/85112236
背景
使用Event time时间模型时,由于网络或传输等原因,事件被Flink处理的顺序不一定是事件产生的顺序(乱序),可能会存在两方面影响:
- 当前窗口不知道何时停止,开始计算结果;
- 影响窗口计算结果的准确性,见示例;
WaterMark机制
WaterMark本质上是一个带有时间戳的特殊event,当Flink中的运算符接收到水印时,它明白(假设)它不会看到比该时间戳更早的消息。
A Watermark(t) declares that event time has reached time t in that stream, meaning that there should be no more elements from the stream with a timestamp t’ <= t (i.e. events with timestamps older or equal to the watermark).It can then safely compute and emit the result of the window
生成WaterMark
WaterMark需要开发人员根据具体的场景采取合适的策略生成;
生成方式:
- 数据源中产生;
- 在Flink入口处生成( Watermark Generators);
并发WaterMark
场景:一个operator存在多个输入流,可能同时收到多个WaterMark;
处理原则:使用时间戳最小的WaterMark更新当前窗口的Event time,这意味着窗口会等待所有的输入流数据到达才会开始计算;
参考: