Skip to content

Commit 3a1ce86

Browse files
committed
feat: add mutations support
1 parent 6667833 commit 3a1ce86

File tree

16 files changed

+6354
-15
lines changed

16 files changed

+6354
-15
lines changed

aborted_transactions_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,51 @@ func TestCommitAborted(t *testing.T) {
6060
}
6161
}
6262

63+
func TestCommitWithMutationsAborted(t *testing.T) {
64+
t.Parallel()
65+
66+
db, server, teardown := setupTestDBConnectionWithParams(t, "minSessions=1;maxSessions=1")
67+
defer teardown()
68+
ctx := context.Background()
69+
70+
conn, err := db.Conn(ctx)
71+
if err != nil {
72+
t.Fatalf("failed to open connection: %v", err)
73+
}
74+
defer func() { _ = conn.Close() }()
75+
76+
tx, err := conn.BeginTx(ctx, &sql.TxOptions{})
77+
if err != nil {
78+
t.Fatalf("begin failed: %v", err)
79+
}
80+
if err := conn.Raw(func(driverConn interface{}) error {
81+
spannerConn, _ := driverConn.(SpannerConn)
82+
mutation := spanner.Insert("foo", []string{}, []interface{}{})
83+
return spannerConn.BufferWrite([]*spanner.Mutation{mutation})
84+
}); err != nil {
85+
t.Fatalf("failed to buffer mutations: %v", err)
86+
}
87+
// Abort the transaction on the first commit attempt.
88+
server.TestSpanner.PutExecutionTime(testutil.MethodCommitTransaction, testutil.SimulatedExecutionTime{
89+
Errors: []error{status.Error(codes.Aborted, "Aborted")},
90+
})
91+
err = tx.Commit()
92+
if err != nil {
93+
t.Fatalf("commit failed: %v", err)
94+
}
95+
reqs := drainRequestsFromServer(server.TestSpanner)
96+
commitReqs := requestsOfType(reqs, reflect.TypeOf(&sppb.CommitRequest{}))
97+
if g, w := len(commitReqs), 2; g != w {
98+
t.Fatalf("commit request count mismatch\nGot: %v\nWant: %v", g, w)
99+
}
100+
for _, req := range commitReqs {
101+
commitReq := req.(*sppb.CommitRequest)
102+
if g, w := len(commitReq.Mutations), 1; g != w {
103+
t.Fatalf("mutation count mismatch\n Got: %v\nWant: %v", g, w)
104+
}
105+
}
106+
}
107+
63108
func TestCommitAbortedWithInternalRetriesDisabled(t *testing.T) {
64109
t.Parallel()
65110

benchmarks/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
cloud.google.com/go/iam v1.5.2 // indirect
2525
cloud.google.com/go/longrunning v0.6.7 // indirect
2626
cloud.google.com/go/monitoring v1.24.2 // indirect
27-
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 // indirect
27+
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.3 // indirect
2828
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
2929
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3030
github.com/cncf/xds/go v0.0.0-20250326154945-ae57f3c0d45f // indirect
@@ -44,7 +44,7 @@ require (
4444
github.com/zeebo/errs v1.4.0 // indirect
4545
go.opencensus.io v0.24.0 // indirect
4646
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
47-
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 // indirect
47+
go.opentelemetry.io/contrib/detectors/gcp v1.36.0 // indirect
4848
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
4949
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
5050
go.opentelemetry.io/otel v1.36.0 // indirect
@@ -60,6 +60,6 @@ require (
6060
golang.org/x/text v0.26.0 // indirect
6161
golang.org/x/time v0.12.0 // indirect
6262
google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 // indirect
63-
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect
63+
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822 // indirect
6464
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
6565
)

benchmarks/go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
617617
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
618618
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 h1:DBjmt6/otSdULyJdVg2BlG0qGZO5tKL4VzOs0jpvw5Q=
619619
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2/go.mod h1:dppbR7CwXD4pgtV9t3wD1812RaLDcBjtblcDF5f1vI0=
620+
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.3/go.mod h1:dppbR7CwXD4pgtV9t3wD1812RaLDcBjtblcDF5f1vI0=
620621
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 h1:ErKg/3iS1AKcTkf3yixlZ54f9U1rljCkQyEXWUnIUxc=
621622
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0/go.mod h1:yAZHSGnqScoU556rBOVkwLze6WP5N+U11RHuWaGVxwY=
622623
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
@@ -925,6 +926,7 @@ go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJyS
925926
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
926927
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 h1:bGvFt68+KTiAKFlacHW6AhA56GF2rS0bdD3aJYEnmzA=
927928
go.opentelemetry.io/contrib/detectors/gcp v1.35.0/go.mod h1:qGWP8/+ILwMRIUf9uIVLloR1uo5ZYAslM4O6OqUi1DA=
929+
go.opentelemetry.io/contrib/detectors/gcp v1.36.0/go.mod h1:IbBN8uAIIx734PTonTPxAxnjc2pQTxWNkwfstZ+6H2k=
928930
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 h1:q4XOmH/0opmeuJtPsbFNivyl7bCt7yRBbeEm2sC/XtQ=
929931
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0/go.mod h1:snMWehoOh2wsEwnvvwtDyFCxVeDAODenXHtn5vzrKjo=
930932
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus=
@@ -1510,6 +1512,7 @@ google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 h1:1tXaIXCracvtsRx
15101512
google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2/go.mod h1:49MsLSx0oWMOZqcpB3uL8ZOkAh1+TndpJ8ONoCBWiZk=
15111513
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 h1:vPV0tzlsK6EzEDHNNH5sa7Hs9bd7iXR7B1tSiPepkV0=
15121514
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2/go.mod h1:pKLAc5OolXC3ViWGI62vvC0n10CpwAtRcTNCFwTKBEw=
1515+
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822/go.mod h1:h3c4v36UTKzUiuaOKQ6gr3S+0hovBtUrXzTG/i3+XEc=
15131516
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 h1:fc6jSaCT0vBduLYZHYrBBNY4dsWuvgyff9noRNDdBeE=
15141517
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
15151518
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=

examples/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
cloud.google.com/go/monitoring v1.24.2 // indirect
2727
dario.cat/mergo v1.0.0 // indirect
2828
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
29-
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 // indirect
29+
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.3 // indirect
3030
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
3131
github.com/Microsoft/go-winio v0.6.2 // indirect
3232
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
@@ -81,7 +81,7 @@ require (
8181
github.com/zeebo/errs v1.4.0 // indirect
8282
go.opencensus.io v0.24.0 // indirect
8383
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
84-
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 // indirect
84+
go.opentelemetry.io/contrib/detectors/gcp v1.36.0 // indirect
8585
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
8686
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
8787
go.opentelemetry.io/otel v1.36.0 // indirect
@@ -98,7 +98,7 @@ require (
9898
golang.org/x/text v0.26.0 // indirect
9999
golang.org/x/time v0.12.0 // indirect
100100
google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 // indirect
101-
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect
101+
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822 // indirect
102102
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
103103
google.golang.org/grpc v1.73.0 // indirect
104104
google.golang.org/protobuf v1.36.6 // indirect

examples/go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
623623
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
624624
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 h1:DBjmt6/otSdULyJdVg2BlG0qGZO5tKL4VzOs0jpvw5Q=
625625
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2/go.mod h1:dppbR7CwXD4pgtV9t3wD1812RaLDcBjtblcDF5f1vI0=
626+
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.3/go.mod h1:dppbR7CwXD4pgtV9t3wD1812RaLDcBjtblcDF5f1vI0=
626627
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 h1:ErKg/3iS1AKcTkf3yixlZ54f9U1rljCkQyEXWUnIUxc=
627628
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0/go.mod h1:yAZHSGnqScoU556rBOVkwLze6WP5N+U11RHuWaGVxwY=
628629
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
@@ -1015,6 +1016,7 @@ go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJyS
10151016
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
10161017
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 h1:bGvFt68+KTiAKFlacHW6AhA56GF2rS0bdD3aJYEnmzA=
10171018
go.opentelemetry.io/contrib/detectors/gcp v1.35.0/go.mod h1:qGWP8/+ILwMRIUf9uIVLloR1uo5ZYAslM4O6OqUi1DA=
1019+
go.opentelemetry.io/contrib/detectors/gcp v1.36.0/go.mod h1:IbBN8uAIIx734PTonTPxAxnjc2pQTxWNkwfstZ+6H2k=
10181020
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 h1:q4XOmH/0opmeuJtPsbFNivyl7bCt7yRBbeEm2sC/XtQ=
10191021
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0/go.mod h1:snMWehoOh2wsEwnvvwtDyFCxVeDAODenXHtn5vzrKjo=
10201022
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus=
@@ -1616,6 +1618,7 @@ google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 h1:1tXaIXCracvtsRx
16161618
google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2/go.mod h1:49MsLSx0oWMOZqcpB3uL8ZOkAh1+TndpJ8ONoCBWiZk=
16171619
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 h1:vPV0tzlsK6EzEDHNNH5sa7Hs9bd7iXR7B1tSiPepkV0=
16181620
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2/go.mod h1:pKLAc5OolXC3ViWGI62vvC0n10CpwAtRcTNCFwTKBEw=
1621+
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822/go.mod h1:h3c4v36UTKzUiuaOKQ6gr3S+0hovBtUrXzTG/i3+XEc=
16191622
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 h1:fc6jSaCT0vBduLYZHYrBBNY4dsWuvgyff9noRNDdBeE=
16201623
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
16211624
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=

go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ go 1.24
44

55
toolchain go1.24.4
66

7+
replace cloud.google.com/go/spanner => /Users/loite/GolandProjects/google-cloud-go/spanner
8+
79
require (
810
cloud.google.com/go v0.121.2
911
cloud.google.com/go/longrunning v0.6.7
@@ -26,7 +28,7 @@ require (
2628
cloud.google.com/go/compute/metadata v0.7.0 // indirect
2729
cloud.google.com/go/iam v1.5.2 // indirect
2830
cloud.google.com/go/monitoring v1.24.2 // indirect
29-
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 // indirect
31+
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.3 // indirect
3032
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
3133
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3234
github.com/cncf/xds/go v0.0.0-20250326154945-ae57f3c0d45f // indirect
@@ -44,7 +46,7 @@ require (
4446
github.com/zeebo/errs v1.4.0 // indirect
4547
go.opencensus.io v0.24.0 // indirect
4648
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
47-
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 // indirect
49+
go.opentelemetry.io/contrib/detectors/gcp v1.36.0 // indirect
4850
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
4951
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
5052
go.opentelemetry.io/otel v1.36.0 // indirect
@@ -60,5 +62,5 @@ require (
6062
golang.org/x/text v0.26.0 // indirect
6163
golang.org/x/time v0.12.0 // indirect
6264
google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 // indirect
63-
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect
65+
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822 // indirect
6466
)

0 commit comments

Comments
 (0)