-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-3625 monitor with a thread-per-server #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ case "$OS" in | |
check_mongocryptd | ||
|
||
chmod +x src/libmongoc/Debug/test-libmongoc.exe | ||
./src/libmongoc/Debug/test-libmongoc.exe $TEST_ARGS | ||
./src/libmongoc/Debug/test-libmongoc.exe $TEST_ARGS -d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried putting --no-fork here, but then stumbled on an existing bug: https://jira.mongodb.org/browse/CDRIVER-3637 |
||
;; | ||
|
||
*) | ||
|
@@ -104,9 +104,9 @@ case "$OS" in | |
|
||
if [ "$VALGRIND" = "on" ]; then | ||
. $DIR/valgrind.sh | ||
run_valgrind ./src/libmongoc/test-libmongoc --no-fork $TEST_ARGS | ||
run_valgrind ./src/libmongoc/test-libmongoc --no-fork $TEST_ARGS -d | ||
else | ||
./src/libmongoc/test-libmongoc --no-fork $TEST_ARGS | ||
./src/libmongoc/test-libmongoc --no-fork $TEST_ARGS -d | ||
fi | ||
|
||
;; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -560,7 +560,7 @@ _mongoc_get_rr_search (const char *service, | |
* | ||
* Fetch an SRV or TXT resource record and update put results in | ||
* @rr_data. | ||
* | ||
* | ||
* See RFCs 1464 and 2782, MongoDB's "Initial DNS Seedlist Discovery" | ||
* spec, and MongoDB's "Polling SRV Records for Mongos Discovery" | ||
* spec. | ||
|
@@ -644,10 +644,12 @@ mongoc_client_connect_tcp (int32_t connecttimeoutms, | |
hints.ai_flags = 0; | ||
hints.ai_protocol = 0; | ||
|
||
TRACE ("DNS lookup for %s", host->host); | ||
s = getaddrinfo (host->host, portstr, &hints, &result); | ||
|
||
if (s != 0) { | ||
mongoc_counter_dns_failure_inc (); | ||
TRACE ("Failed to resolve %s", host->host); | ||
bson_set_error (error, | ||
MONGOC_ERROR_STREAM, | ||
MONGOC_ERROR_STREAM_NAME_RESOLUTION, | ||
|
@@ -764,49 +766,26 @@ mongoc_client_connect_unix (const mongoc_host_list_t *host, bson_error_t *error) | |
#endif | ||
} | ||
|
||
|
||
/* | ||
*-------------------------------------------------------------------------- | ||
* | ||
* mongoc_client_default_stream_initiator -- | ||
* | ||
* A mongoc_stream_initiator_t that will handle the various type | ||
* of supported sockets by MongoDB including TCP and UNIX. | ||
* | ||
* Language binding authors may want to implement an alternate | ||
* version of this method to use their native stream format. | ||
* | ||
* Returns: | ||
* A mongoc_stream_t if successful; otherwise NULL and @error is set. | ||
* | ||
* Side effects: | ||
* @error is set if return value is NULL. | ||
* | ||
*-------------------------------------------------------------------------- | ||
*/ | ||
|
||
mongoc_stream_t * | ||
mongoc_client_default_stream_initiator (const mongoc_uri_t *uri, | ||
const mongoc_host_list_t *host, | ||
void *user_data, | ||
bson_error_t *error) | ||
mongoc_client_connect (bool buffered, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The server monitors do not have a mongoc_client_t, but need to create a stream to a server given just a host address. mongoc_client_connect establishes connection with just the address and SSL options, and is used by mongoc_client_default_stream_initiator, which takes the SSL options from a mongoc_client_t. |
||
bool use_ssl, | ||
void *ssl_opts_void, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sidenote: I found it frustrating to work with mongoc_ssl_opt_t. Since it is conditionally defined, using it requires either hiding the type or using typedefs. |
||
const mongoc_uri_t *uri, | ||
const mongoc_host_list_t *host, | ||
bson_error_t *error) | ||
{ | ||
mongoc_stream_t *base_stream = NULL; | ||
int32_t connecttimeoutms; | ||
#ifdef MONGOC_ENABLE_SSL | ||
mongoc_client_t *client = (mongoc_client_t *) user_data; | ||
const char *mechanism; | ||
#endif | ||
|
||
BSON_ASSERT (uri); | ||
BSON_ASSERT (host); | ||
|
||
#ifndef MONGOC_ENABLE_SSL | ||
if (mongoc_uri_get_tls (uri)) { | ||
if (ssl_opts_void || mongoc_uri_get_tls (uri)) { | ||
bson_set_error (error, | ||
MONGOC_ERROR_CLIENT, | ||
MONGOC_ERROR_CLIENT_NO_ACCEPTABLE_PEER, | ||
"SSL is not enabled in this build of mongo-c-driver."); | ||
"TLS is not enabled in this build of mongo-c-driver."); | ||
return NULL; | ||
} | ||
#endif | ||
|
@@ -836,14 +815,17 @@ mongoc_client_default_stream_initiator (const mongoc_uri_t *uri, | |
|
||
#ifdef MONGOC_ENABLE_SSL | ||
if (base_stream) { | ||
mongoc_ssl_opt_t *ssl_opts; | ||
const char *mechanism; | ||
|
||
ssl_opts = (mongoc_ssl_opt_t *) ssl_opts_void; | ||
mechanism = mongoc_uri_get_auth_mechanism (uri); | ||
|
||
if (client->use_ssl || | ||
(mechanism && (0 == strcmp (mechanism, "MONGODB-X509")))) { | ||
if (use_ssl || (mechanism && (0 == strcmp (mechanism, "MONGODB-X509")))) { | ||
mongoc_stream_t *original = base_stream; | ||
|
||
base_stream = mongoc_stream_tls_new_with_hostname ( | ||
base_stream, host->host, &client->ssl_opts, true); | ||
base_stream, host->host, ssl_opts, true); | ||
|
||
if (!base_stream) { | ||
mongoc_stream_destroy (original); | ||
|
@@ -863,9 +845,54 @@ mongoc_client_default_stream_initiator (const mongoc_uri_t *uri, | |
} | ||
#endif | ||
|
||
return base_stream ? mongoc_stream_buffered_new (base_stream, 1024) : NULL; | ||
if (!base_stream) { | ||
return NULL; | ||
} | ||
if (buffered) { | ||
return mongoc_stream_buffered_new (base_stream, 1024); | ||
} | ||
return base_stream; | ||
} | ||
|
||
/* | ||
*-------------------------------------------------------------------------- | ||
* | ||
* mongoc_client_default_stream_initiator -- | ||
* | ||
* A mongoc_stream_initiator_t that will handle the various type | ||
* of supported sockets by MongoDB including TCP and UNIX. | ||
* | ||
* Language binding authors may want to implement an alternate | ||
* version of this method to use their native stream format. | ||
* | ||
* Returns: | ||
* A mongoc_stream_t if successful; otherwise NULL and @error is set. | ||
* | ||
* Side effects: | ||
* @error is set if return value is NULL. | ||
* | ||
*-------------------------------------------------------------------------- | ||
*/ | ||
|
||
mongoc_stream_t * | ||
mongoc_client_default_stream_initiator (const mongoc_uri_t *uri, | ||
const mongoc_host_list_t *host, | ||
void *user_data, | ||
bson_error_t *error) | ||
{ | ||
void *ssl_opts_void = NULL; | ||
bool use_ssl = false; | ||
#ifdef MONGOC_ENABLE_SSL | ||
mongoc_client_t *client = (mongoc_client_t *) user_data; | ||
|
||
use_ssl = client->use_ssl; | ||
ssl_opts_void = (void *) &client->ssl_opts; | ||
|
||
#endif | ||
|
||
return mongoc_client_connect ( | ||
true, use_ssl, ssl_opts_void, uri, host, error); | ||
} | ||
|
||
/* | ||
*-------------------------------------------------------------------------- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
/* | ||
* Copyright 2020-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "mongoc-prelude.h" | ||
|
||
#ifndef MONGOC_TOPOLOGY_BACKGROUND_MONITORING_PRIVATE_H | ||
#define MONGOC_TOPOLOGY_BACKGROUND_MONITORING_PRIVATE_H | ||
|
||
/* Methods of mongoc_topology_t for managing background monitoring. */ | ||
|
||
struct _mongoc_topology_t; | ||
|
||
void | ||
_mongoc_topology_background_monitoring_start ( | ||
struct _mongoc_topology_t *topology); | ||
|
||
void | ||
_mongoc_topology_background_monitoring_reconcile ( | ||
struct _mongoc_topology_t *topology); | ||
|
||
void | ||
_mongoc_topology_background_monitoring_request_scan ( | ||
struct _mongoc_topology_t *topology); | ||
|
||
void | ||
_mongoc_topology_background_monitoring_stop ( | ||
struct _mongoc_topology_t *topology); | ||
|
||
#endif /* MONGOC_TOPOLOGY_BACKGROUND_MONITORING_PRIVATE_H */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lets debug logs to print to stdout. There's likely a better way to
accomplish that. But the only downside of running with --no-fork I'm aware of is
that the first test failure fails the entire process. That did not seem like a
big loss to me. Though, I'm happy to change back and look for alternatives if
there's disagreement