How should the transaction requires abort case be handled for the Transactional Producer API?
According to the documentation, if while trying to commit a transaction, an error occurs where a transaction should be aborted (possibly due to rebalancing), the steps to be taken should be:
- producer --> abort transaction
- producer --> begin transaction
- rewind consumer offsets
Aborting and beginning a new transaction are straight forward. However, how and how far should the consumer offset be rewound? What would this look like for the Python client? In the case of a single message being consumed at a time, should only that message simply be reprocessed?
As a reference, the code example that I'm referring to is:
while True:
try:
producer.commit_transaction(10.0)
break
except KafkaException as e:
if e.args[0].retriable():
# retriable error, try again
continue
# **************Relevant to the question**************
elif e.args[0].txn_requires_abort():
# abort current transaction, begin a new transaction,
# and rewind the consumer to start over.
producer.abort_transaction()
producer.begin_transaction()
rewind_consumer_offsets...()
# **************
else:
# treat all other errors as fatal
raise