Skip to content

Commit cac6bad

Browse files
authored
RUST-1152 Always use hello for monitoring when loadBalanced=true (#609)
1 parent 9583189 commit cac6bad

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/cmap/establish/handshake/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ impl Handshaker {
164164

165165
let mut command = hello_command(
166166
options.as_ref().and_then(|opts| opts.server_api.as_ref()),
167+
options.as_ref().and_then(|opts| opts.load_balanced.into()),
167168
None,
168169
);
169170

src/hello.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,19 @@ pub(crate) const LEGACY_HELLO_COMMAND_NAME_LOWERCASE: &str = "ismaster";
3131

3232
/// Construct a hello or legacy hello command, depending on the circumstances.
3333
///
34-
/// If an API version is provided, `hello` will be used.
34+
/// If an API version is provided or `load_balanced` is true, `hello` will be used.
3535
/// If the server indicated `helloOk: true`, then `hello` will also be used.
3636
/// Otherwise, legacy hello will be used, and if it's unknown whether the server supports hello,
3737
/// the command also will contain `helloOk: true`.
38-
pub(crate) fn hello_command(api: Option<&ServerApi>, hello_ok: Option<bool>) -> Command {
39-
let (command, command_name) = if api.is_some() || matches!(hello_ok, Some(true)) {
38+
pub(crate) fn hello_command(
39+
server_api: Option<&ServerApi>,
40+
load_balanced: Option<bool>,
41+
hello_ok: Option<bool>,
42+
) -> Command {
43+
let (command, command_name) = if server_api.is_some()
44+
|| matches!(load_balanced, Some(true))
45+
|| matches!(hello_ok, Some(true))
46+
{
4047
(doc! { "hello": 1 }, "hello")
4148
} else {
4249
let mut cmd = doc! { LEGACY_HELLO_COMMAND_NAME: 1 };
@@ -46,7 +53,7 @@ pub(crate) fn hello_command(api: Option<&ServerApi>, hello_ok: Option<bool>) ->
4653
(cmd, LEGACY_HELLO_COMMAND_NAME)
4754
};
4855
let mut command = Command::new(command_name.into(), "admin".into(), command);
49-
if let Some(server_api) = api {
56+
if let Some(server_api) = server_api {
5057
command.set_server_api(server_api);
5158
}
5259
command

src/sdam/monitor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ impl HeartbeatMonitor {
193193
Some(ref mut conn) => {
194194
let command = hello_command(
195195
self.client_options.server_api.as_ref(),
196+
self.client_options.load_balanced,
196197
Some(conn.stream_description()?.hello_ok),
197198
);
198199
run_hello(

src/test/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl TestClient {
8383
.await;
8484
session.mark_dirty();
8585

86-
let hello_cmd = hello_command(options.server_api.as_ref(), None);
86+
let hello_cmd = hello_command(options.server_api.as_ref(), options.load_balanced, None);
8787
let hello = RunCommand::new("admin".into(), hello_cmd.body, None, None).unwrap();
8888

8989
let server_info = bson::from_bson(Bson::Document(

0 commit comments

Comments
 (0)