水印总是Long.MIN_VALUE问题

项目场景:

flink1.7版本:事件时间处理时,水印总是Long.MIN_VALUE问题

问题描述

水位线怎么不触发?数据一直有序得进来,为什么没有窗口被fire掉

原因分析:

Flink source用到了FlinkKafkaConsumer010,没有指定KafkaPartitioner的话,会通过FixedPartitioner来给出默认的partitioner方法:
public int partition(T record, byte[] key, byte[] value, String targetTopic, int[] partitions) {
Preconditions.checkArgument(partitions != null && partitions.length > 0, “Partitions of the target topic is empty.”);
return partitions[this.parallelInstanceId % partitions.length];
}

追踪源码:
StatusWatermarkValve.java
private void findAndOutputNewMinWatermarkAcrossAlignedChannels() {
long newMinWatermark = Long.MAX_VALUE;
// determine new overall watermark by considering only watermark-aligned channels across all channels
for (InputChannelStatus channelStatus : channelStatuses) {
if (channelStatus.isWatermarkAligned) {
newMinWatermark = Math.min(channelStatus.watermark, newMinWatermark);
}
}
// we acknowledge and output the new overall watermark if it is larger than the last output watermark
if (newMinWatermark > lastOutputWatermark) {
lastOutputWatermark = newMinWatermark;
outputHandler.handleWatermark(new Watermark(lastOutputWatermark));
}
}
这里会将所有的channel status的水位线做个汇总:取最小的水位线。这个地方有的channel status下的水位线一直是最小的long值那个不正常的水位线,进而导致整体的水位线发送不出去

解决方案:

网上解决方案:修改assigntimestampandwatermarks的并行度
当assigntimestampandwatermarks的并行度修改后,事件会被shuffled across(洗牌),因此到了TimestampAndWatermarkAssigner不会有空的partition存在了。
并未解决我遇到的问题,根据FlinkKafkaConsumer 中的 per-partition watermarks 应该考虑空闲分区的讨论,解决方案在flink1.11被修复,增加了withIdleness


版权声明:本文为qq_40844739原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。