Skip to content

Commit d086a3e

Browse files
authored
CSHARP-3763: Default directConnection to false and remove ConnectMode logic (#1472)
1 parent efcbc44 commit d086a3e

File tree

70 files changed

+474
-2530
lines changed

Some content is hidden

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

70 files changed

+474
-2530
lines changed

src/MongoDB.Driver/ClusterKey.cs

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,23 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Linq;
19-
using MongoDB.Driver.Core.Clusters;
2019
using MongoDB.Driver.Core.Configuration;
2120
using MongoDB.Driver.Core.Servers;
2221
using MongoDB.Shared;
2322

2423
namespace MongoDB.Driver
2524
{
26-
internal class ClusterKey
25+
internal sealed class ClusterKey
2726
{
2827
// fields
2928
private readonly bool _allowInsecureTls;
3029
private readonly string _applicationName;
3130
private readonly Action<ClusterBuilder> _clusterConfigurator;
3231
private readonly IReadOnlyList<CompressorConfiguration> _compressors;
33-
#pragma warning disable CS0618 // Type or member is obsolete
34-
private readonly ConnectionMode _connectionMode;
35-
private readonly ConnectionModeSwitch _connectionModeSwitch;
36-
#pragma warning restore CS0618 // Type or member is obsolete
3732
private readonly TimeSpan _connectTimeout;
3833
private readonly MongoCredential _credential;
3934
private readonly CryptClientSettings _cryptClientSettings;
40-
private readonly bool? _directConnection;
35+
private readonly bool _directConnection;
4136
private readonly int _hashCode;
4237
private readonly TimeSpan _heartbeatInterval;
4338
private readonly TimeSpan _heartbeatTimeout;
@@ -73,14 +68,10 @@ public ClusterKey(
7368
string applicationName,
7469
Action<ClusterBuilder> clusterConfigurator,
7570
IReadOnlyList<CompressorConfiguration> compressors,
76-
#pragma warning disable CS0618 // Type or member is obsolete
77-
ConnectionMode connectionMode,
78-
ConnectionModeSwitch connectionModeSwitch,
79-
#pragma warning restore CS0618 // Type or member is obsolete
8071
TimeSpan connectTimeout,
8172
MongoCredential credential,
8273
CryptClientSettings cryptClientSettings,
83-
bool? directConnection,
74+
bool directConnection,
8475
TimeSpan heartbeatInterval,
8576
TimeSpan heartbeatTimeout,
8677
bool ipv6,
@@ -109,14 +100,10 @@ public ClusterKey(
109100
int waitQueueSize,
110101
TimeSpan waitQueueTimeout)
111102
{
112-
ConnectionModeHelper.EnsureConnectionModeValuesAreValid(connectionMode, connectionModeSwitch, directConnection);
113-
114103
_allowInsecureTls = allowInsecureTls;
115104
_applicationName = applicationName;
116105
_clusterConfigurator = clusterConfigurator;
117106
_compressors = compressors;
118-
_connectionMode = connectionMode;
119-
_connectionModeSwitch = connectionModeSwitch;
120107
_connectTimeout = connectTimeout;
121108
_credential = credential;
122109
_cryptClientSettings = cryptClientSettings;
@@ -157,36 +144,10 @@ public ClusterKey(
157144
public string ApplicationName { get { return _applicationName; } }
158145
public Action<ClusterBuilder> ClusterConfigurator { get { return _clusterConfigurator; } }
159146
public IReadOnlyList<CompressorConfiguration> Compressors { get { return _compressors; } }
160-
[Obsolete("Use DirectConnection instead.")]
161-
public ConnectionMode ConnectionMode
162-
{
163-
get
164-
{
165-
if (_connectionModeSwitch == ConnectionModeSwitch.UseDirectConnection)
166-
{
167-
throw new InvalidOperationException("ConnectionMode cannot be used when ConnectionModeSwitch is set to UseDirectConnection.");
168-
}
169-
return _connectionMode;
170-
}
171-
}
172-
[Obsolete("This property will be removed in a later release.")]
173-
public ConnectionModeSwitch ConnectionModeSwitch => _connectionModeSwitch;
174147
public TimeSpan ConnectTimeout { get { return _connectTimeout; } }
175148
public MongoCredential Credential { get { return _credential; } }
176149
public CryptClientSettings CryptClientSettings { get { return _cryptClientSettings; } }
177-
public bool? DirectConnection
178-
{
179-
get
180-
{
181-
#pragma warning disable CS0618 // Type or member is obsolete
182-
if (_connectionModeSwitch == ConnectionModeSwitch.UseConnectionMode)
183-
#pragma warning restore CS0618 // Type or member is obsolete
184-
{
185-
throw new InvalidOperationException("DirectConnection cannot be used when ConnectionModeSwitch is set to UseConnectionMode.");
186-
}
187-
return _directConnection;
188-
}
189-
}
150+
public bool DirectConnection { get { return _directConnection; } }
190151
public TimeSpan HeartbeatInterval { get { return _heartbeatInterval; } }
191152
public TimeSpan HeartbeatTimeout { get { return _heartbeatTimeout; } }
192153
public bool IPv6 { get { return _ipv6; } }
@@ -238,8 +199,6 @@ public override bool Equals(object obj)
238199
_applicationName == rhs._applicationName &&
239200
object.ReferenceEquals(_clusterConfigurator, rhs._clusterConfigurator) &&
240201
_compressors.SequenceEqual(rhs._compressors) &&
241-
_connectionMode == rhs._connectionMode &&
242-
_connectionModeSwitch == rhs._connectionModeSwitch &&
243202
_connectTimeout == rhs._connectTimeout &&
244203
_credential == rhs._credential &&
245204
object.Equals(_cryptClientSettings, rhs._cryptClientSettings) &&

src/MongoDB.Driver/ClusterRegistry.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,9 @@ private IClusterInternal CreateCluster(ClusterKey clusterKey)
8383

8484
private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey clusterKey)
8585
{
86-
#pragma warning disable CS0618 // Type or member is obsolete
8786
var endPoints = clusterKey.Servers.Select(s => EndPointHelper.Parse(s.ToString()));
88-
var connectionModeSwitch = clusterKey.ConnectionModeSwitch;
89-
Optional<ClusterConnectionMode> connectionMode = connectionModeSwitch == ConnectionModeSwitch.UseConnectionMode ? clusterKey.ConnectionMode.ToCore() : default;
90-
Optional<bool?> directConnection = connectionModeSwitch == ConnectionModeSwitch.UseDirectConnection ? clusterKey.DirectConnection : default;
9187
return settings.With(
92-
connectionMode: connectionMode,
93-
connectionModeSwitch: connectionModeSwitch,
94-
directConnection: directConnection,
88+
directConnection: clusterKey.DirectConnection,
9589
cryptClientSettings: clusterKey.CryptClientSettings,
9690
endPoints: Optional.Enumerable(endPoints),
9791
loadBalanced: clusterKey.LoadBalanced,
@@ -101,7 +95,6 @@ private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey cl
10195
serverApi: clusterKey.ServerApi,
10296
serverSelectionTimeout: clusterKey.ServerSelectionTimeout,
10397
scheme: clusterKey.Scheme);
104-
#pragma warning restore CS0618 // Type or member is obsolete
10598
}
10699

107100
private ConnectionPoolSettings ConfigureConnectionPool(ConnectionPoolSettings settings, ClusterKey clusterKey)

src/MongoDB.Driver/ConnectionMode.cs

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

src/MongoDB.Driver/ConnectionModeHelper.cs

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

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFact
7272
_rapidHeartbeatTimerCallbackState = new InterlockedInt32(RapidHeartbeatTimerCallbackState.NotRunning);
7373

7474
_clusterId = new ClusterId();
75-
_description = CreateInitialDescription();
75+
_description = ClusterDescription.CreateInitial(_clusterId, _settings.DirectConnection);
7676
_descriptionChangedTaskCompletionSource = new TaskCompletionSource<bool>();
7777
_latencyLimitingServerSelector = new LatencyLimitingServerSelector(settings.LocalThreshold);
7878

@@ -82,16 +82,6 @@ protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFact
8282

8383
_clusterEventLogger = loggerFactory.CreateEventLogger<LogCategories.SDAM>(eventSubscriber);
8484
_serverSelectionEventLogger = loggerFactory.CreateEventLogger<LogCategories.ServerSelection>(eventSubscriber);
85-
86-
ClusterDescription CreateInitialDescription()
87-
{
88-
#pragma warning disable CS0618 // Type or member is obsolete
89-
var connectionModeSwitch = _settings.ConnectionModeSwitch;
90-
var clusterConnectionMode = connectionModeSwitch == ConnectionModeSwitch.UseConnectionMode ? _settings.ConnectionMode : default;
91-
var directConnection = connectionModeSwitch == ConnectionModeSwitch.UseDirectConnection ? _settings.DirectConnection : default;
92-
return ClusterDescription.CreateInitial(_clusterId, clusterConnectionMode, _settings.ConnectionModeSwitch, directConnection);
93-
#pragma warning restore CS0618 // Type or member is obsolete
94-
}
9585
}
9686

9787
// events
@@ -142,20 +132,12 @@ protected virtual void Dispose(bool disposing)
142132
{
143133
_clusterEventLogger.Logger?.LogTrace(_clusterId, "Cluster disposing");
144134

145-
#pragma warning disable CS0618 // Type or member is obsolete
146-
var connectionModeSwitch = _description.ConnectionModeSwitch;
147-
var connectionMode = connectionModeSwitch == ConnectionModeSwitch.UseConnectionMode ? _description.ConnectionMode : default;
148-
var directConnection = connectionModeSwitch == ConnectionModeSwitch.UseDirectConnection ? _description.DirectConnection : default;
149-
150135
var newClusterDescription = new ClusterDescription(
151136
_clusterId,
152-
connectionMode,
153-
connectionModeSwitch,
154-
directConnection,
137+
_description.DirectConnection,
155138
dnsMonitorException: null,
156139
ClusterType.Unknown,
157140
Enumerable.Empty<ServerDescription>());
158-
#pragma warning restore CS0618 // Type or member is obsolete
159141

160142
UpdateClusterDescription(newClusterDescription);
161143

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

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

0 commit comments

Comments
 (0)