Skip to content
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

Add nested propagation support to R2dbcTransactionManager #30134

Closed
christophejan opened this issue Mar 17, 2023 · 0 comments
Closed

Add nested propagation support to R2dbcTransactionManager #30134

christophejan opened this issue Mar 17, 2023 · 0 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@christophejan
Copy link
Contributor

I think it could be useful to add R2dbcTransactionManager nested propagation transactions support.

The current r2dbc transaction manager implementation doesn't throw an exception when nested propagation is used "alone", but throw the following exception when a nested propagation is defined while a started transaction is already associate to the current process :

org.springframework.transaction.CannotCreateTransactionException: Could not open R2DBC Connection for transaction; nested exception is java.lang.IllegalStateException: Already value [org.springframework.r2dbc.connection.ConnectionHolder@7b0007f6] for key [ConnectionPool[PostgreSQL]] bound to context
	at org.springframework.r2dbc.connection.R2dbcTransactionManager.lambda$null$5(R2dbcTransactionManager.java:227) ~[spring-r2dbc-5.3.25.jar:5.3.25]

The documentation, contain the following statement :

Understanding PROPAGATION_NESTED
PROPAGATION_NESTED uses a single physical transaction with multiple savepoints that it can roll back to. Such partial rollbacks let an inner transaction scope trigger a rollback for its scope, with the outer transaction being able to continue the physical transaction despite some operations having been rolled back. This setting is typically mapped onto JDBC savepoints, so it works only with JDBC resource transactions. See Spring’s DataSourceTransactionManager.

If I'm right, r2dbc use a sigle connection per transaction and offer createSavepoint, rollbackTransactionToSavepoint and releaseSavepoint.

I think they could be used to implement nested propagation support on R2dbcTransactionManager.

I test a rather dirty workarround implementation and it seem to work pretty well.

I think nested propagation give flexibility ; for example, when a part of a process fail, they give the ability to restore the state of the current transaction to it's consistent state, just before the failing part, letting the caller decide to just retry, fail or switch to a fallback.

I would be great if this feature could be supported by build-in spring implementation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 17, 2023
@rstoyanchev rstoyanchev added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Mar 27, 2023
@jhoeller jhoeller added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 3, 2023
@jhoeller jhoeller modified the milestones: 6.1.x, 6.0.10 Jun 3, 2023
@jhoeller jhoeller self-assigned this Jun 4, 2023
mdeinum pushed a commit to mdeinum/spring-framework that referenced this issue Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants