confluentinc / confluent-kafka-python

Confluent's Kafka Python Client
http://docs.confluent.io/current/clients/confluent-kafka-python
Other
3.73k stars 882 forks source link

Transactional Produce Increments Offset by 2 #1706

Closed hellwigt-eq closed 5 months ago

hellwigt-eq commented 5 months ago

Description

When I produce a message transactionally, the offset is incremented by 2. For example, when producing the first message to a fresh topic, the offset of that message is 0, but when producing the second message, the offset is 2, the third message's offset is 4, and so on. It appears the offset is being incremented twice on every commit. This behavior does not manifest when committing non-transactionally.

This is a problem because it critically breaks counting in KSQL, which we depend on for tracking flow through the system. For example, after producing those 3 messages, KSQL counts them as 6 messages.

Also, Provectus' Kafka UI can be used as an alternate method to quickly visually confirm what's described here.

How to reproduce

from confluent_kafka import Producer

p = Producer({"bootstrap.servers": "...", "transactional.id": "test"}) p.init_transactions() p.begin_transaction() p.produce(topic="dev.test-topic", value="test message") p.commit_transaction()

Running that multiple times will produce the described effect.

Checklist

Please provide the following information:

hellwigt-eq commented 5 months ago

Closing because it seems this is an inherently necessary artifact of transactional commits, and won't be fixed, as per other similar issues.