Skip to content

Commit c0f286b

Browse files
CSHARP-3480: Switch to using maxWireVersion rather than buildInfo to determine feature support. (#720)
CSHARP-3480: Switch to using maxWireVersion rather than buildInfo to determine feature support.
1 parent 1cc033d commit c0f286b

File tree

118 files changed

+1551
-2437
lines changed

Some content is hidden

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

118 files changed

+1551
-2437
lines changed

src/MongoDB.Driver.Core/Core/Authentication/DefaultAuthenticator.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,15 @@ public void Authenticate(IConnection connection, ConnectionDescription descripti
8484
// hello or legacy hello request and should query the server (provided that the server >= 4.0), merging results into
8585
// a new ConnectionDescription
8686
if (!description.HelloResult.HasSaslSupportedMechs
87-
&& Feature.ScramSha256Authentication.IsSupported(description.ServerVersion))
87+
&& Feature.ScramSha256Authentication.IsSupported(description.MaxWireVersion))
8888
{
8989
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi));
9090
var helloProtocol = HelloHelper.CreateProtocol(command, _serverApi);
9191
var helloResult = HelloHelper.GetResult(connection, helloProtocol, cancellationToken);
9292
var mergedHelloResult = new HelloResult(description.HelloResult.Wrapped.Merge(helloResult.Wrapped));
9393
description = new ConnectionDescription(
9494
description.ConnectionId,
95-
mergedHelloResult,
96-
description.BuildInfoResult);
95+
mergedHelloResult);
9796
}
9897

9998
var authenticator = GetOrCreateAuthenticator(connection, description);
@@ -110,16 +109,15 @@ public async Task AuthenticateAsync(IConnection connection, ConnectionDescriptio
110109
// hello or legacy hello request and should query the server (provided that the server >= 4.0), merging results into
111110
// a new ConnectionDescription
112111
if (!description.HelloResult.HasSaslSupportedMechs
113-
&& Feature.ScramSha256Authentication.IsSupported(description.ServerVersion))
112+
&& Feature.ScramSha256Authentication.IsSupported(description.MaxWireVersion))
114113
{
115114
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi));
116115
var helloProtocol = HelloHelper.CreateProtocol(command, _serverApi);
117116
var helloResult = await HelloHelper.GetResultAsync(connection, helloProtocol, cancellationToken).ConfigureAwait(false);
118117
var mergedHelloResult = new HelloResult(description.HelloResult.Wrapped.Merge(helloResult.Wrapped));
119118
description = new ConnectionDescription(
120119
description.ConnectionId,
121-
mergedHelloResult,
122-
description.BuildInfoResult);
120+
mergedHelloResult);
123121
}
124122

125123
var authenticator = GetOrCreateAuthenticator(connection, description);

src/MongoDB.Driver.Core/Core/Bindings/CoreSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,13 @@ private void EnsureTransactionsAreSupported()
510510
case ServerType.Standalone:
511511
throw new NotSupportedException("Standalone servers do not support transactions.");
512512
case ServerType.ShardRouter:
513-
Feature.ShardedTransactions.ThrowIfNotSupported(connectedDataBearingServer.Version);
513+
Feature.ShardedTransactions.ThrowIfNotSupported(connectedDataBearingServer.MaxWireVersion);
514514
break;
515515
case ServerType.LoadBalanced:
516516
// do nothing, load balancing always supports transactions
517517
break;
518518
default:
519-
Feature.Transactions.ThrowIfNotSupported(connectedDataBearingServer.Version);
519+
Feature.Transactions.ThrowIfNotSupported(connectedDataBearingServer.MaxWireVersion);
520520
break;
521521
}
522522
}

src/MongoDB.Driver.Core/Core/Clusters/Cluster.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ internal abstract class Cluster : ICluster
3838
#region static
3939
// static fields
4040
private static readonly TimeSpan __minHeartbeatIntervalDefault = TimeSpan.FromMilliseconds(500);
41-
private static readonly SemanticVersion __minSupportedServerVersion = new SemanticVersion(3, 6, 0);
41+
private static readonly SemanticVersion __minSupportedServerVersion = WireVersion.ToServerVersion(WireVersion.SupportedWireVersionRange.Min);
4242
private static readonly IServerSelector __randomServerSelector = new RandomServerSelector();
43-
private static readonly Range<int> __supportedWireVersionRange = new Range<int>(6, 15);
43+
private static readonly Range<int> __supportedWireVersionRange = WireVersion.SupportedWireVersionRange;
4444

4545
// static properties
4646
/// <summary>

src/MongoDB.Driver.Core/Core/Connections/BuildInfoResult.cs

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/MongoDB.Driver.Core/Core/Connections/ConnectionDescription.cs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ namespace MongoDB.Driver.Core.Connections
2828
public sealed class ConnectionDescription : IEquatable<ConnectionDescription>
2929
{
3030
// fields
31-
private readonly BuildInfoResult _buildInfoResult;
3231
private readonly IReadOnlyList<CompressorType> _compressors;
3332
private readonly ConnectionId _connectionId;
3433
private readonly HelloResult _helloResult;
3534
private readonly int _maxBatchCount;
3635
private readonly int _maxDocumentSize;
3736
private readonly int _maxMessageSize;
37+
private readonly int _maxWireVersion;
38+
private readonly int _minWireVersion;
3839
private readonly SemanticVersion _serverVersion;
3940
private readonly ObjectId? _serviceId;
4041

@@ -44,33 +45,22 @@ public sealed class ConnectionDescription : IEquatable<ConnectionDescription>
4445
/// </summary>
4546
/// <param name="connectionId">The connection identifier.</param>
4647
/// <param name="helloResult">The hello result.</param>
47-
/// <param name="buildInfoResult">The buildInfo result.</param>
48-
public ConnectionDescription(ConnectionId connectionId, HelloResult helloResult, BuildInfoResult buildInfoResult)
48+
public ConnectionDescription(ConnectionId connectionId, HelloResult helloResult)
4949
{
5050
_connectionId = Ensure.IsNotNull(connectionId, nameof(connectionId));
51-
_buildInfoResult = Ensure.IsNotNull(buildInfoResult, nameof(buildInfoResult));
5251
_helloResult = Ensure.IsNotNull(helloResult, nameof(helloResult));
5352

5453
_compressors = Ensure.IsNotNull(_helloResult.Compressions, "compressions");
5554
_maxBatchCount = helloResult.MaxBatchCount;
5655
_maxDocumentSize = helloResult.MaxDocumentSize;
5756
_maxMessageSize = helloResult.MaxMessageSize;
57+
_maxWireVersion = helloResult.MaxWireVersion;
58+
_minWireVersion = helloResult.MinWireVersion;
5859
_serviceId = helloResult.ServiceId;
59-
_serverVersion = buildInfoResult.ServerVersion;
60+
_serverVersion = WireVersion.ToServerVersion(_maxWireVersion);
6061
}
6162

6263
// properties
63-
/// <summary>
64-
/// Gets the buildInfo result.
65-
/// </summary>
66-
/// <value>
67-
/// The buildInfo result.
68-
/// </value>
69-
public BuildInfoResult BuildInfoResult
70-
{
71-
get { return _buildInfoResult; }
72-
}
73-
7464
/// <summary>
7565
/// Gets the available compressors.
7666
/// </summary>
@@ -157,12 +147,35 @@ public int MaxWireDocumentSize
157147
get { return _maxDocumentSize + 16 * 1024; }
158148
}
159149

150+
/// <summary>
151+
/// Gets the maximum wire version.
152+
/// </summary>
153+
/// <value>
154+
/// The maximum wire version.
155+
/// </value>
156+
public int MaxWireVersion
157+
{
158+
get { return _maxWireVersion; }
159+
}
160+
161+
/// <summary>
162+
/// Gets the minimum wire version.
163+
/// </summary>
164+
/// <value>
165+
/// The minimum wire version.
166+
/// </value>
167+
public int MinWireVersion
168+
{
169+
get { return _minWireVersion; }
170+
}
171+
160172
/// <summary>
161173
/// Gets the server version.
162174
/// </summary>
163175
/// <value>
164176
/// The server version.
165177
/// </value>
178+
[Obsolete("Use MaxWireVersion instead.")]
166179
public SemanticVersion ServerVersion
167180
{
168181
get { return _serverVersion; }
@@ -189,7 +202,6 @@ public bool Equals(ConnectionDescription other)
189202
}
190203

191204
return
192-
_buildInfoResult.Equals(other._buildInfoResult) &&
193205
_connectionId.StructurallyEquals(other._connectionId) &&
194206
_helloResult.Equals(other._helloResult);
195207
}
@@ -204,7 +216,6 @@ public override bool Equals(object obj)
204216
public override int GetHashCode()
205217
{
206218
return new Hasher()
207-
.Hash(_buildInfoResult)
208219
.Hash(_connectionId)
209220
.Hash(_helloResult)
210221
.GetHashCode();
@@ -217,7 +228,7 @@ public override int GetHashCode()
217228
/// <returns>A connection description.</returns>
218229
public ConnectionDescription WithConnectionId(ConnectionId value)
219230
{
220-
return _connectionId.StructurallyEquals(value) ? this : new ConnectionDescription(value, _helloResult, _buildInfoResult);
231+
return _connectionId.StructurallyEquals(value) ? this : new ConnectionDescription(value, _helloResult);
221232
}
222233
}
223234
}

src/MongoDB.Driver.Core/Core/Connections/ConnectionInitializer.cs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ public ConnectionDescription SendHello(IConnection connection, CancellationToken
122122
throw new InvalidOperationException("Driver attempted to initialize in load balancing mode, but the server does not support this mode.");
123123
}
124124

125-
var buildInfoProtocol = CreateBuildInfoProtocol(_serverApi);
126-
var buildInfoResult = new BuildInfoResult(buildInfoProtocol.Execute(connection, cancellationToken));
127-
128-
return new ConnectionDescription(connection.ConnectionId, helloResult, buildInfoResult);
125+
return new ConnectionDescription(connection.ConnectionId, helloResult);
129126
}
130127

131128
public async Task<ConnectionDescription> SendHelloAsync(IConnection connection, CancellationToken cancellationToken)
@@ -140,34 +137,10 @@ public async Task<ConnectionDescription> SendHelloAsync(IConnection connection,
140137
throw new InvalidOperationException("Driver attempted to initialize in load balancing mode, but the server does not support this mode.");
141138
}
142139

143-
var buildInfoProtocol = CreateBuildInfoProtocol(_serverApi);
144-
var buildInfoResult = new BuildInfoResult(await buildInfoProtocol.ExecuteAsync(connection, cancellationToken).ConfigureAwait(false));
145-
146-
return new ConnectionDescription(connection.ConnectionId, helloResult, buildInfoResult);
140+
return new ConnectionDescription(connection.ConnectionId, helloResult);
147141
}
148142

149143
// private methods
150-
private CommandWireProtocol<BsonDocument> CreateBuildInfoProtocol(ServerApi serverApi)
151-
{
152-
var buildInfoServerApi =
153-
serverApi != null
154-
? new ServerApi(
155-
serverApi.Version,
156-
strict: false, // buildInfo is not part of server API version 1 so we must skip strict flag, otherwise initialize will fail
157-
deprecationErrors: serverApi.DeprecationErrors)
158-
: null;
159-
160-
var buildInfoCommand = new BsonDocument("buildInfo", 1);
161-
var buildInfoProtocol = new CommandWireProtocol<BsonDocument>(
162-
databaseNamespace: DatabaseNamespace.Admin,
163-
command: buildInfoCommand,
164-
secondaryOk: true,
165-
resultSerializer: BsonDocumentSerializer.Instance,
166-
messageEncoderSettings: null,
167-
serverApi: buildInfoServerApi);
168-
return buildInfoProtocol;
169-
}
170-
171144
private CommandWireProtocol<BsonDocument> CreateGetLastErrorProtocol(ServerApi serverApi)
172145
{
173146
var getLastErrorCommand = new BsonDocument("getLastError", 1);

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

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)