-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(spanner): support commit options in mutation operations. #10668
Changes from 4 commits
9f513df
93c6da5
d732da2
c181829
8b3d121
30d79ea
c1472f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1498,7 +1498,11 @@ func TestIntegration_ReadWriteTransaction_StatementBased(t *testing.T) { | |
Insert("Accounts", []string{"AccountId", "Nickname", "Balance"}, []interface{}{int64(1), "Foo", int64(50)}), | ||
Insert("Accounts", []string{"AccountId", "Nickname", "Balance"}, []interface{}{int64(2), "Bar", int64(1)}), | ||
} | ||
if _, err := client.Apply(ctx, accounts, ApplyAtLeastOnce()); err != nil { | ||
duration, err := time.ParseDuration("100ms") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add mock server tests for both normal read/write transactions and writeAtLeastOnce transactions that verify that the maxCommitDelay that has been set is actually sent to Spanner in both cases? This integration test only shows that setting the option does not break anything, it is not able to determine whether the option was actually sent or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the tests |
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := client.Apply(ctx, accounts, ApplyAtLeastOnce(), ApplyCommitOptions(&CommitOptions{ReturnCommitStats: true, MaxCommitDelay: &duration})); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1859,6 +1859,9 @@ type writeOnlyTransaction struct { | |||||||
// current transaction from the allowed tracking change streams with DDL option | ||||||||
// allow_txn_exclusion=true. | ||||||||
excludeTxnFromChangeStreams bool | ||||||||
// maxCommitDelay is the maximum time that the commit will be delayed by the | ||||||||
// backend before it is acknowledged. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (The field here is not
Suggested change
|
||||||||
commitOptions *CommitOptions | ||||||||
} | ||||||||
|
||||||||
// applyAtLeastOnce commits a list of mutations to Cloud Spanner at least once, | ||||||||
|
@@ -1883,6 +1886,11 @@ func (t *writeOnlyTransaction) applyAtLeastOnce(ctx context.Context, ms ...*Muta | |||||||
return ts, err | ||||||||
} | ||||||||
|
||||||||
var maxCommitDelay *durationpb.Duration | ||||||||
if t.commitOptions != nil && t.commitOptions.MaxCommitDelay != nil { | ||||||||
maxCommitDelay = durationpb.New(*(t.commitOptions.MaxCommitDelay)) | ||||||||
} | ||||||||
|
||||||||
// Make a retryer for Aborted and certain Internal errors. | ||||||||
retryer := onCodes(DefaultRetryBackoff, codes.Aborted, codes.Internal) | ||||||||
// Apply the mutation and retry if the commit is aborted. | ||||||||
|
@@ -1910,6 +1918,7 @@ func (t *writeOnlyTransaction) applyAtLeastOnce(ctx context.Context, ms ...*Muta | |||||||
}, | ||||||||
Mutations: mPb, | ||||||||
RequestOptions: createRequestOptions(t.commitPriority, "", t.transactionTag), | ||||||||
MaxCommitDelay: maxCommitDelay, | ||||||||
}) | ||||||||
if err != nil && !isAbortedErr(err) { | ||||||||
// should not be the case with multiplexed sessions | ||||||||
|
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.
I don't quite understand why this is different depending on whether
ao.atLeastOnce
is true or not.