Flink,使用“对象重用模式"的规则 [英] Flink, rule of using 'object reuse mode'

查看:49
本文介绍了Flink,使用“对象重用模式"的规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Doc说这个模式会导致bug,但是没有告诉我使用这个模式的规则,在什么情况下会导致bug?假设我有一份工作,

Doc says this mode can cause bugs, but it does not tell me the rule of using this mode, in what case it will cause bugs? Let's say I have a job,

  1. 来源:kafka(字节[]数据),
  2. flat-map:将 byte[] 解析为 Google Protobuf 对象 'foo',创建一个 Tuple2<>(foo.id, foo),并返回这个 tuple2
  3. keyby 和 process:对于每个 id,将第一个 foo 放入 ValueState,如果有多个具有相同 id 的对象,则更新 ValueState.10 秒后发出第一个 foo(updated).

在这种情况下,是否可以打开对象重用模式"?

In this case, is it OK to turn on 'object reuse mode'?

推荐答案

对于您所描述的管道,是的,可以安全地启用对象重用.

For the pipeline you have described, yes, object reuse can be safely enabled.

对象重用仅适用于在同一任务中的运算符实例之间转发数据的情况——因此在您的情况下,在源和平面图之间.keyBy 强制 ser/de 和 network shuffle,因此不能在 flatmap 和 process 函数之间使用对象重用.但是对象重用可能也适用于流程函数和接收器(我假设存在)之间.

Object reuse only applies to situations where data is forwarded between operator instances within the same task -- so in your case, between the source and flatmap. The keyBy forces ser/de and a network shuffle, so object reuse cannot be used between the flatmap and process function. But object reuse would probably also apply between the process function and sink (which I assume is present).

启用对象重用后,是否安全

With object reuse enabled, is it NOT safe to

  • 记住跨函数调用的输入对象引用或
  • 修改输入对象

如果你避开这两点,你就可以安全

If you avoid those two points, you may safely

  • 修改一个输出对象并再次发出它

顺便说一句,最好在 DeserializationSchema 或 KafkaDeserializationSchema 中实现反序列化,而不是在 flatmap 中,在这种情况下,对象重用与管道的那部分无关.

By the way, it would be preferable to implement your deserialization in a DeserializationSchema or KafkaDeserializationSchema, rather than in a flatmap, in which case object reuse would be irrelevant for that part of your pipeline.

这篇关于Flink,使用“对象重用模式"的规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆