Skip to content

Commit

Permalink
GODRIVER-2348 Deprecate maxTimeMS
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Feb 1, 2024
1 parent c32af34 commit 54abbc5
Show file tree
Hide file tree
Showing 35 changed files with 107 additions and 535 deletions.
6 changes: 2 additions & 4 deletions internal/integration/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ func TestCollection(t *testing.T) {
count int64
}{
{"no options", nil, 5},
{"options", options.EstimatedDocumentCount().SetMaxTime(1 * time.Second), 5},
{"options", options.EstimatedDocumentCount().SetComment(1), 5},
}
for _, tc := range testCases {
mt.Run(tc.name, func(mt *mtest.T) {
Expand All @@ -885,7 +885,7 @@ func TestCollection(t *testing.T) {
}{
{"no options", bson.D{}, nil, all},
{"filter", bson.D{{"x", bson.D{{"$gt", 2}}}}, nil, last3},
{"options", bson.D{}, options.Distinct().SetMaxTime(5000000000), all},
{"options", bson.D{}, options.Distinct().SetComment(1), all},
}
for _, tc := range testCases {
mt.Run(tc.name, func(mt *mtest.T) {
Expand Down Expand Up @@ -1144,7 +1144,6 @@ func TestCollection(t *testing.T) {
SetComment(expectedComment).
SetHint(indexName).
SetMax(bson.D{{"x", int32(5)}}).
SetMaxTime(1 * time.Second).
SetMin(bson.D{{"x", int32(0)}}).
SetProjection(bson.D{{"x", int32(1)}}).
SetReturnKey(false).
Expand All @@ -1166,7 +1165,6 @@ func TestCollection(t *testing.T) {
AppendString("comment", expectedComment).
AppendString("hint", indexName).
StartDocument("max").AppendInt32("x", 5).FinishDocument().
AppendInt32("maxTimeMS", 1000).
StartDocument("min").AppendInt32("x", 0).FinishDocument().
StartDocument("projection").AppendInt32("x", 1).FinishDocument().
AppendBoolean("returnKey", false).
Expand Down
4 changes: 0 additions & 4 deletions internal/integration/crud_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ func executeAggregate(mt *mtest.T, agg aggregator, sess mongo.Session, args bson
opts.SetBatchSize(val.Int32())
case "collation":
opts.SetCollation(createCollation(mt, val.Document()))
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
case "allowDiskUse":
opts.SetAllowDiskUse(val.Boolean())
case "session":
Expand Down Expand Up @@ -350,8 +348,6 @@ func setFindModifiers(modifiersDoc bson.Raw, opts *options.FindOptions) {
opts.SetHint(val.Document())
case "$max":
opts.SetMax(val.Document())
case "$maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
case "$min":
opts.SetMin(val.Document())
case "$returnKey":
Expand Down
13 changes: 8 additions & 5 deletions internal/integration/index_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package integration
import (
"context"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -567,16 +566,20 @@ func TestIndexView(t *testing.T) {
assert.True(mt, cmp.Equal(specs, expectedSpecs), "expected specifications to match: %v", cmp.Diff(specs, expectedSpecs))
})
mt.RunOpts("options passed to listIndexes", mtest.NewOptions().MinServerVersion("3.0"), func(mt *mtest.T) {
opts := options.ListIndexes().SetMaxTime(100 * time.Millisecond)
opts := options.ListIndexes().SetBatchSize(1)
_, err := mt.Coll.Indexes().ListSpecifications(context.Background(), opts)
assert.Nil(mt, err, "ListSpecifications error: %v", err)

evt := mt.GetStartedEvent()
assert.Equal(mt, evt.CommandName, "listIndexes", "expected %q command to be sent, got %q", "listIndexes",
evt.CommandName)
maxTimeMS, ok := evt.Command.Lookup("maxTimeMS").Int64OK()
assert.True(mt, ok, "expected command %v to contain %q field", evt.Command, "maxTimeMS")
assert.Equal(mt, int64(100), maxTimeMS, "expected maxTimeMS value to be 100, got %d", maxTimeMS)

cursorDoc, ok := evt.Command.Lookup("cursor").DocumentOK()
assert.True(mt, ok, "expected command: %v to contain a cursor document", evt.Command)

batchSize, ok := cursorDoc.Lookup("batchSize").Int32OK()
assert.True(mt, ok, "expected command %v to contain %q field", evt.Command, "batchSize")
assert.Equal(mt, int32(1), batchSize, "expected maxTimeMS value to be 1, got %d", batchSize)
})
})
mt.Run("drop one", func(mt *mtest.T) {
Expand Down
23 changes: 10 additions & 13 deletions internal/integration/unified/collection_operation_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ func executeAggregate(ctx context.Context, operation *operation) (*operationResu
return nil, fmt.Errorf("error creating hint: %v", err)
}
opts.SetHint(hint)
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
case "maxAwaitTimeMS":
opts.SetMaxAwaitTime(time.Duration(val.Int32()) * time.Millisecond)
case "pipeline":
Expand Down Expand Up @@ -194,7 +192,7 @@ func executeCountDocuments(ctx context.Context, operation *operation) (*operatio
case "limit":
opts.SetLimit(val.Int64())
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
case "skip":
opts.SetSkip(int64(val.Int32()))
default:
Expand Down Expand Up @@ -519,7 +517,7 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul
case "filter":
filter = val.Document()
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
default:
return nil, fmt.Errorf("unrecognized distinct option %q", key)
}
Expand Down Expand Up @@ -560,7 +558,7 @@ func executeDropIndex(ctx context.Context, operation *operation) (*operationResu
case "name":
name = val.StringValue()
case "maxTimeMS":
dropIndexOpts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
default:
return nil, fmt.Errorf("unrecognized dropIndex option %q", key)
}
Expand All @@ -583,11 +581,10 @@ func executeDropIndexes(ctx context.Context, operation *operation) (*operationRe
elems, _ := operation.Arguments.Elements()
for _, elem := range elems {
key := elem.Key()
val := elem.Value()

switch key {
case "maxTimeMS":
dropIndexOpts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
default:
return nil, fmt.Errorf("unrecognized dropIndexes option %q", key)
}
Expand Down Expand Up @@ -648,7 +645,7 @@ func executeEstimatedDocumentCount(ctx context.Context, operation *operation) (*
case "comment":
opts.SetComment(val)
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
default:
return nil, fmt.Errorf("unrecognized estimatedDocumentCount option %q", key)
}
Expand Down Expand Up @@ -725,7 +722,7 @@ func executeFindOne(ctx context.Context, operation *operation) (*operationResult
}
opts.SetHint(hint)
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
case "projection":
opts.SetProjection(val.Document())
case "sort":
Expand Down Expand Up @@ -784,7 +781,7 @@ func executeFindOneAndDelete(ctx context.Context, operation *operation) (*operat
}
opts.SetHint(hint)
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
case "projection":
opts.SetProjection(val.Document())
case "sort":
Expand Down Expand Up @@ -850,7 +847,7 @@ func executeFindOneAndReplace(ctx context.Context, operation *operation) (*opera
case "let":
opts.SetLet(val.Document())
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
case "projection":
opts.SetProjection(val.Document())
case "replacement":
Expand Down Expand Up @@ -934,7 +931,7 @@ func executeFindOneAndUpdate(ctx context.Context, operation *operation) (*operat
case "let":
opts.SetLet(val.Document())
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
case "projection":
opts.SetProjection(val.Document())
case "returnDocument":
Expand Down Expand Up @@ -1397,7 +1394,7 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult,
case "max":
opts.SetMax(val.Document())
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
case "min":
opts.SetMin(val.Document())
case "noCursorTimeout":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"fmt"
"io"
"math"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsontype"
Expand All @@ -40,7 +39,7 @@ func createBucketFindCursor(ctx context.Context, operation *operation) (*cursorR

switch key {
case "maxTimeMS":
opts.SetMaxTime(time.Duration(val.Int32()) * time.Millisecond)
return nil, newSkipTestError("the maxTimeMS collection option is not supported")
case "filter":
filter = val.Document()
default:
Expand Down
44 changes: 8 additions & 36 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,9 +938,6 @@ func mergeAggregateOptions(opts ...*options.AggregateOptions) *options.Aggregate
if ao.Collation != nil {
aggOpts.Collation = ao.Collation
}
if ao.MaxTime != nil {
aggOpts.MaxTime = ao.MaxTime
}
if ao.MaxAwaitTime != nil {
aggOpts.MaxAwaitTime = ao.MaxAwaitTime
}
Expand Down Expand Up @@ -1025,8 +1022,7 @@ func aggregate(a aggregateParams) (cur *Cursor, err error) {
Crypt(a.client.cryptFLE).
ServerAPI(a.client.serverAPI).
HasOutputStage(hasOutputStage).
Timeout(a.client.timeout).
MaxTime(ao.MaxTime)
Timeout(a.client.timeout)

if ao.AllowDiskUse != nil {
op.AllowDiskUse(*ao.AllowDiskUse)
Expand Down Expand Up @@ -1140,9 +1136,6 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{},
if co.Limit != nil {
countOpts.Limit = co.Limit
}
if co.MaxTime != nil {
countOpts.MaxTime = co.MaxTime
}
if co.Skip != nil {
countOpts.Skip = co.Skip
}
Expand Down Expand Up @@ -1171,7 +1164,7 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{},
op := operation.NewAggregate(pipelineArr).Session(sess).ReadConcern(rc).ReadPreference(coll.readPreference).
CommandMonitor(coll.client.monitor).ServerSelector(selector).ClusterClock(coll.client.clock).Database(coll.db.name).
Collection(coll.name).Deployment(coll.client.deployment).Crypt(coll.client.cryptFLE).ServerAPI(coll.client.serverAPI).
Timeout(coll.client.timeout).MaxTime(countOpts.MaxTime)
Timeout(coll.client.timeout)
if countOpts.Collation != nil {
op.Collation(bsoncore.Document(countOpts.Collation.ToDocument()))
}
Expand Down Expand Up @@ -1262,16 +1255,13 @@ func (coll *Collection) EstimatedDocumentCount(ctx context.Context,
if opt.Comment != nil {
co.Comment = opt.Comment
}
if opt.MaxTime != nil {
co.MaxTime = opt.MaxTime
}
}
selector := makeReadPrefSelector(sess, coll.readSelector, coll.client.localThreshold)
op := operation.NewCount().Session(sess).ClusterClock(coll.client.clock).
Database(coll.db.name).Collection(coll.name).CommandMonitor(coll.client.monitor).
Deployment(coll.client.deployment).ReadConcern(rc).ReadPreference(coll.readPreference).
ServerSelector(selector).Crypt(coll.client.cryptFLE).ServerAPI(coll.client.serverAPI).
Timeout(coll.client.timeout).MaxTime(co.MaxTime)
Timeout(coll.client.timeout)

if co.Comment != nil {
comment, err := marshalValue(co.Comment, coll.bsonOpts, coll.registry)
Expand Down Expand Up @@ -1342,17 +1332,14 @@ func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter i
if do.Comment != nil {
option.Comment = do.Comment
}
if do.MaxTime != nil {
option.MaxTime = do.MaxTime
}
}

op := operation.NewDistinct(fieldName, f).
Session(sess).ClusterClock(coll.client.clock).
Database(coll.db.name).Collection(coll.name).CommandMonitor(coll.client.monitor).
Deployment(coll.client.deployment).ReadConcern(rc).ReadPreference(coll.readPreference).
ServerSelector(selector).Crypt(coll.client.cryptFLE).ServerAPI(coll.client.serverAPI).
Timeout(coll.client.timeout).MaxTime(option.MaxTime)
Timeout(coll.client.timeout)

if option.Collation != nil {
op.Collation(bsoncore.Document(option.Collation.ToDocument()))
Expand Down Expand Up @@ -1438,9 +1425,6 @@ func mergeFindOptions(opts ...*options.FindOptions) *options.FindOptions {
if opt.MaxAwaitTime != nil {
fo.MaxAwaitTime = opt.MaxAwaitTime
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Min != nil {
fo.Min = opt.Min
}
Expand Down Expand Up @@ -1516,7 +1500,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
CommandMonitor(coll.client.monitor).ServerSelector(selector).
ClusterClock(coll.client.clock).Database(coll.db.name).Collection(coll.name).
Deployment(coll.client.deployment).Crypt(coll.client.cryptFLE).ServerAPI(coll.client.serverAPI).
Timeout(coll.client.timeout).MaxTime(fo.MaxTime).Logger(coll.client.logger)
Timeout(coll.client.timeout).Logger(coll.client.logger)

cursorOpts := coll.client.createBaseCursorOptions()

Expand Down Expand Up @@ -1655,7 +1639,6 @@ func newFindOptionsFromFindOneOptions(opts ...*options.FindOneOptions) []*option
Comment: opt.Comment,
Hint: opt.Hint,
Max: opt.Max,
MaxTime: opt.MaxTime,
Min: opt.Min,
Projection: opt.Projection,
ReturnKey: opt.ReturnKey,
Expand Down Expand Up @@ -1768,9 +1751,6 @@ func mergeFindOneAndDeleteOptions(opts ...*options.FindOneAndDeleteOptions) *opt
if opt.Comment != nil {
fo.Comment = opt.Comment
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Projection != nil {
fo.Projection = opt.Projection
}
Expand Down Expand Up @@ -1807,8 +1787,7 @@ func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{}
return &SingleResult{err: err}
}
fod := mergeFindOneAndDeleteOptions(opts...)
op := operation.NewFindAndModify(f).Remove(true).ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout).
MaxTime(fod.MaxTime)
op := operation.NewFindAndModify(f).Remove(true).ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout)
if fod.Collation != nil {
op = op.Collation(bsoncore.Document(fod.Collation.ToDocument()))
}
Expand Down Expand Up @@ -1874,9 +1853,6 @@ func mergeFindOneAndReplaceOptions(opts ...*options.FindOneAndReplaceOptions) *o
if opt.Comment != nil {
fo.Comment = opt.Comment
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Projection != nil {
fo.Projection = opt.Projection
}
Expand Down Expand Up @@ -1931,7 +1907,7 @@ func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{

fo := mergeFindOneAndReplaceOptions(opts...)
op := operation.NewFindAndModify(f).Update(bsoncore.Value{Type: bsontype.EmbeddedDocument, Data: r}).
ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout).MaxTime(fo.MaxTime)
ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout)
if fo.BypassDocumentValidation != nil && *fo.BypassDocumentValidation {
op = op.BypassDocumentValidation(*fo.BypassDocumentValidation)
}
Expand Down Expand Up @@ -2009,9 +1985,6 @@ func mergeFindOneAndUpdateOptions(opts ...*options.FindOneAndUpdateOptions) *opt
if opt.Comment != nil {
fo.Comment = opt.Comment
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Projection != nil {
fo.Projection = opt.Projection
}
Expand Down Expand Up @@ -2063,8 +2036,7 @@ func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}
}

fo := mergeFindOneAndUpdateOptions(opts...)
op := operation.NewFindAndModify(f).ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout).
MaxTime(fo.MaxTime)
op := operation.NewFindAndModify(f).ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout)

u, err := marshalUpdateValue(update, coll.bsonOpts, coll.registry, true)
if err != nil {
Expand Down
Loading

0 comments on commit 54abbc5

Please sign in to comment.