Skip to content

Commit c90981e

Browse files
authored
CDRIVER-4048 support loadBalanced URI option (#808)
- Resyncs the URI options tests and the initial DNS seedlist discovery tests - Add the loadBalanced URI option - Validates the loadBalanced URI option after TXT records are applied - Disable SRV polling if loadBalanced is enabled - Add prose test to ensure SRV polling is disabled - Consolidates DNS related tests under /initial_dns_seedlist_discovery/
1 parent 3a6f54e commit c90981e

Some content is hidden

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

53 files changed

+731
-90
lines changed

.evergreen/config.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,41 @@ functions:
754754
export IAM_AUTH_ECS_ACCOUNT=${iam_auth_ecs_account}
755755
export IAM_AUTH_ECS_SECRET_ACCESS_KEY=${iam_auth_ecs_secret_access_key}
756756
sh ./.evergreen/run-aws-tests.sh ${TESTCASE}
757+
clone drivers-evergreen-tools:
758+
- command: shell.exec
759+
params:
760+
shell: bash
761+
script: |-
762+
set -o errexit
763+
if [ ! -d "drivers-evergreen-tools" ]; then
764+
git clone [email protected]:mongodb-labs/drivers-evergreen-tools.git --depth=1
765+
fi
766+
start load balancer:
767+
- command: shell.exec
768+
params:
769+
shell: bash
770+
script: |-
771+
set -o errexit
772+
export DRIVERS_TOOLS=./drivers-evergreen-tools
773+
export MONGODB_URI="${MONGODB_URI}"
774+
bash $DRIVERS_TOOLS/.evergreen/run-load-balancer.sh start
775+
- command: expansions.update
776+
params:
777+
file: lb-expansion.yml
778+
stop load balancer:
779+
- command: shell.exec
780+
params:
781+
shell: bash
782+
script: |-
783+
set -o errexit
784+
# Only run if a load balancer was started.
785+
if [ -z "${SINGLE_MONGOS_LB_URI}" ]; then
786+
echo "OK - no load balancer running"
787+
exit 0
788+
fi
789+
export DRIVERS_TOOLS=./drivers-evergreen-tools
790+
export MONGODB_URI="foo" # TODO: DRIVERS-1833 remove this.
791+
$DRIVERS_TOOLS/.evergreen/run-load-balancer.sh stop
757792
pre:
758793
- func: fetch source
759794
- func: windows fix
@@ -765,6 +800,7 @@ post:
765800
- func: upload mo artifacts
766801
- func: upload test results
767802
- func: cleanup
803+
- func: stop load balancer
768804
timeout:
769805
- func: backtrace
770806
tasks:
@@ -19123,6 +19159,28 @@ tasks:
1912319159
AUTH: noauth
1912419160
DNS: 'on'
1912519161
SSL: ssl
19162+
- name: test-dns-loadbalanced-openssl
19163+
depends_on:
19164+
name: debug-compile-sasl-openssl
19165+
commands:
19166+
- func: fetch build
19167+
vars:
19168+
BUILD_NAME: debug-compile-sasl-openssl
19169+
- func: bootstrap mongo-orchestration
19170+
vars:
19171+
AUTH: noauth
19172+
SSL: ssl
19173+
TOPOLOGY: sharded_cluster
19174+
VERSION: latest
19175+
- func: clone drivers-evergreen-tools
19176+
- func: start load balancer
19177+
vars:
19178+
MONGODB_URI: mongodb://localhost:27017,localhost:27018
19179+
- func: run tests
19180+
vars:
19181+
AUTH: noauth
19182+
DNS: loadbalanced
19183+
SSL: ssl
1912619184
- name: test-dns-auth-openssl
1912719185
depends_on:
1912819186
name: debug-compile-sasl-openssl
@@ -26840,6 +26898,7 @@ buildvariants:
2684026898
- .4.0 .openssl !.nosasl .server
2684126899
- test-dns-openssl
2684226900
- test-dns-auth-openssl
26901+
- test-dns-loadbalanced-openssl
2684326902
- name: gcc54
2684426903
display_name: GCC 5.4 (Ubuntu 16.04)
2684526904
expansions:

.evergreen/run-tests.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ if [ "$IPV4_ONLY" != "on" ]; then
4949
export MONGOC_CHECK_IPV6="on"
5050
fi
5151

52-
if [ "$DNS" = "dns-auth" ]; then
53-
export MONGOC_TEST_DNS=on
54-
TEST_ARGS="$TEST_ARGS -l /initial_dns_auth/*"
55-
elif [ "$DNS" != "nodns" ]; then
56-
export MONGOC_TEST_DNS=on
57-
TEST_ARGS="$TEST_ARGS -l /initial_dns_seedlist_discovery*"
52+
# TODO (CDRIVER-4045): consolidate DNS tests into regular test tasks.
53+
if [ "$DNS" != "nodns" ]; then
54+
TEST_ARGS="$TEST_ARGS -l /initial_dns_seedlist_discovery/*"
55+
if [ "$DNS" = "loadbalanced" ]; then
56+
export MONGOC_TEST_DNS_LOADBALANCED=on
57+
else
58+
export MONGOC_TEST_DNS=on
59+
fi
5860
fi
5961

6062
if [ "$CC" = "mingw" ]; then

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Makefile
2121
test-results.json
2222
VERSION_CURRENT
2323
VERSION_RELEASED
24+
*.pyc
2425

2526
# Windows things
2627
*.sdf

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ The tests for mongodb+srv:// connection strings require some setup, see the
215215
Initial DNS Seedlist Discovery Spec. By default these connection strings are
216216
NOT tested, enable them with:
217217

218-
* `MONGOC_TEST_DNS=on`
218+
* `MONGOC_TEST_DNS=on` assumes a replica set is running with TLS enabled on ports 27017, 27018, and 27019.
219+
220+
* `MONGOC_TEST_DNS_LOADBALANCED=on` assumes a load balanced sharded cluster is running with mongoses on ports 27017 and 27018 and TLS enabled. The load balancer can be listening on any port.
219221

220222
The mock server timeout threshold for future functions can be set with:
221223

build/evergreen_config_lib/functions.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,5 +543,35 @@
543543
export IAM_AUTH_ECS_SECRET_ACCESS_KEY=${iam_auth_ecs_secret_access_key}
544544
sh ./.evergreen/run-aws-tests.sh ${TESTCASE}
545545
''')
546-
))
546+
)),
547+
('clone drivers-evergreen-tools', Function(
548+
shell_exec(r'''
549+
if [ ! -d "drivers-evergreen-tools" ]; then
550+
git clone [email protected]:mongodb-labs/drivers-evergreen-tools.git --depth=1
551+
fi
552+
''', test=False)
553+
)),
554+
('start load balancer', Function(
555+
shell_exec(r'''
556+
export DRIVERS_TOOLS=./drivers-evergreen-tools
557+
export MONGODB_URI="${MONGODB_URI}"
558+
bash $DRIVERS_TOOLS/.evergreen/run-load-balancer.sh start
559+
''', test=False),
560+
OD ([
561+
("command", "expansions.update"),
562+
("params", OD([("file", "lb-expansion.yml")]))
563+
]),
564+
)),
565+
('stop load balancer', Function(
566+
shell_exec(r'''
567+
# Only run if a load balancer was started.
568+
if [ -z "${SINGLE_MONGOS_LB_URI}" ]; then
569+
echo "OK - no load balancer running"
570+
exit 0
571+
fi
572+
export DRIVERS_TOOLS=./drivers-evergreen-tools
573+
export MONGODB_URI="foo" # TODO: DRIVERS-1833 remove this.
574+
$DRIVERS_TOOLS/.evergreen/run-load-balancer.sh stop
575+
''', test=False),
576+
)),
547577
])

build/evergreen_config_lib/tasks.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,9 @@ def _check_allowed(self):
626626

627627
class DNSTask(MatrixTask):
628628
axes = OD([('auth', [False, True]),
629-
('ssl', ['openssl', 'winssl', 'darwinssl'])])
629+
('loadbalanced', [False, True]),
630+
('ssl', ['openssl', 'winssl', 'darwinssl'])
631+
])
630632

631633
name_prefix = 'test-dns'
632634

@@ -648,20 +650,33 @@ def to_dict(self):
648650
commands.append(
649651
func('fetch build', BUILD_NAME=self.depends_on['name']))
650652

651-
orchestration = bootstrap(TOPOLOGY='replica_set',
653+
orchestration = bootstrap(TOPOLOGY='sharded_cluster' if self.loadbalanced else 'replica_set',
652654
AUTH='auth' if self.auth else 'noauth',
653655
SSL='ssl')
654656

655657
if self.auth:
656658
orchestration['vars']['AUTHSOURCE'] = 'thisDB'
657659

658660
commands.append(orchestration)
661+
662+
dns = 'on'
663+
if self.loadbalanced:
664+
dns = 'loadbalanced'
665+
commands.append (func("clone drivers-evergreen-tools"))
666+
commands.append (func("start load balancer", MONGODB_URI="mongodb://localhost:27017,localhost:27018"))
667+
elif self.auth:
668+
dns = 'dns-auth'
659669
commands.append(run_tests(SSL='ssl',
660670
AUTH=self.display('auth'),
661-
DNS='dns-auth' if self.auth else 'on'))
671+
DNS=dns))
662672

663673
return task
664674

675+
def _check_allowed(self):
676+
prohibit (self.loadbalanced and self.auth)
677+
# Load balancer tests only run on some Linux hosts in Evergreen until CDRIVER-4041 is resolved.
678+
prohibit (self.loadbalanced and self.ssl in ["darwinssl", "winssl"])
679+
665680

666681
all_tasks = chain(all_tasks, DNSTask.matrix())
667682

build/evergreen_config_lib/variants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ def days(n):
325325
'.4.2 .openssl !.nosasl .server',
326326
'.4.0 .openssl !.nosasl .server',
327327
'test-dns-openssl',
328-
'test-dns-auth-openssl'
328+
'test-dns-auth-openssl',
329+
'test-dns-loadbalanced-openssl'
329330
],
330331
{'CC': 'gcc'}),
331332
Variant('gcc54',

build/generate-evergreen-config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
OD([('func', 'upload mo artifacts')]),
6161
OD([('func', 'upload test results')]),
6262
OD([('func', 'cleanup')]),
63+
OD([('func', 'stop load balancer')]),
6364
]),
6465
('timeout', [
6566
OD([('func', 'backtrace')])

src/libmongoc/doc/mongoc_uri_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ MONGOC_URI_SOCKETTIMEOUTMS sockettimeoutms 300
101101
MONGOC_URI_TIMEOUTMS timeoutms Empty (no timeout) The time limit for the full execution of an operation.
102102
MONGOC_URI_REPLICASET replicaset Empty (no replicaset) The name of the Replica Set that the driver should connect to.
103103
MONGOC_URI_ZLIBCOMPRESSIONLEVEL zlibcompressionlevel -1 When the MONGOC_URI_COMPRESSORS includes "zlib" this options configures the zlib compression level, when the zlib compressor is used to compress client data.
104+
MONGOC_URI_LOADBALANCED loadbalanced false If true, this indicates the driver is connecting to a MongoDB cluster behind a load balancer.
104105
========================================== ================================= ================================= ============================================================================================================================================================================================================================================
105106

106107
Setting any of the \*timeoutMS options above to ``0`` will be interpreted as "use the default value".

src/libmongoc/src/mongoc/mongoc-client-private.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,10 @@ typedef enum {
148148
BSON_STATIC_ASSERT2 (mongoc_cmd_rw,
149149
MONGOC_CMD_RW == (MONGOC_CMD_READ | MONGOC_CMD_WRITE));
150150

151-
typedef enum { MONGOC_RR_SRV, MONGOC_RR_TXT } mongoc_rr_type_t;
152-
153-
typedef struct _mongoc_rr_data_t {
154-
/* Number of records returned by DNS. */
155-
uint32_t count;
156-
157-
/* Set to lowest TTL found when polling SRV records. */
158-
uint32_t min_ttl;
159-
160-
/* Set to the resulting host list when polling SRV records */
161-
mongoc_host_list_t *hosts;
162-
163-
/* Set to the TXT record when polling for TXT */
164-
char *txt_record_opts;
165-
} mongoc_rr_data_t;
166151

152+
/* TODO (CDRIVER-4052): Move MONGOC_RR_DEFAULT_BUFFER_SIZE and _mongoc_client_get_rr to
153+
* mongoc-topology-private.h or in a separate file. There is no reason these
154+
* should be in mongoc-client. */
167155
#define MONGOC_RR_DEFAULT_BUFFER_SIZE 1024
168156
bool
169157
_mongoc_client_get_rr (const char *service,

src/libmongoc/src/mongoc/mongoc-topology-private.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ typedef enum {
4646
struct _mongoc_background_monitor_t;
4747
struct _mongoc_client_pool_t;
4848

49+
typedef enum { MONGOC_RR_SRV, MONGOC_RR_TXT } mongoc_rr_type_t;
50+
51+
typedef struct _mongoc_rr_data_t {
52+
/* Number of records returned by DNS. */
53+
uint32_t count;
54+
55+
/* Set to lowest TTL found when polling SRV records. */
56+
uint32_t min_ttl;
57+
58+
/* Set to the resulting host list when polling SRV records */
59+
mongoc_host_list_t *hosts;
60+
61+
/* Set to the TXT record when polling for TXT */
62+
char *txt_record_opts;
63+
} mongoc_rr_data_t;
64+
65+
typedef bool (*_mongoc_rr_resolver_fn) (const char *service,
66+
mongoc_rr_type_t rr_type,
67+
mongoc_rr_data_t *rr_data,
68+
size_t initial_buffer_size,
69+
bson_error_t *error);
70+
4971
typedef struct _mongoc_topology_t {
5072
mongoc_topology_description_t description;
5173
/* topology->uri is initialized as a copy of the client/pool's URI.
@@ -104,6 +126,9 @@ typedef struct _mongoc_topology_t {
104126
mongoc_set_t *server_monitors;
105127
mongoc_set_t *rtt_monitors;
106128
bson_mutex_t apm_mutex;
129+
130+
/* This is overridable for SRV polling tests to mock DNS records. */
131+
_mongoc_rr_resolver_fn rr_resolver;
107132
} mongoc_topology_t;
108133

109134
mongoc_topology_t *
@@ -229,4 +254,24 @@ mongoc_topology_rescan_srv (mongoc_topology_t *topology);
229254

230255
bool
231256
mongoc_topology_should_rescan_srv (mongoc_topology_t *topology);
257+
258+
/* _mongoc_topology_set_rr_resolver is called by tests to mock DNS responses for
259+
* SRV polling.
260+
* This is necessarily called after initial seedlist discovery completes in
261+
* mongoc_topology_new.
262+
* Callers should call this before monitoring starts.
263+
* Callers must lock topology->mutex.
264+
*/
265+
void
266+
_mongoc_topology_set_rr_resolver (mongoc_topology_t *topology,
267+
_mongoc_rr_resolver_fn rr_resolver);
268+
269+
/* _mongoc_topology_set_srv_polling_rescan_interval_ms is called by tests to
270+
* shorten the rescan interval.
271+
* Callers should call this before monitoring starts.
272+
* Callers must lock topology->mutex.
273+
*/
274+
void
275+
_mongoc_topology_set_srv_polling_rescan_interval_ms (
276+
mongoc_topology_t *topology, int64_t val);
232277
#endif

0 commit comments

Comments
 (0)