WindowOperator

processElement

final Collection<W> elementWindows = windowAssigner.assignWindows(   //找出该element被assign的所有windows
element.getValue(), element.getTimestamp(), windowAssignerContext); //if element is handled by none of assigned elementWindows
boolean isSkippedElement = true; //element默认是会skiped for (W window: elementWindows) { // drop if the window is already late
if (isWindowLate(window)) { //如果window是late,逻辑是window.maxTimestamp() + allowedLateness <= internalTimerService.currentWatermark(),continue表示skip
continue;
}
isSkippedElement = false; //只要有一个窗口非late,该element就是非late数据 windowState.setCurrentNamespace(window);
windowState.add(element.getValue()); //把数据加到windowState中 triggerContext.key = key;
triggerContext.window = window; //EventTimeTrigger,(window.maxTimestamp() <= ctx.getCurrentWatermark(),会立即fire
//否则只是ctx.registerEventTimeTimer(window.maxTimestamp()),注册等待后续watermark来触发
TriggerResult triggerResult = triggerContext.onElement(element); if (triggerResult.isFire()) { //如果Fire
ACC contents = windowState.get();
if (contents == null) {
continue;
}
emitWindowContents(window, contents); //emit window内容, 这里会调用自己定义的user function
} //对于比较常用的TumblingEventTimeWindows,用EventTimeTrigger,所以是不会触发purge的
if (triggerResult.isPurge()) { //如果purge
windowState.clear(); //将window的state清除掉
}
registerCleanupTimer(window); //window的数据也需要清除
} // side output input event if
// element not handled by any window
// late arriving tag has been set
// windowAssigner is event time and current timestamp + allowed lateness no less than element timestamp
//如果所有的assign window都是late,再判断一下element也是late
if (isSkippedElement && isElementLate(element)) { //isElementLate, (element.getTimestamp() + allowedLateness <= internalTimerService.currentWatermark())
if (lateDataOutputTag != null){
sideOutput(element); //如果定义了sideOutput,就输出late element
} else {
this.numLateRecordsDropped.inc(); //否则直接丢弃
}
} 这里currentWatermark的默认值,
private long currentWatermark = Long.MIN_VALUE;

如果定期发送watermark,那么在第一次收到watermark前,不会有late数据

继续看看,数据清除掉逻辑
protected void registerCleanupTimer(W window) {
long cleanupTime = cleanupTime(window); //cleanupTime, window.maxTimestamp() + allowedLateness if (windowAssigner.isEventTime()) {
triggerContext.registerEventTimeTimer(cleanupTime); //这里只是简单的注册registerEventTimeTimer
} else {
triggerContext.registerProcessingTimeTimer(cleanupTime);
}
}

如果clear只是简单的注册EventTimeTimer,那么在onEventTime的时候一定有clear的逻辑、

WindowOperator.onEventTime

if (windowAssigner.isEventTime() && isCleanupTime(triggerContext.window, timer.getTimestamp())) {  //time == cleanupTime(window);
clearAllState(triggerContext.window, windowState, mergingWindows);
}

果然,onEventTime的时候会判断,如果Timer的time等于 window的cleanup time,就把all state清除掉

所以当超过,window.maxTimestamp() + allowedLateness就会被清理掉

Flink - allowedLateness的更多相关文章

  1. Flink 灵魂两百问,这谁顶得住?

    Flink 学习 https://github.com/zhisheng17/flink-learning 麻烦路过的各位亲给这个项目点个 star,太不易了,写了这么多,算是对我坚持下来的一种鼓励吧 ...

  2. flink Window的Timestamps/Watermarks和allowedLateness的区别

    Watermartks是通过additional的时间戳来控制窗口激活的时间,allowedLateness来控制窗口的销毁时间.   注: 因为此特性包括官方文档在1.3-1.5版本均未做改变,所以 ...

  3. Flink – window operator

      参考, http://wuchong.me/blog/2016/05/25/flink-internals-window-mechanism/ http://wuchong.me/blog/201 ...

  4. Flink Program Guide (6) -- 窗口 (DataStream API编程指导 -- For Java)

    窗口(Window) 本文翻译自文档Windows ----------------------------------- Flink使用窗口的概念,根据element的时间戳或者其他指标,将可能无限 ...

  5. Flink 的Window 操作(基于flink 1.3描述)

    Window是无限数据流处理的核心,Window将一个无限的stream拆分成有限大小的”buckets”桶,我们可以在这些桶上做计算操作.本文主要聚焦于在Flink中如何进行窗口操作,以及程序员如何 ...

  6. Flink学习(二)Flink中的时间

    摘自Apache Flink官网 最早的streaming 架构是storm的lambda架构 分为三个layer batch layer serving layer speed layer 一.在s ...

  7. Flink – WindowedStream

    在WindowedStream上可以执行,如reduce,aggregate,min,max等操作 关键是要理解windowOperator对KVState的运用,因为window是用它来存储wind ...

  8. Flink窗口介绍及应用

    Windows是Flink流计算的核心,本文将概括的介绍几种窗口的概念,重点只放在窗口的应用上. 本实验的数据采用自拟电影评分数据(userId, movieId, rating, timestamp ...

  9. flink watermark介绍

    转发请注明原创地址 http://www.cnblogs.com/dongxiao-yang/p/7610412.html 一 概念 watermark是flink为了处理eventTime窗口计算提 ...

随机推荐

  1. Socket网络编程--小小网盘程序(1)

    这个系列是准备讲基于Linux Socket进行文件传输.简单的文件传输就是客户端可以上传文件,可以从服务器端下载文件.就这么两个功能如果再加上身份验证,就成了FTP服务器了,如果对用户的操作再加上一 ...

  2. (转) mysql中left join,right join,inner join的区别

    转自:https://blog.csdn.net/qq_35975416/article/details/78842958 sql查询中有一个非常重要的环节就是表的关联查询,一般使用left join ...

  3. 学习MongoDB(Troubleshoot Replica Sets) 集群排除故障

    Test Connections Between all Members(集群中节点网络测试) 在进行Mongodb集群时,每个节点的网络都需要互动,假设有3个服务器节点. m1.example.ne ...

  4. T4 生成数据库实体类

    来源不详,整理如下: <#@ template language="C#" debug="True" hostspecific="True&qu ...

  5. 【转帖】39个让你受益的HTML5教程

    39个让你受益的HTML5教程                    闲话少说,本文作者为大家收集了网上学习HTML5的资源,期望它们可以帮助大家更好地学习HTML5. 好人啊! 不过,作者原来说的4 ...

  6. Python爬虫学习——布隆过滤器

    布隆过滤器的实现方法1:自己实现 参考 http://www.cnblogs.com/naive/p/5815433.html bllomFilter两个参数分别代表,布隆过滤器的大小和hash函数的 ...

  7. linux下Ftp服务安装

    安装vsftp 使用yum命令安装vsftp #yum install vsftpd -y 如果yum安装不成功,可以到 http://pkgs.org/centos-6/centos-x86_64/ ...

  8. python中利用redis构建任务队列(queue)

    Python中的使用标准queue模块就可以建立多进程使用的队列,但是使用redis和redis-queue(rq)模块使这一操作更加简单. Part 1. 比如首先我们使用队列来简单的储存数据:我们 ...

  9. OpenGL——二次曲面函数(球面-圆锥面-圆柱面)

    代码: #include<iostream> #include <math.h> #include<Windows.h> #include <GL/glut. ...

  10. 【SpringCloud微服务实战学习系列】客户端负载均衡Spring Cloud Ribbon

    Spring Cloud Ribbon是一个基于HTTP和TCP的客户端负载均衡工具,它基于Netflix Ribbon实现.通过Spring Cloud的封装,可以让我们轻松地将面向服务的RES模板 ...