-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Non-Blocking Retries cannot combine with container transactions. #3072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non-Blocking Retries cannot combine with container transactions. #3072
Conversation
@ Wzy19930507 We need some more due diligence analysis on this issue. What you are saying is that retryable topics and nested transactions are not supported. Maybe the minimum we need to do is add a note in the doc saying that nested txns are not supported with retryable topics. I don't think we need to add the tests and the detailed docs you have in this PR. We can probably take your test as a POC for analyzing the issue (at a later time). Could you re-work the PR to only include the note in the docs? |
@sobychacko Thanks for your quick reply. I will re-work this PR. |
@@ -79,6 +79,9 @@ Instead, use a `KafkaTransactionManager` in the container to start the Kafka tra | |||
|
|||
See xref:tips.adoc#ex-jdbc-sync[Examples of Kafka Transactions with Other Transaction Managers] for an example application that chains JDBC and Kafka transactions. | |||
|
|||
IMPORTANT: Container transactions use xref:retrytopic.adoc[Non-Blocking Retries] will break transaction atomicity. | |||
When listener code threw exception, container transactions commit success and record sending to the retryable topic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that what expected from asynchronous, non-blocking retries?
To be able to send to the retry topic we indeed has to commit the current transaction.
I'm not fully sure how this non-blocking retires work internally, but apparently we don't start a new transaction, when we consume from the next retry topic.
It might work some way with a @Transactional
on the @KafkaListener
, but pay attention that @EnableTransactionManagement
has to be activated.
Either way: I would not say in the docs break
.
It sounds like a bug which is not supposed to be there.
It is just a feature which cannot be combined with transactions due to async nature.
Do you see things differently?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree with you, i'll re-test the @Transactional
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test result is non-blocking retries cannot be combined with transactions.
@Transactional
case as follows:
When PROPAGATION_REQUIRED
will infinite retry because of container transactions rollback. (un-expected).
When PROPAGATION_REQUIRED_NEW
- If listener code fail and container code success, listener code rollback, container code commit success. (expected)
- If listener code fail and container code fail, listener code rollback, container code rollback. (expected)
- If listener code success and container code fail, listener code commit success, container code rollback then infinite retry. (un-expected)
CurrentKafkaTransactionManager
only supportPROPAGATION_REQUIRES_NEW
andPROPAGATION_REQUIRED
, the above case tests only these two cases.
PROPAGATION_REQUIRED_NEW un-expected Report see https://github.com/Wzy19930507/spring-kafka/tree/report_pr_3072
Please see if there are any omissions, thanks.
I'll modify docs to Non-blocking retries cannot be combined with container transactions first and see if there's a way to implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Wzy19930507 We might want to use present tense here: When the listener code throws an exception, container transaction commit succeeds, and the record is sent to the retryable topic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the correction, fix it.
* docs `transactions.adoc` and `retrytopic.adoc`
d3816ac
to
379a798
Compare
@@ -79,6 +79,9 @@ Instead, use a `KafkaTransactionManager` in the container to start the Kafka tra | |||
|
|||
See xref:tips.adoc#ex-jdbc-sync[Examples of Kafka Transactions with Other Transaction Managers] for an example application that chains JDBC and Kafka transactions. | |||
|
|||
IMPORTANT: Container transactions use xref:retrytopic.adoc[Non-Blocking Retries] will break transaction atomicity. | |||
When listener code threw exception, container transactions commit success and record sending to the retryable topic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Wzy19930507 We might want to use present tense here: When the listener code throws an exception, container transaction commit succeeds, and the record is sent to the retryable topic.
Retry topic will break container txns atomicity
See #2934