Skip to content

Commit

Permalink
RUST-953 Treat load balancers like mongos for readPreference (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
abr-egn committed Aug 12, 2021
1 parent d33f38d commit 53b677a
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/sdam/description/topology/mod.rs
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 {
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

0 comments on commit 53b677a

Please sign in to comment.