Skip to content

Commit 24c422e

Browse files
committed
Generate AbortTransaction operation
GODRIVER-1043 Change-Id: Ic7a1501c06d3cc6a3aa4b30c1e45e43a5f1dbfa2
1 parent 2b8bc9c commit 24c422e

File tree

5 files changed

+208
-6
lines changed

5 files changed

+208
-6
lines changed

mongo/session.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
2121
"go.mongodb.org/mongo-driver/x/mongo/driver/session"
2222
"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
23-
"go.mongodb.org/mongo-driver/x/mongo/driverlegacy"
2423
"go.mongodb.org/mongo-driver/x/network/command"
2524
)
2625

@@ -183,14 +182,21 @@ func (s *sessionImpl) AbortTransaction(ctx context.Context) error {
183182
return s.clientSession.AbortTransaction()
184183
}
185184

186-
cmd := command.AbortTransaction{
187-
Session: s.clientSession,
185+
var selector description.ServerSelectorFunc = func(t description.Topology, svrs []description.Server) ([]description.Server, error) {
186+
if s.clientSession.PinnedServer != nil {
187+
return s.clientSession.PinnedServer.SelectServer(t, svrs)
188+
}
189+
return description.WriteSelector().SelectServer(t, svrs)
188190
}
189191

190192
s.clientSession.Aborting = true
191-
_, err = driverlegacy.AbortTransaction(ctx, cmd, s.topo, description.WriteSelector())
193+
err = operation.NewAbortTransaction().Session(s.clientSession).ClusterClock(s.client.clock).Database("admin").
194+
Deployment(s.topo).WriteConcern(s.clientSession.CurrentWc).ServerSelector(selector).
195+
Retry(driver.RetryOncePerCommand).CommandMonitor(s.client.monitor).RecoveryToken(bsoncore.Document(s.clientSession.RecoveryToken)).Execute(ctx)
192196

197+
s.clientSession.Aborting = false
193198
_ = s.clientSession.AbortTransaction()
199+
194200
return replaceErrors(err)
195201
}
196202

x/mongo/driver/operation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
269269
op.Client.RetryWrite = false
270270
if *op.RetryMode > RetryNone {
271271
op.Client.RetryWrite = true
272-
if !op.Client.Committing {
272+
if !op.Client.Committing && !op.Client.Aborting {
273273
op.Client.IncrementTxnNumber()
274274
}
275275
}
@@ -460,7 +460,7 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
460460
func (op Operation) retryable(desc description.Server) RetryType {
461461
switch op.RetryType {
462462
case RetryWrite:
463-
if op.Client != nil && op.Client.Committing {
463+
if op.Client != nil && (op.Client.Committing || op.Client.Aborting) {
464464
return RetryWrite
465465
}
466466
if op.Deployment.SupportsRetry() &&

x/mongo/driver/operation/abort_transaction.go

Lines changed: 178 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version = 0
2+
name = "AbortTransaction"
3+
documentation = "AbortTransaction performs an abortTransaction operation."
4+
5+
[properties]
6+
enabled = ["write concern"]
7+
retryable = {mode = "once per command", type = "writes"}
8+
9+
[command]
10+
name = "abortTransaction"
11+
parameter = "database"
12+
13+
[request.recoveryToken]
14+
type = "document"
15+
documentation = """
16+
RecoveryToken sets the recovery token to use when committing or aborting a sharded transaction.\
17+
"""

x/mongo/driver/operation/operation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ package operation
1010
//go:generate operationgen drop_indexes.toml operation drop_indexes.go
1111
//go:generate operationgen drop_database.toml operation drop_database.go
1212
//go:generate operationgen commit_transaction.toml operation commit_transaction.go
13+
//go:generate operationgen abort_transaction.toml operation abort_transaction.go

0 commit comments

Comments
 (0)