Skip to content

Commit 83f9d8f

Browse files
committed
update comments; format
1 parent 79304fd commit 83f9d8f

File tree

6 files changed

+49
-35
lines changed

6 files changed

+49
-35
lines changed

src/libmongoc/src/mongoc/mongoc-topology-description-apm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ _mongoc_topology_description_monitor_opening (mongoc_topology_description_t *td)
125125
if (td->type == MONGOC_TOPOLOGY_LOAD_BALANCED) {
126126
mongoc_server_description_t *prev_sd;
127127

128-
/* LoadBalanced deployments must have exactly one host listed. */
128+
/* LoadBalanced deployments must have exactly one host listed. Otherwise,
129+
* an error would have occurred when constructing the topology. */
129130
BSON_ASSERT (td->servers->items_len == 1);
130-
sd = (mongoc_server_description_t *) mongoc_set_get_item (td->servers,
131-
(int) 0);
131+
sd = (mongoc_server_description_t *) mongoc_set_get_item (td->servers, 0);
132132
prev_sd = mongoc_server_description_new_copy (sd);
133133
if (td->apm_callbacks.topology_changed) {
134134
mongoc_topology_description_destroy (prev_td);

src/libmongoc/src/mongoc/mongoc-topology-scanner.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,10 +1136,6 @@ mongoc_topology_scanner_start (mongoc_topology_scanner_t *ts,
11361136
skip =
11371137
obey_cooldown && mongoc_topology_scanner_node_in_cooldown (node, now);
11381138

1139-
if (skip) {
1140-
MONGOC_DEBUG ("skipping node: %s due to cooldown", node->host.host_and_port);
1141-
}
1142-
11431139
if (!skip) {
11441140
mongoc_topology_scanner_node_setup (node, &node->last_error);
11451141
}

src/libmongoc/src/mongoc/mongoc-topology.c

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,12 @@ _mongoc_topology_scanner_cb (uint32_t id,
174174
topology = (mongoc_topology_t *) data;
175175

176176
if (topology->description.type == MONGOC_TOPOLOGY_LOAD_BALANCED) {
177-
/* In load balanced mode, scanning is only for connection establishment. It must not modify the topology description. */
178-
MONGOC_DEBUG ("Ignoring hello response in callback in load balanced mode");
177+
/* In load balanced mode, scanning is only for connection establishment.
178+
* It must not modify the topology description. */
179179
return;
180180
}
181181

182182
bson_mutex_lock (&topology->mutex);
183-
184183
sd = mongoc_topology_description_server_by_id (
185184
&topology->description, id, NULL);
186185

@@ -432,6 +431,12 @@ mongoc_topology_new (const mongoc_uri_t *uri, bool single_threaded)
432431
topology->uri, MONGOC_URI_LOADBALANCED, false)) {
433432
init_type = MONGOC_TOPOLOGY_LOAD_BALANCED;
434433
if (topology->single_threaded) {
434+
/* Cooldown only applies to server monitoring for single-threaded
435+
* clients. In load balanced mode, the topology scanner is used to
436+
* create connections. The cooldown period does not apply. A network
437+
* error to a load balanced connection does not imply subsequent
438+
* connection attempts will be to the same server and that a delay
439+
* should occur. */
435440
_mongoc_topology_bypass_cooldown (topology);
436441
}
437442
} else if (service && !has_directconnection) {
@@ -961,9 +966,10 @@ mongoc_topology_select (mongoc_topology_t *topology,
961966
}
962967
}
963968

964-
/* Bypasses normal server selection behavior for a load balanced topology. Returns the id of the one load balancer server. Returns 0 on failure.
965-
* Successful post-condition: On a single threaded client, a connection will have been established.
966-
*/
969+
/* Bypasses normal server selection behavior for a load balanced topology.
970+
* Returns the id of the one load balancer server. Returns 0 on failure.
971+
* Successful post-condition: On a single threaded client, a connection will
972+
* have been established. */
967973
static uint32_t
968974
_mongoc_topology_select_server_id_loadbalanced (mongoc_topology_t *topology,
969975
bson_error_t *error)
@@ -999,32 +1005,42 @@ _mongoc_topology_select_server_id_loadbalanced (mongoc_topology_t *topology,
9991005
return selected_server_id;
10001006
}
10011007

1002-
/* If this is a single threaded topology, we must ensure that a connection is available to this server. Wrapping drivers make the assumption that successful server selection implies a connection is available. */
1003-
node = mongoc_topology_scanner_get_node (topology->scanner, selected_server_id);
1008+
/* If this is a single threaded topology, we must ensure that a connection is
1009+
* available to this server. Wrapping drivers make the assumption that
1010+
* successful server selection implies a connection is available. */
1011+
node =
1012+
mongoc_topology_scanner_get_node (topology->scanner, selected_server_id);
10041013
if (!node) {
1005-
_mongoc_server_selection_error ("Topology scanner in invalid state; cannot find load balancer", NULL, error);
1014+
_mongoc_server_selection_error (
1015+
"Topology scanner in invalid state; cannot find load balancer",
1016+
NULL,
1017+
error);
10061018
return 0;
10071019
}
10081020

10091021
if (!node->stream) {
1010-
MONGOC_DEBUG ("server selection performing scan since no connection has been established");
1022+
TRACE ("%s",
1023+
"Server selection performing scan since no connection has "
1024+
"been established");
10111025
_mongoc_topology_do_blocking_scan (topology, &scanner_error);
10121026
}
10131027

10141028
if (!node->stream) {
1015-
/* Use the error domain / code returned in mongoc-cluster when fetching a stream fails. */
1029+
/* Use the same error domain / code that is returned in mongoc-cluster.c
1030+
* when fetching a stream fails. */
10161031
if (scanner_error.code) {
10171032
bson_set_error (error,
1018-
MONGOC_ERROR_STREAM,
1019-
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1020-
"Could not establish stream for node %s: %s",
1021-
node->host.host_and_port, scanner_error.message);
1033+
MONGOC_ERROR_STREAM,
1034+
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1035+
"Could not establish stream for node %s: %s",
1036+
node->host.host_and_port,
1037+
scanner_error.message);
10221038
} else {
10231039
bson_set_error (error,
1024-
MONGOC_ERROR_STREAM,
1025-
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1026-
"Could not establish stream for node %s",
1027-
node->host.host_and_port);
1040+
MONGOC_ERROR_STREAM,
1041+
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1042+
"Could not establish stream for node %s",
1043+
node->host.host_and_port);
10281044
}
10291045
return 0;
10301046
}
@@ -1089,7 +1105,6 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,
10891105

10901106
if (topology->description.type == MONGOC_TOPOLOGY_LOAD_BALANCED) {
10911107
bson_mutex_unlock (&topology->mutex);
1092-
MONGOC_DEBUG ("bypassing server selection for load balanced topology");
10931108
return _mongoc_topology_select_server_id_loadbalanced (topology, error);
10941109
}
10951110

@@ -1400,8 +1415,8 @@ _mongoc_topology_update_from_handshake (mongoc_topology_t *topology,
14001415
bson_mutex_lock (&topology->mutex);
14011416

14021417
if (topology->description.type == MONGOC_TOPOLOGY_LOAD_BALANCED) {
1403-
/* In load balanced mode, scanning is only for connection establishment. It must not modify the topology description. */
1404-
MONGOC_DEBUG ("Ignoring handshake response in load balanced mode");
1418+
/* In load balanced mode, scanning is only for connection establishment.
1419+
* It must not modify the topology description. */
14051420
bson_mutex_unlock (&topology->mutex);
14061421
return true;
14071422
}

src/libmongoc/tests/json-test.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,8 +1739,9 @@ run_json_general_test (const json_test_config_t *config)
17391739

17401740
/* expect "operation was interrupted", ignore "command not found" or "is
17411741
* not supported" */
1742-
if (!r && (error.domain != MONGOC_ERROR_SERVER ||
1743-
(error.code != 11601 && error.code != 59)) &&
1742+
if (!r &&
1743+
(error.domain != MONGOC_ERROR_SERVER ||
1744+
(error.code != 11601 && error.code != 59)) &&
17441745
(strstr (error.message, "is unsupported") == NULL)) {
17451746
MONGOC_WARNING ("Error in killAllSessions: %s", error.message);
17461747
}

src/libmongoc/tests/test-mongoc-loadbalanced.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,9 @@ test_loadbalanced_cooldown_is_bypassed_single (void *unused)
409409
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
410410
"Could not establish stream");
411411

412-
/* Failing to "scan" would normally cause the node to be in cooldown. But in
413-
* load balancer mode this is bypassed. The subsequent connect attempt should
412+
/* Failing to "scan" would normally cause the node to be in cooldown and fail
413+
* to reconnect (until the 5 second period has passed). But in load balancer
414+
* mode cooldown is bypassed, so the subsequent connect attempt should
414415
* succeed. */
415416
ok = mongoc_client_command_simple (client,
416417
"admin",

src/libmongoc/tests/test-mongoc-sdam.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ _topology_has_description (mongoc_topology_description_t *topology,
3636
ASSERT_CMPSTR (sd->set_name, set_name);
3737
}
3838
/* TODO (CDRIVER-4057) this should assert that a null setName means the
39-
server description also has no setName.
40-
Uncomment this when CDRIVER-4057 is resolved.
39+
server description also has no setName. Uncomment this when
40+
CDRIVER-4057 is resolved:
41+
4142
else if (sd->set_name) {
4243
test_error ("server: %s, expected NULL setName, got: %s", address,
4344
sd->set_name);

0 commit comments

Comments
 (0)