Skip to content

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

Conversation

Wzy19930507
Copy link
Contributor

@Wzy19930507 Wzy19930507 commented Feb 26, 2024

Retry topic will break container txns atomicity

  1. container txns commit success.
  2. Message send to retryable topic retry again.
  • Add adoc to notice.

See #2934

@sobychacko
Copy link
Contributor

@ 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?

@Wzy19930507
Copy link
Contributor Author

@sobychacko Thanks for your quick reply. I will re-work this PR.
Sorry for my an ambiguous description, let me see if I can describe the problem more precisely.

@Wzy19930507 Wzy19930507 changed the title Listener tx nested kafka tx not support retry topic Container KafkaTransactionManager not support non-blocking retries. Feb 27, 2024
@Wzy19930507 Wzy19930507 changed the title Container KafkaTransactionManager not support non-blocking retries. Container txns use non-blocking retries break txns atomicity. Feb 27, 2024
@@ -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.
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@Wzy19930507 Wzy19930507 Feb 28, 2024

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

  1. If listener code fail and container code success, listener code rollback, container code commit success. (expected)
  2. If listener code fail and container code fail, listener code rollback, container code rollback. (expected)
  3. If listener code success and container code fail, listener code commit success, container code rollback then infinite retry. (un-expected)
    Current KafkaTransactionManager only support PROPAGATION_REQUIRES_NEW and PROPAGATION_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.

Copy link
Contributor

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.

Copy link
Contributor Author

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`
@Wzy19930507 Wzy19930507 changed the title Container txns use non-blocking retries break txns atomicity. Non-Blocking Retries cannot combine with container transactions. Feb 28, 2024
@Wzy19930507 Wzy19930507 force-pushed the listener_tx_nested_kafka_tx_not_support_retry_topic branch from d3816ac to 379a798 Compare February 28, 2024 05:13
@@ -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.
Copy link
Contributor

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.

@sobychacko sobychacko added this to the 3.2.0-M2 milestone Feb 28, 2024
@sobychacko sobychacko merged commit 3449f8c into spring-projects:main Feb 28, 2024
@Wzy19930507 Wzy19930507 deleted the listener_tx_nested_kafka_tx_not_support_retry_topic branch February 28, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants