Skip to content

RUST-953 Treat load balancers like mongos for readPreference #422

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
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
36 changes: 15 additions & 21 deletions src/sdam/description/topology/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ impl TopologyDescription {
) {
match (self.topology_type, server_type) {
(TopologyType::Sharded, ServerType::Mongos)
| (TopologyType::Single, ServerType::Mongos) => {
| (TopologyType::Single, ServerType::Mongos)
| (TopologyType::LoadBalanced, _) => {
self.update_command_read_pref_for_mongos(command, criteria)
}
(TopologyType::Single, ServerType::Standalone) => {}
Expand Down Expand Up @@ -212,27 +213,20 @@ impl TopologyDescription {
command: &mut Command<T>,
criteria: Option<&SelectionCriteria>,
) {
match criteria {
Some(SelectionCriteria::ReadPreference(ReadPreference::Secondary { ref options })) => {
command.set_read_preference(ReadPreference::Secondary {
options: options.clone(),
})
let read_preference = match criteria {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes aren't a functional change, I just happened to be looking at this function and find it easier to read with the inner enum matched on directly.

Some(SelectionCriteria::ReadPreference(rp)) => rp,
_ => return,
};
match read_preference {
ReadPreference::Secondary { .. }
| ReadPreference::PrimaryPreferred { .. }
| ReadPreference::Nearest { .. } => {
command.set_read_preference(read_preference.clone())
}
Some(SelectionCriteria::ReadPreference(ReadPreference::PrimaryPreferred {
ref options,
})) => command.set_read_preference(ReadPreference::PrimaryPreferred {
options: options.clone(),
}),
Some(SelectionCriteria::ReadPreference(ReadPreference::SecondaryPreferred {
ref options,
})) if options.max_staleness.is_some() || options.tag_sets.is_some() => command
.set_read_preference(ReadPreference::SecondaryPreferred {
options: options.clone(),
}),
Some(SelectionCriteria::ReadPreference(ReadPreference::Nearest { ref options })) => {
command.set_read_preference(ReadPreference::Nearest {
options: options.clone(),
})
ReadPreference::SecondaryPreferred { ref options }
if options.max_staleness.is_some() || options.tag_sets.is_some() =>
{
command.set_read_preference(read_preference.clone())
}
_ => {}
}
Expand Down