Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flink 来自KeyedCoProcessFunction的processElement1和processElement2是否为原子w.r.t.状态?或者他们可以同时修改共享状态吗?_Apache Flink_Flink Streaming - Fatal编程技术网

Apache flink 来自KeyedCoProcessFunction的processElement1和processElement2是否为原子w.r.t.状态?或者他们可以同时修改共享状态吗?

Apache flink 来自KeyedCoProcessFunction的processElement1和processElement2是否为原子w.r.t.状态?或者他们可以同时修改共享状态吗?,apache-flink,flink-streaming,Apache Flink,Flink Streaming,我有两个流,一个数据流只包含一个设置ValueState passing=true/false的标志,另一个控制流添加一个要通知MapState的用户。将更改从false传递到true时,将向MapState中尚未收到通知的用户发出通知 下面是状态如何转换 下面是处理此逻辑的KeyedCoProcessFunction 类TestKeyedCoProcessFunction扩展KeyedCoProcessFunction[字符串,字符串,字符串,字符串]{ @通知临时私有变量:MapState[

我有两个流,一个数据流只包含一个设置ValueState passing=true/false的标志,另一个控制流添加一个要通知MapState的用户。将更改从false传递到true时,将向MapState中尚未收到通知的用户发出通知

下面是状态如何转换

下面是处理此逻辑的KeyedCoProcessFunction

类TestKeyedCoProcessFunction扩展KeyedCoProcessFunction[字符串,字符串,字符串,字符串]{ @通知临时私有变量:MapState[String,Boolean]=\u0//user:已通知 @临时私有var传递:ValueState[java.lang.Boolean]=\u0//更新为传递时发出通知=true 覆盖def OPEN参数:配置:单元={ val notifiedDescriptor=new MapStateDescriptornotified,Types.STRING,Types.BOOLEAN notified=getRuntimeContext.getMapStatenotifiedDescriptor val passingDescriptor=新值StateDescriptorPassing,Types.BOOLEAN 传递=getRuntimeContext.getStatepassingDescriptor 如果传递.value==null{ passing.updatevalse } } def addUseruser:字符串:布尔={ 如有通知,请联系我们{ 错误的 }否则{ notified.putuser,false 符合事实的 } } def setPassingnewPassing:字符串:布尔={ 如果传递.value{ 如果newPassing==true{ 错误的 }否则{ passing.updatevalse 符合事实的 } }否则{ 如果newPassing==false{ 错误的 }否则{ passing.updaterue 符合事实的 } } } def notifyNotifiedUserCollector:收集器[字符串]:单位={ val keys=notified.keys.iterator 而keys.hasNext{ val user=keys.next val userNotified=notified.getuser 如果!已通知用户{ collector.collectHey+user+passing=true notified.putuser,true } } } def setNotifiedFalseAll:单位={ val keys=notified.keys.iterator 而keys.hasNext{ val user=keys.next val userNotified=notified.getuser 如果通知用户{ notified.putuser,false } } } 覆盖def processElement1user:字符串, 上下文:KeyedCoProcessFunction[String,String,String,String]上下文, 收集器:收集器[字符串]:单位={ addUseruser 如果传递.value{ NotifyNotifiedUserCollector } } 重写def processElement2newPassing:String, 上下文:KeyedCoProcessFunction[String,String,String,String]上下文, 收集器:收集器[字符串]:单位={ val MODIFED=setPassingnewPassing 如果传递.value{ NotifyNotifiedUserCollector }否则{ 如果修改{ SetdFalseall } } } } 例如,在同时执行processElement1和processElement2的Flink中是否可能出现争用条件

t+1 processElement2("true")
t+2 processElement2: setPassing("true")
t+3 processElement2: notifyNotNotifiedUsers() // starts iteration on MapState
t+4 processElement1("new_user")
t+5 processElement1: addUser(user) // adds user to MapState
t+6 processElement1: notifyNotNotifiedUsers() // starts another parallel iteration on MapState resulting in maybe missed/duplicate notification

在KeyedCoProcessFunction的任何给定实例中,或者在Flink的任何用户函数界面中,都不可能存在竞争条件。processElement1和processElement2不能同时执行。onTimer也是安全的。

在KeyedCoProcessFunction的任何给定实例中,或者在Flink的任何用户函数界面中,都不可能存在竞争条件。processElement1和processElement2不能同时执行。onTimer也很安全。

好吧,那就不用担心了,谢谢David,你对我学习Flink的过程真的很有帮助。好吧,那就不用担心了,谢谢David,你对我学习Flink的过程真的很有帮助