-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: (Hibernate) Rollback to savepoint fails during transaction retry. #27274
Comments
Hi @Vladimir-Shulga , we notice that your error message mentions cockroach_restart. This is only possible if you are running CockroachDB-specific changes in your application code: a native Hibernate app would never produce this error. We deduce your app code using Hibernate has already been equipped to handle these errors in CockroachDB. Hence:
|
Hi @awoods187, "cockroach_restart" is name of savepoint that was created in my Java code. if statements in scope of transaction executed successfully I do If specific exception with SqlState 40001 happens I do Exception I posted happens during rolling back transaction to manually created savepoint. I haven't applied any changes to CocroachDB sources. |
@Vladimir-Shulga you should create a specific transaction object ( This needs to be done using the CockroachDBTransactionCoordinator provided in https://github.com/cockroachdb/hibernate-savepoint-fix. If you use the |
(Arguably there is a pitfall in our docs here: we should be much more explicit in docs and the README of https://github.com/cockroachdb/hibernate-savepoint-fix that the code must use a single txn object and not the session directly.) |
@knz
I do have separate transaction object and do commit/rollback on it. How can I run queries like "ROLLBACK TO SAVEPOINT cockroach_restart" on transaction but not on session? `public class Txn {
} |
Thanks for sharing this code with us. I'd need to ask for some colleague with more Java experience than I to look into it. |
@Vladimir-Shulga I might take a guess as to what the problem is: at the very beginning you say "concurrent inserts". Are you trying to use multiple Java threads using the same |
@knz |
So as of right now I think the best approach for this issue is twofold.
|
any status updates, timeline? |
@lfmunoz what is the problem that you are running into? More examples will help us prioritize. |
I got rollback to savepoints working with Spring Boot / JPA / Hibernate so this isn't a problem for me anymore. Having problems with liquid-base but that is a separate issue. Special thanks to https://github.com/cockroachdb/hibernate-savepoint-fix and other code I found. See below for my implementation with Spring Annotation. If anything I would appreciate feedback from cockroachdb people to make sure I am doing everything correctly in the code below.
|
@lfmunoz thanks for sharing, this is really useful. |
I'm closing this issue due to age. |
I'm working with single node cockroachdb configuration. Using Hibernate as on ORM. Implemented custom transaction manager according to https://github.com/cockroachdb/hibernate-savepoint-fix.
Cockroachdb fails to process concurrent inserts to multiple tables in one transaction with exception:
2018-07-04 08:44:03,0395 191f69c78b1b80c21ed7bb001da49719 ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: restart transaction: HandledRetryableTxnError: TransactionAbortedError: txn aborted "sql txn" id=8e677091 key=/Table/112/1/362490898983419905/"FILTER_SET"/0 rw=true pri=0.16579172 iso=SERIALIZABLE stat=PENDING epo=0 ts=1530693821.068963662,1 orig=1530693815.911493801,0 max=1530693815.911493801,0 wto=false rop=false seq=7923
Transaction is aborted after this error and can't be rolled back to savepoint.
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement Caused by: org.postgresql.util.PSQLException: ERROR: Expected "ROLLBACK TO SAVEPOINT COCKROACH_RESTART": current transaction is aborted, commands ignored until end of transaction block at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168) at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:135) 37 lines skipped for [org.hibernate]
Same inserts are successful when executed in one thread.
I'm attaching simplified version of my schema. Data is inserted into the frame and connected tables.
cockroach_schema.txt
Jira issue: CRDB-4961
The text was updated successfully, but these errors were encountered: