-
Notifications
You must be signed in to change notification settings - Fork 935
GODRIVER-3889 Move commitTransaction and abortTransaction to the mongo package. #2473
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
Changes from 3 commits
8692c7d
e93c357
5d392f2
353dd8b
090ff3c
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 |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Copyright (C) MongoDB, Inc. 2019-present. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. You may obtain | ||
| // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| package mongo | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "go.mongodb.org/mongo-driver/v2/event" | ||
| "go.mongodb.org/mongo-driver/v2/internal/driverutil" | ||
| "go.mongodb.org/mongo-driver/v2/internal/logger" | ||
| "go.mongodb.org/mongo-driver/v2/mongo/writeconcern" | ||
| "go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore" | ||
| "go.mongodb.org/mongo-driver/v2/x/mongo/driver" | ||
| "go.mongodb.org/mongo-driver/v2/x/mongo/driver/description" | ||
| "go.mongodb.org/mongo-driver/v2/x/mongo/driver/session" | ||
| ) | ||
|
|
||
| // abortTransactionOp performs an abortTransaction operation. | ||
| type abortTransactionOp struct { | ||
| authenticator driver.Authenticator | ||
| recoveryToken bsoncore.Document | ||
| session *session.Client | ||
| clock *session.ClusterClock | ||
| monitor *event.CommandMonitor | ||
| database string | ||
| deployment driver.Deployment | ||
| selector description.ServerSelector | ||
| writeConcern *writeconcern.WriteConcern | ||
| retry *driver.RetryMode | ||
| maxAdaptiveRetries uint | ||
| enableOverloadRetargeting bool | ||
| serverAPI *driver.ServerAPIOptions | ||
| logger *logger.Logger | ||
| } | ||
|
|
||
| func (at *abortTransactionOp) processResponse(context.Context, bsoncore.Document, driver.ResponseInfo) error { | ||
| return nil | ||
| } | ||
|
|
||
| // Execute runs this operation and returns an error if the operation did not execute successfully. | ||
| func (at *abortTransactionOp) Execute(ctx context.Context) error { | ||
| if at.deployment == nil { | ||
| return errors.New("the abortTransaction operation must have a Deployment set before Execute can be called") | ||
| } | ||
|
|
||
| return driver.Operation{ | ||
| CommandFn: at.command, | ||
| ProcessResponseFn: at.processResponse, | ||
| RetryMode: at.retry, | ||
| Type: driver.Write, | ||
| Client: at.session, | ||
| Clock: at.clock, | ||
| CommandMonitor: at.monitor, | ||
| MaxAdaptiveRetries: at.maxAdaptiveRetries, | ||
| EnableOverloadRetargeting: at.enableOverloadRetargeting, | ||
| Database: at.database, | ||
|
matthewdale marked this conversation as resolved.
|
||
| Deployment: at.deployment, | ||
| Selector: at.selector, | ||
| WriteConcern: at.writeConcern, | ||
| ServerAPI: at.serverAPI, | ||
| Name: driverutil.AbortTransactionOp, | ||
| Authenticator: at.authenticator, | ||
| Logger: at.logger, | ||
| }.Execute(ctx) | ||
| } | ||
|
|
||
| func (at *abortTransactionOp) command(dst []byte, _ description.SelectedServer) ([]byte, error) { | ||
| dst = bsoncore.AppendInt32Element(dst, "abortTransaction", 1) | ||
| if at.recoveryToken != nil { | ||
| dst = bsoncore.AppendDocumentElement(dst, "recoveryToken", at.recoveryToken) | ||
| } | ||
| return dst, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Copyright (C) MongoDB, Inc. 2019-present. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. You may obtain | ||
| // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| package mongo | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "go.mongodb.org/mongo-driver/v2/event" | ||
| "go.mongodb.org/mongo-driver/v2/internal/driverutil" | ||
| "go.mongodb.org/mongo-driver/v2/internal/logger" | ||
| "go.mongodb.org/mongo-driver/v2/mongo/writeconcern" | ||
| "go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore" | ||
| "go.mongodb.org/mongo-driver/v2/x/mongo/driver" | ||
| "go.mongodb.org/mongo-driver/v2/x/mongo/driver/description" | ||
| "go.mongodb.org/mongo-driver/v2/x/mongo/driver/session" | ||
| ) | ||
|
|
||
| // commitTransactionOp attempts to commit a transaction. | ||
| type commitTransactionOp struct { | ||
| authenticator driver.Authenticator | ||
| recoveryToken bsoncore.Document | ||
| session *session.Client | ||
| clock *session.ClusterClock | ||
| monitor *event.CommandMonitor | ||
| database string | ||
| deployment driver.Deployment | ||
|
matthewdale marked this conversation as resolved.
|
||
| selector description.ServerSelector | ||
| writeConcern *writeconcern.WriteConcern | ||
| retry *driver.RetryMode | ||
| maxAdaptiveRetries uint | ||
| enableOverloadRetargeting bool | ||
| serverAPI *driver.ServerAPIOptions | ||
| logger *logger.Logger | ||
| } | ||
|
|
||
| func (ct *commitTransactionOp) processResponse(context.Context, bsoncore.Document, driver.ResponseInfo) error { | ||
| return nil | ||
| } | ||
|
|
||
| // Execute runs this operation and returns an error if the operation did not execute successfully. | ||
| func (ct *commitTransactionOp) Execute(ctx context.Context) error { | ||
|
Member
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. [nit] We should unexport method names. Additionally, is this more naturally a function? What are your thoughts? func executeCommitTxn(ctx context.Context, ct commitTransactionOp) { }
Contributor
Author
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. Unexporting I don't think either syntax is more obvious, so I'd bias toward keeping |
||
| if ct.deployment == nil { | ||
| return errors.New("the commitTransaction operation must have a Deployment set before Execute can be called") | ||
| } | ||
|
|
||
| return driver.Operation{ | ||
| CommandFn: ct.command, | ||
| ProcessResponseFn: ct.processResponse, | ||
| RetryMode: ct.retry, | ||
| Type: driver.Write, | ||
| Client: ct.session, | ||
| Clock: ct.clock, | ||
| CommandMonitor: ct.monitor, | ||
| MaxAdaptiveRetries: ct.maxAdaptiveRetries, | ||
| EnableOverloadRetargeting: ct.enableOverloadRetargeting, | ||
| Database: ct.database, | ||
|
matthewdale marked this conversation as resolved.
|
||
| Deployment: ct.deployment, | ||
| Selector: ct.selector, | ||
| WriteConcern: ct.writeConcern, | ||
| ServerAPI: ct.serverAPI, | ||
| Name: driverutil.CommitTransactionOp, | ||
| Authenticator: ct.authenticator, | ||
| Logger: ct.logger, | ||
| }.Execute(ctx) | ||
| } | ||
|
|
||
| func (ct *commitTransactionOp) command(dst []byte, _ description.SelectedServer) ([]byte, error) { | ||
| dst = bsoncore.AppendInt32Element(dst, "commitTransaction", 1) | ||
| if ct.recoveryToken != nil { | ||
| dst = bsoncore.AppendDocumentElement(dst, "recoveryToken", ct.recoveryToken) | ||
| } | ||
| return dst, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.