Hi all Is keyed streams ( that consumes kafka topi...
# troubleshooting
є
Hi all Is keyed streams ( that consumes kafka topic) are processing "keyed" events sequentially ? i.e. that two events having the same Flink key are not processed in parallel ?
s
yes. keyed event processed sequentially. Because, same key event processed in same subtask.
є
And parallelism doesn't affect this?
s
parallelism affects to the num of subtask. If you set p=2, there are 2 subtaks. And all keyed event distributed into 2 subtask. same keyed event always goes in to same subtask.
є
May it be the case that the sink breaks ordering of keyed stream ?
s
never
є
how to fix this , i.e. make keyed stream to be processed in proper order by a sink ?
s
Oh sorry, ordering is not broken within the same keyed events.
same keyed events always processed in same subtask. in same subtask, events are sinked with proper order.
є
Ok, may it be that it's broken when using tests and
MiniClusterWithClientResource
?
s
never. if there are broken, could you check the keys for out of order events?
є
Just couple of details, that I am using broadcast stream, to "enrich" my keyed stream
So I assume that when I connect broadcast stream - it should be connected to already keyed stream if I want to maintain the order am i right?
So in my test I am setting parallelism to 2 and sending 4 events 3 with key A 1 with key B I am assuming that all events with key A are processed in the same subtask
s
it should be connected to already keyed stream if I want to maintain the order am i right? -> yes~
✅ 1
є
But the
process
method on
BroadcastConnectedStream
returns
SingleOutputStreamOperator
Copy code
public <KEY, OUT> SingleOutputStreamOperator<OUT> process(
            final KeyedBroadcastProcessFunction<KEY, IN1, IN2, OUT> function) {
...
}
Not
KeyedStream
So, should I
keyBy
the strem once again ?
s
KeyedBroadcastProcessFunction
broadcast keyed events to all subtasks with proper order. Could you explain more detail about what you want to do?
є
1. I have a stream
AAA
partitioned by custom key, aka KeyedStream, let's say it's
userId
2. Depending on some enrichment condition ( let's say user is from particular country) - I want to emit an additional event into stream
AAA
3. To implement "enrichment" logic - I am using broadcast stream
BBB
4. So after doing all this - I am noticing that the order of records is lost
s
as i understand your case, the order between keyed stream
AAA
and broadcast stream
BBB
not guaranteed. keyed stream only guaranteed the order of keyed events in stream
AAA
itself.
є
But what do you mean betwenn AAA and BBB They are different streams, BBB is for enrichment only and contains let's say
rules of enrichment
while AAA contains real events I assumed if AAA will be keyed when it is conencted to BBB - the order will be kept and later process steps will respect that order
s
you means that the order of events from stream
AAA
broken at the result? e.g. stream
AAA
emits events
a1
,
a2
,
a3
(Same key
a
) and results ares like
a1
,
a3
,
a2
?
є
So let's say AAA contains a1, a2, b2, a3 ( a and b are examples of keys) the "enricment function" ( via broadcast BBB ) - may inject a2_1, so the order for key a is expected a1, a2, a2_1, a3 ( i skipped keys
b
)
s
order is only guaranteed for events in AAA. if you broadcast event a2_1 via BBB, it does not guarantee. so results can be a1, a2, a3, a2_1 or a2_1, a1, a2, a3 or a1, a2_1, a2, a3 …
є
I am broadcasting via BBB the "enrichment rules"
then in implementation of
BroadcastProcessFunction
which process both AAA ( events) and BBB ( the rules ) i may want to emit / insert a new "event", i.e. insert into AAA to be processed further