如题,今天来分享下之前解决过的一个问题,即Flink窗口延迟数据丢失。
流计算在支持Event Time的时候,引入了Watermark的概念(MillWheel提出这个概念的时候是叫Low Watermark,即低水位,鄙视翻译成水印的:),所有早于Watermark的数据都被认为是延迟数据。而在Flink的窗口计算当中,允许用户指定数据延迟的最大时间,即设置allowedLateness,超过这个时间的数据将会被丢弃,不参与窗口计算。Flink会将被丢弃的数据用SideOutput输出。
具体的实现在WindowOperator#processElement,
for (W window: elementWindows) {
// drop if the window is already late
if (isWindowLate(window)) {
continue;
}
isSkippedElement = false;
windowState.setCurrentNamespace(window);
windowState.add(element.getValue());
triggerContext.key = key;
triggerContext.window = window;
TriggerResult triggerResult = triggerContext.onElement(element);
if (triggerResult.isFire()) {
ACC contents = windowState.get();
if (contents == null) {
continue

本文探讨了Flink中窗口延迟数据丢失的问题,通过自定义Trigger解决了数据丢失,并提出了优化方案,避免了同一窗口多次输出,同时保持了窗口状态的有效管理。
最低0.47元/天 解锁文章
1614





