-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: support getting the commit timestamp of a transaction or statement #52
Conversation
Cloud Spanner returns the commit timestamp of a read/write transaction as a part of the commit response. This PR adds support for getting that timestamp in two ways: 1. Through a CommitTimestamp() method on the SpannerConn interface. 2. Through the SHOW VARIABLE COMMIT_TIMESTAMP client side statement.
} { | ||
c.commitTs = test.wantValue | ||
|
||
it, err := s.ShowCommitTimestamp(ctx, c, "", nil) |
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.
this commit timestamp is from the previous successful txn, right?
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.
Correct
}, | ||
retryAborts: c.retryAborts, | ||
} | ||
c.commitTs = nil |
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.
why do we clear commitTs here?
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.
The commit timestamp is cleared when a new transaction is started to avoid any confusion regarding whether the commit timestamp is related to the current transaction or the one before. So if you try to get the commit timestamp while in a transaction that has not yet committed, you will get an error or NULL instead of the commit timestamp of the previous transaction.
This is also consistent with the behavior of the JDBC driver.
if err != nil { | ||
t.Fatalf("failed to get a connection: %v", err) | ||
} | ||
if _, err := conn.ExecContext(ctx, testutil.UpdateBarSetFoo); err != nil { |
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.
this will do an autocommit, right?
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.
Yes, that is correct. If you execute an update (or any other statement) on a connection that has no active transaction, the statement will be executed in autocommit mode. That means that:
- Update statements will automatically begin an implicit read/write transaction and commit that transaction directly after the update statement if the update was successful.
- Queries will automatically use a single-use read-only transaction, as that is the most efficient way of executing a single query.
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.
LGTM.
Cloud Spanner returns the commit timestamp of a read/write transaction as a part of the commit response.
This PR adds support for getting that timestamp in two ways: