@@ -174,13 +174,12 @@ _mongoc_topology_scanner_cb (uint32_t id,
174
174
topology = (mongoc_topology_t * ) data ;
175
175
176
176
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. */
179
179
return ;
180
180
}
181
181
182
182
bson_mutex_lock (& topology -> mutex );
183
-
184
183
sd = mongoc_topology_description_server_by_id (
185
184
& topology -> description , id , NULL );
186
185
@@ -432,6 +431,12 @@ mongoc_topology_new (const mongoc_uri_t *uri, bool single_threaded)
432
431
topology -> uri , MONGOC_URI_LOADBALANCED , false)) {
433
432
init_type = MONGOC_TOPOLOGY_LOAD_BALANCED ;
434
433
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. */
435
440
_mongoc_topology_bypass_cooldown (topology );
436
441
}
437
442
} else if (service && !has_directconnection ) {
@@ -961,9 +966,10 @@ mongoc_topology_select (mongoc_topology_t *topology,
961
966
}
962
967
}
963
968
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. */
967
973
static uint32_t
968
974
_mongoc_topology_select_server_id_loadbalanced (mongoc_topology_t * topology ,
969
975
bson_error_t * error )
@@ -999,32 +1005,42 @@ _mongoc_topology_select_server_id_loadbalanced (mongoc_topology_t *topology,
999
1005
return selected_server_id ;
1000
1006
}
1001
1007
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 );
1004
1013
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 );
1006
1018
return 0 ;
1007
1019
}
1008
1020
1009
1021
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" );
1011
1025
_mongoc_topology_do_blocking_scan (topology , & scanner_error );
1012
1026
}
1013
1027
1014
1028
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. */
1016
1031
if (scanner_error .code ) {
1017
1032
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 );
1022
1038
} else {
1023
1039
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 );
1028
1044
}
1029
1045
return 0 ;
1030
1046
}
@@ -1089,7 +1105,6 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,
1089
1105
1090
1106
if (topology -> description .type == MONGOC_TOPOLOGY_LOAD_BALANCED ) {
1091
1107
bson_mutex_unlock (& topology -> mutex );
1092
- MONGOC_DEBUG ("bypassing server selection for load balanced topology" );
1093
1108
return _mongoc_topology_select_server_id_loadbalanced (topology , error );
1094
1109
}
1095
1110
@@ -1400,8 +1415,8 @@ _mongoc_topology_update_from_handshake (mongoc_topology_t *topology,
1400
1415
bson_mutex_lock (& topology -> mutex );
1401
1416
1402
1417
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. */
1405
1420
bson_mutex_unlock (& topology -> mutex );
1406
1421
return true;
1407
1422
}
0 commit comments