We have a spark streaming (spark version 2.4.0 ) job which consumes one Kafka topic(4 partition) which includes business-changes as json with Id. These Kafka values also consist RecordTime field and other fields inside json object. This streaming job upserts a Kudu table according to the Id field.
After a while we noticed that, some updates are really not reflecting the latest state of the values for some id fields. We assume 4 different executor processing per partition and when one of them finishes earlier than other it updates target Kudu table. so if we have values like below:
(Id=1, val=A, RecordTime: 10:00:05 ) partition1
(Id=2, val=A, RecordTime: 10:00:04 ) partition1
(Id=1, val=B, RecordTime: 10:00:07 ) partition2
(Id=1, val=C, RecordTime: 10:00:06 ) partition3
(Id=2, val=D, RecordTime: 10:00:05 ) partition1
(Id=2, val=C, RecordTime: 10:00:06 ) partition4
(Id=1, val=E, RecordTime: 10:00:03 ) partition4
then Kudu table should be like this :
| Id | Value | RecordTime |
|---|---|---|
| 1 | B | 10:00:07 |
| 2 | C | 10:00:06 |
But, sometimes we saw the Kudu table like this :
| Id | Value | RecordTime |
|---|---|---|
| 1 | A | 10:00:05 |
| 2 | C | 10:00:06 |
trigger interval is 1-minute.
So, how can we achieve the ordered update of target Kudu table.
- Should we use single partition for ordering but if we do this pros/cons?
- For spark streaming how we can pick the latest record and values at per trigger-interval
- Upsert kudu table according to both id and RecordTime but how?
- Is there any other approach we can think about?
Hope i could explain my problem enough. Briefly, how we can achieve event ordering for per micro-batch interval at spark streaming?
Special thanks to anyone who can help me.