Skip to content

RUST-1370 Only check specific fields for hello equality #892

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

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,29 +182,6 @@ pub(crate) struct HelloCommandResponse {
pub connection_id: Option<i32>,
}

impl PartialEq for HelloCommandResponse {
fn eq(&self, other: &Self) -> bool {
self.server_type() == other.server_type()
&& self.min_wire_version == other.min_wire_version
&& self.max_wire_version == other.max_wire_version
&& self.me == other.me
&& self.hosts == other.hosts
&& self.passives == other.passives
&& self.arbiters == other.arbiters
&& self.tags == other.tags
&& self.set_name == other.set_name
&& self.set_version == other.set_version
&& self.election_id == other.election_id
&& self.primary == other.primary
&& self.logical_session_timeout_minutes == other.logical_session_timeout_minutes
&& self.max_bson_object_size == other.max_bson_object_size
&& self.max_write_batch_size == other.max_write_batch_size
&& self.service_id == other.service_id
&& self.max_message_size_bytes == other.max_message_size_bytes
&& self.topology_version == other.topology_version
}
}

impl HelloCommandResponse {
pub(crate) fn server_type(&self) -> ServerType {
if self.msg.as_deref() == Some("isdbgrid") {
Expand Down
27 changes: 25 additions & 2 deletions src/sdam/description/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
bson_util,
client::ClusterTime,
error::{Error, ErrorKind, Result},
hello::HelloReply,
hello::{HelloCommandResponse, HelloReply},
options::ServerAddress,
selection_criteria::TagSet,
};
Expand Down Expand Up @@ -137,6 +137,25 @@ pub(crate) struct ServerDescription {
pub(crate) reply: Result<Option<HelloReply>>,
}

// Server description equality has a specific notion of what fields in a hello command response
// should be compared (https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#serverdescription).
fn hello_command_eq(a: &HelloCommandResponse, b: &HelloCommandResponse) -> bool {
a.server_type() == b.server_type()
&& a.min_wire_version == b.min_wire_version
&& a.max_wire_version == b.max_wire_version
&& a.me == b.me
&& a.hosts == b.hosts
&& a.passives == b.passives
&& a.arbiters == b.arbiters
&& a.tags == b.tags
&& a.set_name == b.set_name
&& a.set_version == b.set_version
&& a.election_id == b.election_id
&& a.primary == b.primary
&& a.logical_session_timeout_minutes == b.logical_session_timeout_minutes
&& a.topology_version == b.topology_version
}

impl PartialEq for ServerDescription {
fn eq(&self, other: &Self) -> bool {
if self.address != other.address || self.server_type != other.server_type {
Expand All @@ -148,7 +167,11 @@ impl PartialEq for ServerDescription {
let self_response = self_reply.as_ref().map(|r| &r.command_response);
let other_response = other_reply.as_ref().map(|r| &r.command_response);

self_response == other_response
match (self_response, other_response) {
(Some(a), Some(b)) => hello_command_eq(a, b),
(None, None) => true,
_ => false,
}
}
(Err(self_err), Err(other_err)) => {
match (self_err.kind.as_ref(), other_err.kind.as_ref()) {
Expand Down