Aidar Noname
05/05/2023, 2:23 PMsource -> stream1.connect(stream2).process(statefulFunction) -> sink
where statefulFunction has ValueState inside:
KeyedCoProcessFunction {
ValueState state;
processElement1() {
if (state.value() != null) {
// do something
}
}
processElement2() {
state.update()
}
}
There is no guarantee what event first lands in statefulFunction, if they emitted almost at the same time.
Our design presumes the events for processElement2 are passed first , landing in the state before processElement1 events starts flowing in.
I wrote a test to emit events one by one. They wait each other before being emitted.
But I still sleep(5) in controllable Source to give enough time for events to land on the right side.
Maybe someone know better way of doing that, thank you!
Let me know if I need to write the question in more details.Aidar Noname
05/05/2023, 4:55 PMKen Krugler
05/08/2023, 5:21 PMAidar Noname
05/17/2023, 12:40 PMKen Krugler
05/17/2023, 6:27 PMOur design presumes the events for processElement2 are passed first , landing in the state before processElement1 events starts flowing in.Normally that’s not how you’d design a Flink workflow, as there isn’t any guarantee that’s (by default) provided by Flink as to the ordering of events. I would probably code up the
KeyedCoProcessFunction to handle any order (using state to save incoming records that arrive at processElement1() before their corresponding record arrives at processElement2().