Skip to content

Commit

Permalink
GODRIVER-2348 Deprecate maxCommitTimeMS
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Feb 1, 2024
1 parent a4c7211 commit 49427b3
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 102 deletions.
6 changes: 1 addition & 5 deletions internal/integration/json_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@ func createSessionOptions(t testing.TB, opts bson.Raw) *options.SessionOptions {
if txnOpts.WriteConcern != nil {
sessOpts.SetDefaultWriteConcern(txnOpts.WriteConcern)
}
if txnOpts.MaxCommitTime != nil {
sessOpts.SetDefaultMaxCommitTime(txnOpts.MaxCommitTime)
}
default:
t.Fatalf("unrecognized session option: %v", name)
}
Expand Down Expand Up @@ -374,8 +371,7 @@ func createTransactionOptions(t testing.TB, opts bson.Raw) *options.TransactionO
case "readConcern":
txnOpts.SetReadConcern(createReadConcern(opt))
case "maxCommitTimeMS":
t := time.Duration(opt.Int32()) * time.Millisecond
txnOpts.SetMaxCommitTime(&t)
t.Skip("GODRIVER-2348: maxCommitTimeMS is deprecated")
default:
t.Fatalf("unrecognized transaction option: %v", opt)
}
Expand Down
27 changes: 8 additions & 19 deletions internal/integration/unified/session_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package unified

import (
"fmt"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
Expand All @@ -24,11 +23,10 @@ var _ bson.Unmarshaler = (*transactionOptions)(nil)

func (to *transactionOptions) UnmarshalBSON(data []byte) error {
var temp struct {
RC *readConcern `bson:"readConcern"`
RP *ReadPreference `bson:"readPreference"`
WC *writeConcern `bson:"writeConcern"`
MaxCommitTimeMS *int64 `bson:"maxCommitTimeMS"`
Extra map[string]interface{} `bson:",inline"`
RC *readConcern `bson:"readConcern"`
RP *ReadPreference `bson:"readPreference"`
WC *writeConcern `bson:"writeConcern"`
Extra map[string]interface{} `bson:",inline"`
}
if err := bson.Unmarshal(data, &temp); err != nil {
return fmt.Errorf("error unmarshalling to temporary transactionOptions object: %v", err)
Expand All @@ -38,10 +36,6 @@ func (to *transactionOptions) UnmarshalBSON(data []byte) error {
}

to.TransactionOptions = options.Transaction()
if temp.MaxCommitTimeMS != nil {
mctms := time.Duration(*temp.MaxCommitTimeMS) * time.Millisecond
to.SetMaxCommitTime(&mctms)
}
if rc := temp.RC; rc != nil {
to.SetReadConcern(rc.toReadConcernOption())
}
Expand Down Expand Up @@ -72,11 +66,10 @@ var _ bson.Unmarshaler = (*sessionOptions)(nil)

func (so *sessionOptions) UnmarshalBSON(data []byte) error {
var temp struct {
Causal *bool `bson:"causalConsistency"`
MaxCommitTimeMS *int64 `bson:"maxCommitTimeMS"`
TxnOptions *transactionOptions `bson:"defaultTransactionOptions"`
Snapshot *bool `bson:"snapshot"`
Extra map[string]interface{} `bson:",inline"`
Causal *bool `bson:"causalConsistency"`
TxnOptions *transactionOptions `bson:"defaultTransactionOptions"`
Snapshot *bool `bson:"snapshot"`
Extra map[string]interface{} `bson:",inline"`
}
if err := bson.Unmarshal(data, &temp); err != nil {
return fmt.Errorf("error unmarshalling to temporary sessionOptions object: %v", err)
Expand All @@ -89,10 +82,6 @@ func (so *sessionOptions) UnmarshalBSON(data []byte) error {
if temp.Causal != nil {
so.SetCausalConsistency(*temp.Causal)
}
if temp.MaxCommitTimeMS != nil {
mctms := time.Duration(*temp.MaxCommitTimeMS) * time.Millisecond
so.SetDefaultMaxCommitTime(&mctms)
}
if temp.TxnOptions != nil {
if rc := temp.TxnOptions.ReadConcern; rc != nil {
so.SetDefaultReadConcern(rc)
Expand Down
6 changes: 0 additions & 6 deletions mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,6 @@ func (c *Client) StartSession(opts ...*options.SessionOptions) (Session, error)
if opt.DefaultWriteConcern != nil {
sopts.DefaultWriteConcern = opt.DefaultWriteConcern
}
if opt.DefaultMaxCommitTime != nil {
sopts.DefaultMaxCommitTime = opt.DefaultMaxCommitTime
}
if opt.Snapshot != nil {
sopts.Snapshot = opt.Snapshot
}
Expand All @@ -432,9 +429,6 @@ func (c *Client) StartSession(opts ...*options.SessionOptions) (Session, error)
if sopts.DefaultReadPreference != nil {
coreOpts.DefaultReadPreference = sopts.DefaultReadPreference
}
if sopts.DefaultMaxCommitTime != nil {
coreOpts.DefaultMaxCommitTime = sopts.DefaultMaxCommitTime
}
if sopts.Snapshot != nil {
coreOpts.Snapshot = sopts.Snapshot
}
Expand Down
21 changes: 0 additions & 21 deletions mongo/options/sessionoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
package options

import (
"time"

"go.mongodb.org/mongo-driver/mongo/readconcern"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
Expand Down Expand Up @@ -36,14 +34,6 @@ type SessionOptions struct {
// the write concern of the client used to start the session will be used.
DefaultWriteConcern *writeconcern.WriteConcern

// The default maximum amount of time that a CommitTransaction operation executed in the session can run on the
// server. The default value is nil, which means that that there is no time limit for execution.
//
// NOTE(benjirewis): DefaultMaxCommitTime will be deprecated in a future release. The more general Timeout option
// may be used in its place to control the amount of time that a single operation can run before returning an
// error. DefaultMaxCommitTime is ignored if Timeout is set on the client.
DefaultMaxCommitTime *time.Duration

// If true, all read operations performed with this session will be read from the same snapshot. This option cannot
// be set to true if CausalConsistency is set to true. Transactions and write operations are not allowed on
// snapshot sessions and will error. The default value is false.
Expand Down Expand Up @@ -79,17 +69,6 @@ func (s *SessionOptions) SetDefaultWriteConcern(wc *writeconcern.WriteConcern) *
return s
}

// SetDefaultMaxCommitTime sets the value for the DefaultMaxCommitTime field.
//
// NOTE(benjirewis): DefaultMaxCommitTime will be deprecated in a future release. The more
// general Timeout option may be used in its place to control the amount of time that a
// single operation can run before returning an error. DefaultMaxCommitTime is ignored if
// Timeout is set on the client.
func (s *SessionOptions) SetDefaultMaxCommitTime(mct *time.Duration) *SessionOptions {
s.DefaultMaxCommitTime = mct
return s
}

// SetSnapshot sets the value for the Snapshot field.
func (s *SessionOptions) SetSnapshot(b bool) *SessionOptions {
s.Snapshot = &b
Expand Down
24 changes: 0 additions & 24 deletions mongo/options/transactionoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
package options

import (
"time"

"go.mongodb.org/mongo-driver/mongo/readconcern"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
Expand All @@ -27,18 +25,6 @@ type TransactionOptions struct {
// The write concern for operations in the transaction. The default value is nil, which means that the default
// write concern of the session used to start the transaction will be used.
WriteConcern *writeconcern.WriteConcern

// The default maximum amount of time that a CommitTransaction operation executed in the session can run on the
// server. The default value is nil, meaning that there is no time limit for execution.

// The maximum amount of time that a CommitTransaction operation can executed in the transaction can run on the
// server. The default value is nil, which means that the default maximum commit time of the session used to
// start the transaction will be used.
//
// NOTE(benjirewis): MaxCommitTime will be deprecated in a future release. The more general Timeout option may
// be used in its place to control the amount of time that a single operation can run before returning an error.
// MaxCommitTime is ignored if Timeout is set on the client.
MaxCommitTime *time.Duration
}

// Transaction creates a new TransactionOptions instance.
Expand All @@ -63,13 +49,3 @@ func (t *TransactionOptions) SetWriteConcern(wc *writeconcern.WriteConcern) *Tra
t.WriteConcern = wc
return t
}

// SetMaxCommitTime sets the value for the MaxCommitTime field.
//
// NOTE(benjirewis): MaxCommitTime will be deprecated in a future release. The more general Timeout
// option may be used in its place to control the amount of time that a single operation can run before
// returning an error. MaxCommitTime is ignored if Timeout is set on the client.
func (t *TransactionOptions) SetMaxCommitTime(mct *time.Duration) *TransactionOptions {
t.MaxCommitTime = mct
return t
}
4 changes: 0 additions & 4 deletions mongo/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,11 @@ func (s *sessionImpl) StartTransaction(opts ...*options.TransactionOptions) erro
if opt.WriteConcern != nil {
topts.WriteConcern = opt.WriteConcern
}
if opt.MaxCommitTime != nil {
topts.MaxCommitTime = opt.MaxCommitTime
}
}
coreOpts := &session.TransactionOptions{
ReadConcern: topts.ReadConcern,
ReadPreference: topts.ReadPreference,
WriteConcern: topts.WriteConcern,
MaxCommitTime: topts.MaxCommitTime,
}

return s.clientSession.StartTransaction(coreOpts)
Expand Down
22 changes: 6 additions & 16 deletions x/mongo/driver/session/client_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,14 @@ type Client struct {

// options for the current transaction
// most recently set by transactionopt
CurrentRc *readconcern.ReadConcern
CurrentRp *readpref.ReadPref
CurrentWc *writeconcern.WriteConcern
CurrentMct *time.Duration
CurrentRc *readconcern.ReadConcern
CurrentRp *readpref.ReadPref
CurrentWc *writeconcern.WriteConcern

// default transaction options
transactionRc *readconcern.ReadConcern
transactionRp *readpref.ReadPref
transactionWc *writeconcern.WriteConcern
transactionMaxCommitTime *time.Duration
transactionRc *readconcern.ReadConcern
transactionRp *readpref.ReadPref
transactionWc *writeconcern.WriteConcern

pool *Pool
TransactionState TransactionState
Expand Down Expand Up @@ -202,9 +200,6 @@ func NewClientSession(pool *Pool, clientID uuid.UUID, opts ...*ClientOptions) (*
if mergedOpts.DefaultWriteConcern != nil {
c.transactionWc = mergedOpts.DefaultWriteConcern
}
if mergedOpts.DefaultMaxCommitTime != nil {
c.transactionMaxCommitTime = mergedOpts.DefaultMaxCommitTime
}
if mergedOpts.Snapshot != nil {
c.Snapshot = *mergedOpts.Snapshot
}
Expand Down Expand Up @@ -412,7 +407,6 @@ func (c *Client) StartTransaction(opts *TransactionOptions) error {
c.CurrentRc = opts.ReadConcern
c.CurrentRp = opts.ReadPreference
c.CurrentWc = opts.WriteConcern
c.CurrentMct = opts.MaxCommitTime
}

if c.CurrentRc == nil {
Expand All @@ -427,10 +421,6 @@ func (c *Client) StartTransaction(opts *TransactionOptions) error {
c.CurrentWc = c.transactionWc
}

if c.CurrentMct == nil {
c.CurrentMct = c.transactionMaxCommitTime
}

if !c.CurrentWc.Acknowledged() {
_ = c.clearTransactionOpts()
return ErrUnackWCUnsupported
Expand Down
7 changes: 0 additions & 7 deletions x/mongo/driver/session/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
package session

import (
"time"

"go.mongodb.org/mongo-driver/mongo/readconcern"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
Expand All @@ -20,7 +18,6 @@ type ClientOptions struct {
DefaultReadConcern *readconcern.ReadConcern
DefaultWriteConcern *writeconcern.WriteConcern
DefaultReadPreference *readpref.ReadPref
DefaultMaxCommitTime *time.Duration
Snapshot *bool
}

Expand All @@ -29,7 +26,6 @@ type TransactionOptions struct {
ReadConcern *readconcern.ReadConcern
WriteConcern *writeconcern.WriteConcern
ReadPreference *readpref.ReadPref
MaxCommitTime *time.Duration
}

func mergeClientOptions(opts ...*ClientOptions) *ClientOptions {
Expand All @@ -50,9 +46,6 @@ func mergeClientOptions(opts ...*ClientOptions) *ClientOptions {
if opt.DefaultWriteConcern != nil {
c.DefaultWriteConcern = opt.DefaultWriteConcern
}
if opt.DefaultMaxCommitTime != nil {
c.DefaultMaxCommitTime = opt.DefaultMaxCommitTime
}
if opt.Snapshot != nil {
c.Snapshot = opt.Snapshot
}
Expand Down

0 comments on commit 49427b3

Please sign in to comment.