Flink - allowedLateness
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的更多相关文章
- Flink 灵魂两百问,这谁顶得住?
Flink 学习 https://github.com/zhisheng17/flink-learning 麻烦路过的各位亲给这个项目点个 star,太不易了,写了这么多,算是对我坚持下来的一种鼓励吧 ...
- flink Window的Timestamps/Watermarks和allowedLateness的区别
Watermartks是通过additional的时间戳来控制窗口激活的时间,allowedLateness来控制窗口的销毁时间. 注: 因为此特性包括官方文档在1.3-1.5版本均未做改变,所以 ...
- Flink – window operator
参考, http://wuchong.me/blog/2016/05/25/flink-internals-window-mechanism/ http://wuchong.me/blog/201 ...
- Flink Program Guide (6) -- 窗口 (DataStream API编程指导 -- For Java)
窗口(Window) 本文翻译自文档Windows ----------------------------------- Flink使用窗口的概念,根据element的时间戳或者其他指标,将可能无限 ...
- Flink 的Window 操作(基于flink 1.3描述)
Window是无限数据流处理的核心,Window将一个无限的stream拆分成有限大小的”buckets”桶,我们可以在这些桶上做计算操作.本文主要聚焦于在Flink中如何进行窗口操作,以及程序员如何 ...
- Flink学习(二)Flink中的时间
摘自Apache Flink官网 最早的streaming 架构是storm的lambda架构 分为三个layer batch layer serving layer speed layer 一.在s ...
- Flink – WindowedStream
在WindowedStream上可以执行,如reduce,aggregate,min,max等操作 关键是要理解windowOperator对KVState的运用,因为window是用它来存储wind ...
- Flink窗口介绍及应用
Windows是Flink流计算的核心,本文将概括的介绍几种窗口的概念,重点只放在窗口的应用上. 本实验的数据采用自拟电影评分数据(userId, movieId, rating, timestamp ...
- flink watermark介绍
转发请注明原创地址 http://www.cnblogs.com/dongxiao-yang/p/7610412.html 一 概念 watermark是flink为了处理eventTime窗口计算提 ...
随机推荐
- linux每日命令(7):rmdir命令
rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.)删除某目录时也必须具有对父目录的写权限. 一.命令 ...
- 登录tomcat服务器首页直接跳转到项目
原文:https://www.cnblogs.com/xwdreamer/p/3489996.html 需求: 客户觉得每次输入http://10.138.16.232:8080/abc/ 比较烦,他 ...
- System.Runtime.InteropServices.COMException 检索COM类工厂中CLSID{xxxxxxxxx}的组件时失败解决方法
iis7.5中设定应用程序池中<进程模型>中<标识>为localSystem 提示:System.Runtime.InteropServices.COMException: 命 ...
- Git 解决本地远端版本冲突
简单粗暴.... git push -u origin master -f
- html5游戏开发-简单tiger机
http://blog.csdn.net/lufy_legend/article/details/7021965
- [OpenCV] Samples 17: Floodfill
一种聚类方式,代码解析 #!/usr/bin/env python ''' Floodfill sample. Usage: floodfill.py [<image>] Click on ...
- SpringMVC -- @RequestMapping -- 随记
@RequestMapping RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径. RequestMappi ...
- python 截取 取出一部分的字符串
下面是split截取获得 >>> str = 'http://manualfile.s3.amazonaws.com/pdf/gti-chis-1-user-9fb-0-7a05a5 ...
- Elasticsearch数据迁移工具elasticdump工具
1. 工具安装 wget https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar.xz tar xf node-v8.11.2-linux ...
- POJ 3249 Test for Job
Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13457 Accepted: 3100 Descrip ...