Skip to content

Commit 94a1feb

Browse files
CSHARP-3676: SRV support for load balancer mode + SDAM. (#562)
CSHARP-3676: SRV support for load balancer mode + SDAM.
1 parent a3e416f commit 94a1feb

File tree

227 files changed

+5268
-2013
lines changed

Some content is hidden

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

227 files changed

+5268
-2013
lines changed

build.cake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,38 @@ Task("TestGssapiNetStandard15").IsDependentOn("TestGssapi");
334334
Task("TestGssapiNetStandard20").IsDependentOn("TestGssapi");
335335
Task("TestGssapiNetStandard21").IsDependentOn("TestGssapi");
336336

337+
Task("TestLoadBalanced")
338+
.IsDependentOn("Build")
339+
.DoesForEach(
340+
GetFiles("./**/*.Tests.csproj"),
341+
testProject =>
342+
{
343+
var settings = new DotNetCoreTestSettings
344+
{
345+
NoBuild = true,
346+
NoRestore = true,
347+
Configuration = configuration,
348+
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
349+
Filter = "Category=\"SupportLoadBalancing\""
350+
};
351+
352+
switch (target.ToLowerInvariant())
353+
{
354+
case "testloadbalancednetstandard15": settings.Framework = "netcoreapp1.1"; break;
355+
case "testloadbalancednetstandard20": settings.Framework = "netcoreapp2.1"; break;
356+
case "testloadbalancednetstandard21": settings.Framework = "netcoreapp3.0"; break;
357+
}
358+
359+
DotNetCoreTest(
360+
testProject.FullPath,
361+
settings
362+
);
363+
});
364+
365+
Task("TestLoadBalancedNetStandard15").IsDependentOn("TestLoadBalanced");
366+
Task("TestLoadBalancedNetStandard20").IsDependentOn("TestLoadBalanced");
367+
Task("TestLoadBalancedNetStandard21").IsDependentOn("TestLoadBalanced");
368+
337369
Task("Docs")
338370
.IsDependentOn("ApiDocs")
339371
.IsDependentOn("RefDocs");

evergreen/evergreen.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,37 @@ functions:
242242
DRIVERS_TOOLS="${DRIVERS_TOOLS}" \
243243
sh ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake/run-mongohouse-local.sh
244244
245+
run-load-balancer:
246+
- command: shell.exec
247+
params:
248+
script: |
249+
DRIVERS_TOOLS=${DRIVERS_TOOLS} MONGODB_URI=${MONGODB_URI} bash ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh start
250+
- command: expansions.update
251+
params:
252+
file: lb-expansion.yml
253+
254+
run-load-balancer-tests:
255+
- command: shell.exec
256+
type: test
257+
params:
258+
working_dir: "mongo-csharp-driver"
259+
script: |
260+
${PREPARE_SHELL}
261+
SSL=${SSL} OS=${OS} evergreen/add-certs-if-needed.sh
262+
AUTH="${AUTH}" SSL="${SSL}" \
263+
FRAMEWORK=${FRAMEWORK} \
264+
OS=${OS} \
265+
SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}" \
266+
MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \
267+
evergreen/run-load-balancer-tests.sh
268+
269+
stop-load-balancer:
270+
- command: shell.exec
271+
params:
272+
script: |
273+
cd ${DRIVERS_TOOLS}/.evergreen
274+
DRIVERS_TOOLS=${DRIVERS_TOOLS} MONGODB_URI=${MONGODB_URI} bash ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh stop
275+
245276
run-tests:
246277
- command: shell.exec
247278
type: test
@@ -678,6 +709,33 @@ tasks:
678709
vars:
679710
FRAMEWORK: netstandard21
680711

712+
- name: test-load-balancer-netstandard15
713+
commands:
714+
- func: bootstrap-mongo-orchestration
715+
- func: run-load-balancer
716+
- func: run-load-balancer-tests
717+
- func: stop-load-balancer
718+
vars:
719+
FRAMEWORK: netstandard15
720+
721+
- name: test-load-balancer-netstandard20
722+
commands:
723+
- func: bootstrap-mongo-orchestration
724+
- func: run-load-balancer
725+
- func: run-load-balancer-tests
726+
- func: stop-load-balancer
727+
vars:
728+
FRAMEWORK: netstandard20
729+
730+
- name: test-load-balancer-netstandard21
731+
commands:
732+
- func: bootstrap-mongo-orchestration
733+
- func: run-load-balancer
734+
- func: run-load-balancer-tests
735+
- func: stop-load-balancer
736+
vars:
737+
FRAMEWORK: netstandard21
738+
681739
- name: atlas-connectivity-tests
682740
commands:
683741
- func: run-atlas-connectivity-tests
@@ -1327,6 +1385,22 @@ buildvariants:
13271385
tasks:
13281386
- name: plain-auth-tests
13291387

1388+
- matrix_name: tests-load-balancer
1389+
matrix_spec: { version: ["5.0", "latest"], auth: "noauth", ssl: "nossl", topology: "sharded-cluster", os: "ubuntu-1804" }
1390+
display_name: "Load Balancer ${version} ${auth} ${ssl} ${os}"
1391+
tasks:
1392+
- name: "test-load-balancer-netstandard15"
1393+
- name: "test-load-balancer-netstandard20"
1394+
- name: "test-load-balancer-netstandard21"
1395+
1396+
- matrix_name: tests-load-balancer-secure
1397+
matrix_spec: { version: ["5.0", "latest"], auth: "auth", ssl: "ssl", topology: "sharded-cluster", os: "ubuntu-1804" }
1398+
display_name: "Load Balancer ${version} ${auth} ${ssl} ${os}"
1399+
tasks:
1400+
- name: "test-load-balancer-netstandard15"
1401+
- name: "test-load-balancer-netstandard20"
1402+
- name: "test-load-balancer-netstandard21"
1403+
13301404
- name: atlas-connectivity-tests
13311405
display_name: "Atlas Connectivity Tests"
13321406
run_on:

evergreen/run-load-balancer-tests.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -o xtrace # Write all commands first to stderr
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
# Supported/used environment variables:
7+
# SSL Set to enable SSL. Values are "ssl" / "nossl" (default)
8+
# OS Set to current operating system
9+
# FRAMEWORK Set to .net framework
10+
# SINGLE_MONGOS_LB_URI Set the URI pointing to a load balancer configured with a single mongos server
11+
# MULTI_MONGOS_LB_URI Set the URI pointing to a load balancer configured with multiple mongos servers
12+
13+
SSL=${SSL:-nossl}
14+
15+
############################################
16+
# Main Program #
17+
############################################
18+
19+
if [[ ! "$OS" =~ Ubuntu|ubuntu ]]; then
20+
echo "Unsupported OS:${OS}" 1>&2 # write to stderr
21+
exit 1
22+
fi
23+
24+
25+
if [ "$SSL" != "nossl" ]; then
26+
SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}&ssl=true&tlsDisableCertificateRevocationCheck=true"
27+
MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}&ssl=true&tlsDisableCertificateRevocationCheck=true"
28+
fi
29+
30+
echo "Running $AUTH tests (${FRAMEWORK}) over $SSL and connecting to SINGLE_MONGOS_LB_URI: $SINGLE_MONGOS_LB_URI or MULTI_MONGOS_LB_URI: $MULTI_MONGOS_LB_URI"
31+
32+
export MONGODB_URI=${SINGLE_MONGOS_LB_URI}
33+
export MONGODB_URI_WITH_MULTIPLE_MONGOSES=${MULTI_MONGOS_LB_URI}
34+
35+
# show test output
36+
set -x
37+
38+
./build.sh --target TestLoadBalanced${FRAMEWORK}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,22 @@ public void ReleaseSession(ICoreServerSession session)
9595
private bool IsAboutToExpire(ICoreServerSession session)
9696
{
9797
var logicalSessionTimeout = _cluster.Description.LogicalSessionTimeout;
98-
if (!session.LastUsedAt.HasValue || !logicalSessionTimeout.HasValue)
98+
var clusterType = _cluster.Description.Type;
99+
100+
if (clusterType == ClusterType.LoadBalanced)
99101
{
100-
return true;
102+
return false; // sessions never expire in load balancing mode
101103
}
102-
else
104+
else if (session.LastUsedAt.HasValue && logicalSessionTimeout.HasValue)
103105
{
104106
var expiresAt = session.LastUsedAt.Value + logicalSessionTimeout.Value;
105107
var timeRemaining = expiresAt - DateTime.UtcNow;
106108
return timeRemaining < TimeSpan.FromMinutes(1);
107109
}
110+
else
111+
{
112+
return true;
113+
}
108114
}
109115

110116
private bool IsAboutToExpireOrDirty(ICoreServerSession session)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ internal abstract class Cluster : ICluster
8787
protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IEventSubscriber eventSubscriber)
8888
{
8989
_settings = Ensure.IsNotNull(settings, nameof(settings));
90+
Ensure.That(!_settings.LoadBalanced, "LoadBalanced mode is not supported.");
9091
_serverFactory = Ensure.IsNotNull(serverFactory, nameof(serverFactory));
9192
Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));
9293
_state = new InterlockedInt32(State.Initial);
@@ -155,7 +156,7 @@ public ICoreServerSession AcquireServerSession()
155156

156157
protected IClusterableServer CreateServer(EndPoint endPoint)
157158
{
158-
return _serverFactory.CreateServer(_clusterId, _clusterClock, endPoint);
159+
return _serverFactory.CreateServer(_settings.GetInitialClusterType(), _clusterId, _clusterClock, endPoint);
159160
}
160161

161162
public void Dispose()

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public ICluster CreateCluster()
4040
{
4141
var settings = _settings;
4242

43+
bool createLoadBalancedCluster = settings.LoadBalanced;
44+
if (createLoadBalancedCluster)
45+
{
46+
return CreateLoadBalancedCluster(settings);
47+
}
48+
4349
bool createSingleServerCluster;
4450
#pragma warning disable CS0618 // Type or member is obsolete
4551
if (settings.ConnectionModeSwitch == ConnectionModeSwitch.UseDirectConnection)
@@ -88,5 +94,10 @@ private SingleServerCluster CreateSingleServerCluster(ClusterSettings settings)
8894
{
8995
return new SingleServerCluster(settings, _serverFactory, _eventSubscriber);
9096
}
97+
98+
private LoadBalancedCluster CreateLoadBalancedCluster(ClusterSettings setting)
99+
{
100+
return new LoadBalancedCluster(setting, _serverFactory, _eventSubscriber);
101+
}
91102
}
92103
}

0 commit comments

Comments
 (0)