Skip to content

Commit e3f53de

Browse files
authored
GODRIVER-2347 Further deprecate timeout options and clarify RunCommand behavior. (#982)
1 parent d02ee16 commit e3f53de

10 files changed

+122
-16
lines changed

mongo/database.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,13 @@ func (db *Database) processRunCommand(ctx context.Context, cmd interface{},
185185
//
186186
// The runCommand parameter must be a document for the command to be executed. It cannot be nil.
187187
// This must be an order-preserving type such as bson.D. Map types such as bson.M are not valid.
188-
// If the command document contains a session ID or any transaction-specific fields, the behavior is undefined.
189-
// Specifying API versioning options in the command document and declaring an API version on the client is not supported.
190-
// The behavior of RunCommand is undefined in this case.
191188
//
192189
// The opts parameter can be used to specify options for this operation (see the options.RunCmdOptions documentation).
190+
//
191+
// The behavior of RunCommand is undefined if the command document contains any of the following:
192+
// - A session ID or any transaction-specific fields
193+
// - API versioning options when an API version is already declared on the Client
194+
// - maxTimeMS when Timeout is set on the Client
193195
func (db *Database) RunCommand(ctx context.Context, runCommand interface{}, opts ...*options.RunCmdOptions) *SingleResult {
194196
if ctx == nil {
195197
ctx = context.Background()
@@ -218,9 +220,13 @@ func (db *Database) RunCommand(ctx context.Context, runCommand interface{}, opts
218220
//
219221
// The runCommand parameter must be a document for the command to be executed. It cannot be nil.
220222
// This must be an order-preserving type such as bson.D. Map types such as bson.M are not valid.
221-
// If the command document contains a session ID or any transaction-specific fields, the behavior is undefined.
222223
//
223224
// The opts parameter can be used to specify options for this operation (see the options.RunCmdOptions documentation).
225+
//
226+
// The behavior of RunCommandCursor is undefined if the command document contains any of the following:
227+
// - A session ID or any transaction-specific fields
228+
// - API versioning options when an API version is already declared on the Client
229+
// - maxTimeMS when Timeout is set on the Client
224230
func (db *Database) RunCommandCursor(ctx context.Context, runCommand interface{}, opts ...*options.RunCmdOptions) (*Cursor, error) {
225231
if ctx == nil {
226232
ctx = context.Background()

mongo/options/aggregateoptions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type AggregateOptions struct {
3434

3535
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
3636
// is no time limit for query execution.
37+
//
38+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
39+
// Timeout option should be used in its place to control the amount of time that the Aggregate operation can run before
40+
// returning an error. MaxTime is still usable through the deprecated setter.
3741
MaxTime *time.Duration
3842

3943
// The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
@@ -91,6 +95,10 @@ func (ao *AggregateOptions) SetCollation(c *Collation) *AggregateOptions {
9195
}
9296

9397
// SetMaxTime sets the value for the MaxTime field.
98+
//
99+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver.
100+
// The more general Timeout option should be used in its place to control the amount of time that the
101+
// Aggregate operation can run before returning an error.
94102
func (ao *AggregateOptions) SetMaxTime(d time.Duration) *AggregateOptions {
95103
ao.MaxTime = &d
96104
return ao

mongo/options/clientoptions.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,15 @@ func (c *ClientOptions) SetSocketTimeout(d time.Duration) *ClientOptions {
724724
}
725725

726726
// SetTimeout specifies the amount of time that a single operation run on this Client can execute before returning an error.
727-
// This can also be set through the "timeoutMS" URI option (e.g. "timeoutMS=1000"). The default value is nil, meaning operations
728-
// do not inherit a timeout from the Client.
727+
// The deadline of any operation run through the Client will be honored above any Timeout set on the Client; Timeout will only
728+
// be honored if there is no deadline on the operation Context. Timeout can also be set through the "timeoutMS" URI option
729+
// (e.g. "timeoutMS=1000"). The default value is nil, meaning operations do not inherit a timeout from the Client.
729730
//
730-
// If any Timeout is set (even 0) on the Client, the values of other, deprecated timeout-related options will be ignored. In particular:
731-
// ClientOptions.SocketTimeout, WriteConcern.wTimeout, MaxTime on operations, and TransactionOptions.MaxCommitTime.
731+
// If any Timeout is set (even 0) on the Client, the values of other, deprecated timeout-related options will be ignored.
732+
// In particular: ClientOptions.SocketTimeout, WriteConcern.wTimeout, MaxTime on operations, and TransactionOptions.MaxCommitTime.
733+
//
734+
// NOTE(benjirewis): SetTimeout represents unstable, provisional API. The behavior of the driver when a Timeout is specified is
735+
// subject to change.
732736
func (c *ClientOptions) SetTimeout(d time.Duration) *ClientOptions {
733737
c.Timeout = &d
734738
return c

mongo/options/countoptions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type CountOptions struct {
3333

3434
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there is
3535
// no time limit for query execution.
36+
//
37+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
38+
// Timeout option should be used in its place to control the amount of time that the count operation can run before
39+
// returning an error. MaxTime is still usable through the deprecated setter.
3640
MaxTime *time.Duration
3741

3842
// The number of documents to skip before counting. The default value is 0.
@@ -69,6 +73,10 @@ func (co *CountOptions) SetLimit(i int64) *CountOptions {
6973
}
7074

7175
// SetMaxTime sets the value for the MaxTime field.
76+
//
77+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
78+
// Timeout option should be used in its place to control the amount of time that the count operation can run before
79+
// returning an error.
7280
func (co *CountOptions) SetMaxTime(d time.Duration) *CountOptions {
7381
co.MaxTime = &d
7482
return co

mongo/options/distinctoptions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ type DistinctOptions struct {
1717

1818
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
1919
// is no time limit for query execution.
20+
//
21+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
22+
// Timeout option should be used in its place to control the amount of time that the Distinct operation can run before
23+
// returning an error. MaxTime is still usable through the deprecated setter.
2024
MaxTime *time.Duration
2125
}
2226

@@ -32,6 +36,10 @@ func (do *DistinctOptions) SetCollation(c *Collation) *DistinctOptions {
3236
}
3337

3438
// SetMaxTime sets the value for the MaxTime field.
39+
//
40+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
41+
// Timeout option should be used in its place to control the amount of time that the Distinct operation can run before
42+
// returning an error.
3543
func (do *DistinctOptions) SetMaxTime(d time.Duration) *DistinctOptions {
3644
do.MaxTime = &d
3745
return do

mongo/options/estimatedcountoptions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ type EstimatedDocumentCountOptions struct {
1616

1717
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
1818
// is no time limit for query execution.
19+
//
20+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
21+
// Timeout option should be used in its place to control the amount of time that the EstimatedDocumentCount operation
22+
// can run before returning an error. MaxTime is still usable through the deprecated setter.
1923
MaxTime *time.Duration
2024
}
2125

@@ -31,6 +35,10 @@ func (eco *EstimatedDocumentCountOptions) SetComment(comment interface{}) *Estim
3135
}
3236

3337
// SetMaxTime sets the value for the MaxTime field.
38+
//
39+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
40+
// Timeout option should be used in its place to control the amount of time that the EstimatedDocumentCount operation
41+
// can run before returning an error.
3442
func (eco *EstimatedDocumentCountOptions) SetMaxTime(d time.Duration) *EstimatedDocumentCountOptions {
3543
eco.MaxTime = &d
3644
return eco

mongo/options/findoptions.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ type FindOptions struct {
5555
// MaxAwaitTime is the maximum amount of time that the server should wait for new documents to satisfy a tailable cursor
5656
// query. This option is only valid for tailable await cursors (see the CursorType option for more information) and
5757
// MongoDB versions >= 3.2. For other cursor types or previous server versions, this option is ignored.
58-
//
59-
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
60-
// Timeout option should be used in its place to control the amount of time that the Find operation can run before
61-
// returning an error. MaxAwaitTime is still usable through the deprecated setter.
6258
MaxAwaitTime *time.Duration
6359

6460
// MaxTime is the maximum amount of time that the query can run on the server. The default value is nil, meaning that there
@@ -181,10 +177,6 @@ func (f *FindOptions) SetMax(max interface{}) *FindOptions {
181177
}
182178

183179
// SetMaxAwaitTime sets the value for the MaxAwaitTime field.
184-
//
185-
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver.
186-
// The more general Timeout option should be used in its place to control the amount of time that the
187-
// Find operation can run before returning an error.
188180
func (f *FindOptions) SetMaxAwaitTime(d time.Duration) *FindOptions {
189181
f.MaxAwaitTime = &d
190182
return f
@@ -377,6 +369,10 @@ type FindOneOptions struct {
377369

378370
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
379371
// is no time limit for query execution.
372+
//
373+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
374+
// Timeout option should be used in its place to control the amount of time that the FindOne operation can run before
375+
// returning an error. MaxTime is still usable through the deprecated setter.
380376
MaxTime *time.Duration
381377

382378
// A document specifying the inclusive lower bound for a specific index. The default value is 0, which means that
@@ -481,6 +477,10 @@ func (f *FindOneOptions) SetMaxAwaitTime(d time.Duration) *FindOneOptions {
481477
}
482478

483479
// SetMaxTime sets the value for the MaxTime field.
480+
//
481+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
482+
// Timeout option should be used in its place to control the amount of time that the FindOne operation can run before
483+
// returning an error.
484484
func (f *FindOneOptions) SetMaxTime(d time.Duration) *FindOneOptions {
485485
f.MaxTime = &d
486486
return f
@@ -633,6 +633,10 @@ type FindOneAndReplaceOptions struct {
633633

634634
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
635635
// is no time limit for query execution.
636+
//
637+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
638+
// Timeout option should be used in its place to control the amount of time that the FindOneAndReplace operation can
639+
// run before returning an error. MaxTime is still usable through the deprecated setter.
636640
MaxTime *time.Duration
637641

638642
// A document describing which fields will be included in the document returned by the operation. The default value
@@ -691,6 +695,10 @@ func (f *FindOneAndReplaceOptions) SetComment(comment interface{}) *FindOneAndRe
691695
}
692696

693697
// SetMaxTime sets the value for the MaxTime field.
698+
//
699+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
700+
// Timeout option should be used in its place to control the amount of time that the FindOneAndReplace operation can
701+
// run before returning an error.
694702
func (f *FindOneAndReplaceOptions) SetMaxTime(d time.Duration) *FindOneAndReplaceOptions {
695703
f.MaxTime = &d
696704
return f
@@ -799,6 +807,10 @@ type FindOneAndUpdateOptions struct {
799807

800808
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
801809
// is no time limit for query execution.
810+
//
811+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
812+
// Timeout option should be used in its place to control the amount of time that the FindOneAndUpdate operation can run
813+
// before returning an error. MaxTime is still usable through the deprecated setter.
802814
MaxTime *time.Duration
803815

804816
// A document describing which fields will be included in the document returned by the operation. The default value
@@ -863,6 +875,10 @@ func (f *FindOneAndUpdateOptions) SetComment(comment interface{}) *FindOneAndUpd
863875
}
864876

865877
// SetMaxTime sets the value for the MaxTime field.
878+
//
879+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
880+
// Timeout option should be used in its place to control the amount of time that the FindOneAndUpdate operation can run
881+
// before returning an error.
866882
func (f *FindOneAndUpdateOptions) SetMaxTime(d time.Duration) *FindOneAndUpdateOptions {
867883
f.MaxTime = &d
868884
return f
@@ -963,6 +979,10 @@ type FindOneAndDeleteOptions struct {
963979

964980
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
965981
// is no time limit for query execution.
982+
//
983+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
984+
// Timeout option should be used in its place to control the amount of time that the FindOneAndDelete operation can run
985+
// before returning an error. MaxTime is still usable through the deprecated setter.
966986
MaxTime *time.Duration
967987

968988
// A document describing which fields will be included in the document returned by the operation. The default value
@@ -1007,6 +1027,10 @@ func (f *FindOneAndDeleteOptions) SetComment(comment interface{}) *FindOneAndDel
10071027
}
10081028

10091029
// SetMaxTime sets the value for the MaxTime field.
1030+
//
1031+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
1032+
// Timeout option should be used in its place to control the amount of time that the FindOneAndDelete operation can run
1033+
// before returning an error.
10101034
func (f *FindOneAndDeleteOptions) SetMaxTime(d time.Duration) *FindOneAndDeleteOptions {
10111035
f.MaxTime = &d
10121036
return f

mongo/options/gridfsoptions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ type GridFSFindOptions struct {
225225

226226
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
227227
// is no time limit for query execution.
228+
//
229+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
230+
// Timeout option should be used in its place to control the amount of time that GridFS operations can run before
231+
// returning an error. MaxTime is still usable through the deprecated setter.
228232
MaxTime *time.Duration
229233

230234
// If true, the cursor created by the operation will not timeout after a period of inactivity. The default value
@@ -263,6 +267,10 @@ func (f *GridFSFindOptions) SetLimit(i int32) *GridFSFindOptions {
263267
}
264268

265269
// SetMaxTime sets the value for the MaxTime field.
270+
//
271+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver.
272+
// The more general Timeout option should be used in its place to control the amount of time that
273+
// GridFS operations can run before returning an error.
266274
func (f *GridFSFindOptions) SetMaxTime(d time.Duration) *GridFSFindOptions {
267275
f.MaxTime = &d
268276
return f

mongo/options/indexoptions.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ type CreateIndexesOptions struct {
2929

3030
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
3131
// is no time limit for query execution.
32+
//
33+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
34+
// Timeout option should be used in its place to control the amount of time that the create index operation can run before
35+
// returning an error. MaxTime is still usable through the deprecated setter.
3236
MaxTime *time.Duration
3337
}
3438

@@ -38,6 +42,10 @@ func CreateIndexes() *CreateIndexesOptions {
3842
}
3943

4044
// SetMaxTime sets the value for the MaxTime field.
45+
//
46+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
47+
// Timeout option should be used in its place to control the amount of time that the create index operation can run before
48+
// returning an error.
4149
func (c *CreateIndexesOptions) SetMaxTime(d time.Duration) *CreateIndexesOptions {
4250
c.MaxTime = &d
4351
return c
@@ -91,6 +99,10 @@ func MergeCreateIndexesOptions(opts ...*CreateIndexesOptions) *CreateIndexesOpti
9199
type DropIndexesOptions struct {
92100
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
93101
// is no time limit for query execution.
102+
//
103+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
104+
// Timeout option should be used in its place to control the amount of time that the drop index operation can run before
105+
// returning an error. MaxTime is still usable through the deprecated setter.
94106
MaxTime *time.Duration
95107
}
96108

@@ -100,6 +112,10 @@ func DropIndexes() *DropIndexesOptions {
100112
}
101113

102114
// SetMaxTime sets the value for the MaxTime field.
115+
//
116+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
117+
// Timeout option should be used in its place to control the amount of time that the drop index operation can run before
118+
// returning an error.
103119
func (d *DropIndexesOptions) SetMaxTime(duration time.Duration) *DropIndexesOptions {
104120
d.MaxTime = &duration
105121
return d
@@ -128,6 +144,10 @@ type ListIndexesOptions struct {
128144

129145
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
130146
// is no time limit for query execution.
147+
//
148+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
149+
// Timeout option should be used in its place to control the amount of time that the List operation can run before
150+
// returning an error. MaxTime is still usable through the deprecated setter.
131151
MaxTime *time.Duration
132152
}
133153

@@ -143,6 +163,10 @@ func (l *ListIndexesOptions) SetBatchSize(i int32) *ListIndexesOptions {
143163
}
144164

145165
// SetMaxTime sets the value for the MaxTime field.
166+
//
167+
// Deprecated: This option is deprecated and will eventually be removed in version 2.0 of the driver. The more general
168+
// Timeout option should be used in its place to control the amount of time that the List operation can run before
169+
// returning an error.
146170
func (l *ListIndexesOptions) SetMaxTime(d time.Duration) *ListIndexesOptions {
147171
l.MaxTime = &d
148172
return l

0 commit comments

Comments
 (0)