In the Spanner documentation for Commit()
, it says:
Commit might return an ABORTED error. This can occur at any time; commonly, the cause is conflicts with concurrent transactions. However, it can also happen for a variety of other reasons. If Commit returns ABORTED, the caller should re-attempt the transaction from the beginning, re-using the same session.
Two Questions:
If the transaction is aborted, do I have to rerun all the statements that were executed from the beginning of the transaction to retry? Or is simply retrying the commit()
again sufficient?
How do I reproduce an aborted commit on Spanner to verify my retry logic is correct?
I recommend using the official Cloud Spanner client libraries. They have various transaction runner abstractions that will react to errors appropriately, including retry logic.
If a transaction is aborted, the entire transaction should be retried.
Cloud Spanner provides no direct way to force a transaction abort. You can set up two transactions to do something like: