aio-libs / aio-libs/aiokafka

[QUESTION] Rebalance during transaction breaks exactly-once semantics?

未關閉
#844 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
question
主要語言
Python
星號
1.4k
分支
269
平均合併
1 天 1 小時
30 天內合併 PR
6

描述

I try to understand how to implement exactly-once guarantees with the [transactional consume-process-produce example](https://aiokafka.readthedocs.io/en/stable/examples/transaction_example.html).

I use the example almost verbatim. I've added a few print statements and added a sleep to simulate a long processing duration.

```python
...
print("Start sleep")
sleep(4)
print("Done sleep. Start commit")
await producer.send_offsets_to_transaction(
commit_offsets, GROUP_ID)
print("Commit done")
...
```

Besides this, I added a `subscribe()` call with my custom `ConsumerRebalanceListener` to see what's happening.

```python
class MyRebalanceListener(ConsumerRebalanceListener):
def on_partitions_assigned(self, partitions):
print("Assigned:", sorted([p.partition for p in partitions]))

def on_partitions_revoked(self, partitions):
print("Revoked:", sorted([p.partition for p in partitions]))
```

My understanding is that the `send_offsets_to_transaction()` should fail if it tries to commit to partitions whose assignment was revoked. To stress test this, I'm adding a worker when the current worker is *sleeping*, i.e after the output was send but before the offsets were committed. I see log output that indicates

```
(Processing of event)
Start sleep
Done sleep. Start commit
Heartbeat failed for group processing-group because it is rebalancing
Revoked: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Assigned: [0, 2, 4, 6, 8]
Commit done
```

So it seems that the commit succeeded after new partitions were assigned. In the target topic I see duplicated messages, one produced by each worker.

Where does this go wrong? Why doesn't it give me exactly-once guarantees? I can provide the runnable example if this makes it more clear. Shouldn't the transaction fail/be aborted if a rebalance happens in the background?

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。