-
Notifications
You must be signed in to change notification settings - Fork 135
Description
I'm always frustrated when facing with the following errors:
ABORTED: com.google.api.gax.rpc.AbortedException: io.grpc.StatusRuntimeException: ABORTED: Transaction was aborted. It was wounded by a higher priority transaction due to conflict on keys in range [[9a657b0e-93ea-41eb-b19b-53fe73a4eb78], [9a657b0e-93ea-41eb-b19b-53fe73a4eb78]), column created_timestamp in table user_entity.
retry_delay {
nanos: 171129581
}
And other similar.
It always fails on select statements generated by Hibernate ORM while concurrent execution (it's close to real situation, when we have many requests, for instance 100 per second.
So the message is not pretty clarified, but I guessed that it was discarded due to conflicts between transaction, because of all spanner databases have SERIALIZABLE isolation level only.
But the main issue is after aborting it's going to be retried by client mechanism, but it also checks hashes after each retry for two results sets. it does retry impossible due to concurrent modification exception. I want to leave a little change for this transaction to be retried with another strategy that will be chosen via URL properties, without comparing of hashes.
cloudspanner:/projects/test-project-123/instances/test-instance/databases/test-database?retryStrategy=FORCE_RETRY
cloudspanner:/projects/test-project-123/instances/test-instance/databases/test-database?retryStrategy=CHECK_SUM_RESULT - by default, can be omitted. The compatibility is saved.
And then in it will be something like that
13:33:07,796 FINE [com.google.cloud.spanner.connection.ForceRetryStrategy] (connection-executor-67) About to retry SQL transaction
[select userentity0_.ID as ID1_73_, userentity0_.CREATED_TIMESTAMP as CREATED_2_73_, userentity0_.EMAIL as EMAIL3_73_, userentity0_.EMAIL_CONSTRAINT as EMAIL_CO4_73_, userentity0_.EMAIL_VERIFIED as EMAIL_VE5_73_, userentity0_.ENABLED as ENABLED6_73_, userentity0_.FEDERATION_LINK as FEDERATI7_73_, userentity0_.FIRST_NAME as FIRST_NA8_73_, userentity0_.LAST_NAME as LAST_NAM9_73_, userentity0_.NOT_BEFORE as NOT_BEF10_73_, userentity0_.REALM_ID as REALM_I11_73_, userentity0_.SERVICE_ACCOUNT_CLIENT_LINK as SERVICE12_73_, userentity0_.USERNAME as USERNAM13_73_ from USER_ENTITY userentity0_ where userentity0_.EMAIL=@p1 and userentity0_.REALM_ID=@p2]
After getting a message: [ABORTED: com.google.api.gax.rpc.AbortedException: io.grpc.StatusRuntimeException: ABORTED: Transaction was aborted. It was wounded by a higher priority transaction due to conflict on keys in range [[9a657b0e-93ea-41eb-b19b-53fe73a4eb78], [9a657b0e-93ea-41eb-b19b-53fe73a4eb78]), column created_timestamp in table user_entity.
retry_delay {
nanos: 171129581
}
]
Maybe there is another solution, but I haven't found it yet.
Spanner is mutlicluster database. It does spanner more preferable than self-distributed and self-maintained database like MySQL or PostgreSQL. But retry is not allowed for some transactions, and and this complicates the task.
I know that, the option retryAbortsInternally, and I would handle this instead of PR, if I didn't use ORM.
ORM is more convenient in lot of applications than integrating via pure JDBC directly.
I made a PR, I knew that firstly, I was supposed to open issue, discuss and other things and I agreed that my suggestion can be discarded, but maybe this PR as a POC will be interesting.
Thanks for reading.