Skip to content

Commit 9f104e0

Browse files
committed
shortcut server selection
1 parent 22f44b4 commit 9f104e0

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

src/libmongoc/src/mongoc/mongoc-cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ _mongoc_cmd_parts_assemble_mongod (mongoc_cmd_parts_t *parts,
629629
case MONGOC_TOPOLOGY_DESCRIPTION_TYPES:
630630
case MONGOC_TOPOLOGY_LOADBALANCED:
631631
default:
632-
/* must not call this function w/ sharded or unknown topology type */
632+
/* must not call this function w/ sharded, load balanced, or unknown topology type */
633633
BSON_ASSERT (false);
634634
}
635635
} /* if (!parts->is_write_command) */

src/libmongoc/src/mongoc/mongoc-server-description-private.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ struct _mongoc_server_description_t {
109109
2. an app thread receives any network error before completing a handshake
110110
3. an app thread receives a non-timeout network error after the handshake
111111
4. an app thread receives a "not primary" or "node is recovering" error from
112-
a
113-
pre-4.2 server.
112+
a pre-4.2 server.
114113
*/
115114
uint32_t generation;
116115
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ _mongoc_topology_description_monitor_opening (mongoc_topology_description_t *td)
131131
(int) 0);
132132
prev_sd = mongoc_server_description_new_copy (sd);
133133
if (td->apm_callbacks.topology_changed) {
134+
mongoc_topology_description_destroy (prev_td);
134135
_mongoc_topology_description_copy_to (td, prev_td);
135136
}
136137
sd->type = MONGOC_SERVER_LOADBALANCER;

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,6 @@ _mongoc_topology_do_blocking_scan (mongoc_topology_t *topology,
816816
{
817817
_mongoc_handshake_freeze ();
818818

819-
if (topology->description.type == MONGOC_TOPOLOGY_LOADBALANCED) {
820-
MONGOC_DEBUG ("bypassing server selection logic for single threaded");
821-
return;
822-
}
823819
bson_mutex_lock (&topology->mutex);
824820
mongoc_topology_scan_once (topology, true /* obey cooldown */);
825821
bson_mutex_unlock (&topology->mutex);
@@ -1013,6 +1009,20 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,
10131009
if (topology->single_threaded) {
10141010
_mongoc_topology_description_monitor_opening (&topology->description);
10151011

1012+
if (topology->description.type == MONGOC_TOPOLOGY_LOADBALANCED) {
1013+
/* Bypass server selection loop. Always select the only server. */
1014+
selected_server = mongoc_topology_description_select (
1015+
&topology->description, optype, read_prefs, local_threshold_ms);
1016+
1017+
if (!selected_server) {
1018+
_mongoc_server_selection_error (
1019+
"No suitable server found in load balanced deployment",
1020+
NULL,
1021+
error);
1022+
return 0;
1023+
}
1024+
}
1025+
10161026
tried_once = false;
10171027
next_update = topology->last_scan + heartbeat_msec * 1000;
10181028
if (next_update < loop_start) {
@@ -1110,6 +1120,17 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,
11101120
selected_server = mongoc_topology_description_select (
11111121
&topology->description, optype, read_prefs, local_threshold_ms);
11121122

1123+
if (topology->description.type == MONGOC_TOPOLOGY_LOADBALANCED) {
1124+
/* Bypass server selection loop. Always select the only server. */
1125+
if (!selected_server) {
1126+
_mongoc_server_selection_error (
1127+
"No suitable server found in load balanced deployment",
1128+
NULL,
1129+
error);
1130+
return 0;
1131+
}
1132+
}
1133+
11131134
if (!selected_server) {
11141135
TRACE (
11151136
"server selection requesting an immediate scan, want %s",

0 commit comments

Comments
 (0)