-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
spanner: add a statement-based way to run read-write transaction. #2545
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of general comments:
- Statement based transactions also need to be executed in a retry loop, only the user is now responsible for creating that loop one way or another. We should supply a clear example on how to use a statement based transaction, and emphasize the importance of a retry loop. Only checking the commit statement for an Aborted error is not enough, as any statement on the transaction can return with an Aborted error, and should cause the entire transaction to be retried.
- The
Commit
andRollback
methods should not be visible to users of the normalClient.ReadWriteTransaction
method. Those methods would otherwise cause confusion, as they should not be called when using the normalClient.ReadWriteTransaction
method.
@olavloite Please take another look. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for those changes. I'm very happy with the new ReadWriteTransactionStmtBased
struct. Would you mind having a look to see if it would be doable to move the BeginTransaction
call into that struct as well, and only have something like a NewReadWriteTransactionStmtBased
method in client.go
? That way, it won't stand out as much to new users who otherwise might start using it, not realizing that it is intended for libraries / ORMs etc.
@olavloite Two things I want to mention in my latest change:
Thanks for providing these nice suggestions. Please let me know if there are more issues. I am more than happy to fix them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of comments that now can be removed, but otherwise LGTM.
NewReadWriteStmtBasedTransaction.
4b1afc0
to
bf6d028
Compare
This adds the support to run the read-write transaction in the following way (no retries will be attempted and errors will be directly returned to the caller):
Fixes #1971