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窗口计算提 ...
随机推荐
- 物联网架构成长之路(5)-EMQ插件配置
1. 前言 上一小结说了插件的创建,这一节主要怎么编写代码,以及具体流程之类的.2. 增加一句Hello World 修改 ./deps/emq_plugin_wunaozai/src/emq_plu ...
- 在webpack中使用postcss-px2rem的
经过一番折腾重要搞定了. 首先需要安装postcss-plugin-px2rem. npm install --save-dev postcss-plugin-px2rem 我的webpack工程中没 ...
- 【iCore4 双核心板_ARM】例程三:EXTI中断输入实验——读取ARM按键状态
实验原理: 按键的一端与STM32的GPIO(PB9)相连,且PB9外接一个1k大小的限流上接电阻. 初始化时把PB9设置成输入模式,当按键弹起时,PB9由于上拉电阻的作用呈高电平(3.3V): 当按 ...
- Envoy 代替nginx https://www.jianshu.com/p/0a1f67b42fdb
官方文档: https://www.envoyproxy.io/docs1.6.0版官方文档: https://www.envoyproxy.io/docs/envoy/v1.6.0/ 一. 编译和安 ...
- JavaScript高级用法二之内置对象
综述 本篇的主要内容来自慕课网,内置对象,主要内容如下 1 什么是对象 2 Date 日期对象 3 返回/设置年份方法 4 返回星期方法 5 返回/设置时间方法 6 String 字符串对象 7 返回 ...
- Async Performance: Understanding the Costs of Async and Await
Stephen Toub Download the Code Sample Asynchronous programming has long been the realm of only the m ...
- Go指南练习_循环与函数
源地址 https://tour.go-zh.org/flowcontrol/8 一.练习题描述 为了练习函数与循环,我们来实现一个平方根函数:用牛顿法实现平方根函数. 计算机通常使用循环来计算 x ...
- php memcached 扩展
php_memcache.dll下载地址:http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/ 查看php线程:phpinfo ...
- [Converge] Training Neural Networks
CS231n Winter 2016: Lecture 5: Neural Networks Part 2 CS231n Winter 2016: Lecture 6: Neural Networks ...
- Gradle 设置全局代理
#systemProp.socks.proxyHost=127.0.0.1 #systemProp.socks.proxyPort=7077 #systemProp.https.proxyHost=1 ...