Skip to content

Commit 2820bb6

Browse files
author
Oleksandr Poliakov
committed
tmp
1 parent 53698ed commit 2820bb6

File tree

66 files changed

+795
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+795
-465
lines changed

src/MongoDB.Driver/AggregateOptions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2015-present MongoDB Inc.
1+
/* Copyright 2010-present MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ public class AggregateOptions
3434
private BsonDocument _let;
3535
private TimeSpan? _maxAwaitTime;
3636
private TimeSpan? _maxTime;
37+
private TimeSpan? _timeout;
3738
private ExpressionTranslationOptions _translationOptions;
3839
private bool? _useCursor;
3940

@@ -121,12 +122,22 @@ public TimeSpan? MaxAwaitTime
121122
/// <summary>
122123
/// Gets or sets the maximum time.
123124
/// </summary>
125+
[Obsolete("Use Timeout instead")]
124126
public TimeSpan? MaxTime
125127
{
126128
get { return _maxTime; }
127129
set { _maxTime = Ensure.IsNullOrInfiniteOrGreaterThanOrEqualToZero(value, nameof(value)); }
128130
}
129131

132+
/// <summary>
133+
/// Gets or sets the operation timeout.
134+
/// </summary>
135+
public TimeSpan? Timeout
136+
{
137+
get => _timeout;
138+
set => _timeout = Ensure.IsNullOrValidTimeout(value, nameof(Timeout));
139+
}
140+
130141
/// <summary>
131142
/// Gets or sets the translation options.
132143
/// </summary>

src/MongoDB.Driver/BulkWriteOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
1617
using MongoDB.Bson;
18+
using MongoDB.Driver.Core.Misc;
1719

1820
namespace MongoDB.Driver
1921
{
@@ -27,6 +29,7 @@ public sealed class BulkWriteOptions
2729
private BsonValue _comment;
2830
private bool _isOrdered;
2931
private BsonDocument _let;
32+
private TimeSpan? _timeout;
3033

3134
// constructors
3235
/// <summary>
@@ -73,5 +76,14 @@ public BsonDocument Let
7376
get { return _let; }
7477
set { _let = value; }
7578
}
79+
80+
/// <summary>
81+
/// Gets or sets the operation timeout.
82+
/// </summary>
83+
public TimeSpan? Timeout
84+
{
85+
get => _timeout;
86+
set => _timeout = Ensure.IsNullOrValidTimeout(value, nameof(Timeout));
87+
}
7688
}
7789
}

src/MongoDB.Driver/ChangeStreamOptions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2017-present MongoDB Inc.
1+
/* Copyright 2010-present MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ public class ChangeStreamOptions
3535
private bool? _showExpandedEvents;
3636
private BsonDocument _startAfter;
3737
private BsonTimestamp _startAtOperationTime;
38+
private TimeSpan? _timeout;
3839

3940
// public properties
4041
/// <summary>
@@ -166,5 +167,14 @@ public BsonTimestamp StartAtOperationTime
166167
get { return _startAtOperationTime; }
167168
set { _startAtOperationTime = value; }
168169
}
170+
171+
/// <summary>
172+
/// Gets or sets the operation timeout.
173+
/// </summary>
174+
public TimeSpan? Timeout
175+
{
176+
get => _timeout;
177+
set => _timeout = Ensure.IsNullOrValidTimeout(value, nameof(Timeout));
178+
}
169179
}
170180
}

src/MongoDB.Driver/ClientBulkWriteOptions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
1617
using MongoDB.Bson;
18+
using MongoDB.Driver.Core.Misc;
1719

1820
namespace MongoDB.Driver
1921
{
@@ -22,6 +24,8 @@ namespace MongoDB.Driver
2224
/// </summary>
2325
public sealed class ClientBulkWriteOptions
2426
{
27+
private TimeSpan? _timeout;
28+
2529
/// <summary>
2630
/// Initializes a new instance of the <see cref="BulkWriteOptions"/> class.
2731
/// </summary>
@@ -75,6 +79,15 @@ public ClientBulkWriteOptions(
7579
/// </summary>
7680
public BsonDocument Let { get; set; }
7781

82+
/// <summary>
83+
/// Gets or sets the operation timeout.
84+
/// </summary>
85+
public TimeSpan? Timeout
86+
{
87+
get => _timeout;
88+
set => _timeout = Ensure.IsNullOrValidTimeout(value, nameof(Timeout));
89+
}
90+
7891
/// <summary>
7992
/// Whether detailed results for each successful operation should be included in the returned results.
8093
/// </summary>

src/MongoDB.Driver/OperationOptionsBase.cs renamed to src/MongoDB.Driver/ClientSessionExtensions.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
17-
using System.Threading;
16+
namespace MongoDB.Driver;
1817

19-
namespace MongoDB.Driver
18+
internal static class ClientSessionExtensions
2019
{
21-
internal abstract record OperationOptionsBase(TimeSpan Timeout)
20+
public static ReadPreference GetEffectiveReadPreference(this IClientSession session, ReadPreference defaultReadPreference)
2221
{
23-
public OperationContext ToOperationContext(CancellationToken cancellationToken)
24-
=> new (Timeout, cancellationToken);
22+
if (session.IsInTransaction)
23+
{
24+
var transactionReadPreference = session.WrappedCoreSession.CurrentTransaction.TransactionOptions.ReadPreference;
25+
if (transactionReadPreference != null)
26+
{
27+
return transactionReadPreference;
28+
}
29+
}
30+
31+
return defaultReadPreference ?? ReadPreference.Primary;
2532
}
2633
}
2734

src/MongoDB.Driver/Core/Configuration/ConnectionString.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ public bool? Ssl
471471
/// <summary>
472472
/// Gets the per-operation timeout
473473
/// </summary>
474-
// TODO: CSOT: Make it public when CSOT will be ready for GA release
475-
internal TimeSpan? Timeout => _timeout;
474+
public TimeSpan? Timeout => _timeout;
476475

477476
/// <summary>
478477
/// Gets whether to use TLS.

src/MongoDB.Driver/Core/Misc/Ensure.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2013-present MongoDB Inc.
1+
/* Copyright 2010-present MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -444,11 +444,12 @@ public static string IsNullOrNotEmpty(string value, string paramName)
444444
/// <returns>The value of the parameter.</returns>
445445
public static TimeSpan? IsNullOrValidTimeout(TimeSpan? value, string paramName)
446446
{
447-
if (value != null)
447+
if (value == null)
448448
{
449-
IsValidTimeout(value.Value, paramName);
449+
return null;
450450
}
451-
return value;
451+
452+
return IsValidTimeout(value.Value, paramName);
452453
}
453454

454455
/// <summary>
@@ -459,12 +460,12 @@ public static string IsNullOrNotEmpty(string value, string paramName)
459460
/// <returns>The value of the parameter.</returns>
460461
public static TimeSpan IsValidTimeout(TimeSpan value, string paramName)
461462
{
462-
if (value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan)
463+
if (value > TimeSpan.Zero || value == Timeout.InfiniteTimeSpan)
463464
{
464-
var message = string.Format("Invalid timeout: {0}.", value);
465-
throw new ArgumentException(message, paramName);
465+
return value;
466466
}
467-
return value;
467+
468+
throw new ArgumentException($"Invalid timeout: {value}.", paramName);
468469
}
469470

470471
/// <summary>

src/MongoDB.Driver/CountOptions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public sealed class CountOptions
3131
private long? _limit;
3232
private TimeSpan? _maxTime;
3333
private long? _skip;
34+
private TimeSpan? _timeout;
3435

3536
// properties
3637
/// <summary>
@@ -72,6 +73,7 @@ public long? Limit
7273
/// <summary>
7374
/// Gets or sets the maximum time.
7475
/// </summary>
76+
[Obsolete("Use Timeout instead")]
7577
public TimeSpan? MaxTime
7678
{
7779
get { return _maxTime; }
@@ -86,5 +88,14 @@ public long? Skip
8688
get { return _skip; }
8789
set { _skip = value; }
8890
}
91+
92+
/// <summary>
93+
/// Gets or sets the operation timeout.
94+
/// </summary>
95+
public TimeSpan? Timeout
96+
{
97+
get => _timeout;
98+
set => _timeout = Ensure.IsNullOrValidTimeout(value, nameof(Timeout));
99+
}
89100
}
90101
}

src/MongoDB.Driver/CreateCollectionOptions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System;
1717
using MongoDB.Bson;
1818
using MongoDB.Bson.Serialization;
19+
using MongoDB.Driver.Core.Misc;
1920

2021
namespace MongoDB.Driver
2122
{
@@ -35,6 +36,7 @@ public class CreateCollectionOptions
3536
private long? _maxSize;
3637
private bool? _noPadding;
3738
private BsonDocument _storageEngine;
39+
private TimeSpan? _timeout;
3840
private TimeSeriesOptions _timeSeriesOptions;
3941
private bool? _usePowerOf2Sizes;
4042
private IBsonSerializerRegistry _serializerRegistry;
@@ -145,6 +147,15 @@ public BsonDocument StorageEngine
145147
set { _storageEngine = value; }
146148
}
147149

150+
/// <summary>
151+
/// Gets or sets the operation timeout.
152+
/// </summary>
153+
public TimeSpan? Timeout
154+
{
155+
get => _timeout;
156+
set => _timeout = Ensure.IsNullOrValidTimeout(value, nameof(Timeout));
157+
}
158+
148159
/// <summary>
149160
/// Gets or sets the <see cref="TimeSeriesOptions"/> to use when creating a time series collection.
150161
/// </summary>

src/MongoDB.Driver/CreateManyIndexesOptions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2018-present MongoDB Inc.
1+
/* Copyright 2010-present MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ public class CreateManyIndexesOptions
2828
private BsonValue _comment;
2929
private CreateIndexCommitQuorum _commitQuorum;
3030
private TimeSpan? _maxTime;
31+
private TimeSpan? _timeout;
3132

3233
// public properties
3334
/// <summary>
@@ -54,10 +55,20 @@ public CreateIndexCommitQuorum CommitQuorum
5455
/// Gets or sets the maximum time.
5556
/// </summary>
5657
/// <value>The maximum time.</value>
58+
[Obsolete("Use Timeout instead")]
5759
public TimeSpan? MaxTime
5860
{
5961
get { return _maxTime; }
6062
set { _maxTime = Ensure.IsNullOrInfiniteOrGreaterThanOrEqualToZero(value, nameof(value)); }
6163
}
64+
65+
/// <summary>
66+
/// Gets or sets the operation timeout.
67+
/// </summary>
68+
public TimeSpan? Timeout
69+
{
70+
get => _timeout;
71+
set => _timeout = Ensure.IsNullOrValidTimeout(value, nameof(Timeout));
72+
}
6273
}
6374
}

0 commit comments

Comments
 (0)