Skip to content

Commit e5bdc41

Browse files
committed
RUST-953 Treat load balancers like mongos for readPreference
1 parent d33f38d commit e5bdc41

File tree

1 file changed

+15
-21
lines changed
  • src/sdam/description/topology

1 file changed

+15
-21
lines changed

src/sdam/description/topology/mod.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ impl TopologyDescription {
176176
) {
177177
match (self.topology_type, server_type) {
178178
(TopologyType::Sharded, ServerType::Mongos)
179-
| (TopologyType::Single, ServerType::Mongos) => {
179+
| (TopologyType::Single, ServerType::Mongos)
180+
| (TopologyType::LoadBalanced, _) => {
180181
self.update_command_read_pref_for_mongos(command, criteria)
181182
}
182183
(TopologyType::Single, ServerType::Standalone) => {}
@@ -212,27 +213,20 @@ impl TopologyDescription {
212213
command: &mut Command<T>,
213214
criteria: Option<&SelectionCriteria>,
214215
) {
215-
match criteria {
216-
Some(SelectionCriteria::ReadPreference(ReadPreference::Secondary { ref options })) => {
217-
command.set_read_preference(ReadPreference::Secondary {
218-
options: options.clone(),
219-
})
216+
let read_preference = match criteria {
217+
Some(SelectionCriteria::ReadPreference(rp)) => rp,
218+
_ => return,
219+
};
220+
match read_preference {
221+
ReadPreference::Secondary { .. }
222+
| ReadPreference::PrimaryPreferred { .. }
223+
| ReadPreference::Nearest { .. } => {
224+
command.set_read_preference(read_preference.clone())
220225
}
221-
Some(SelectionCriteria::ReadPreference(ReadPreference::PrimaryPreferred {
222-
ref options,
223-
})) => command.set_read_preference(ReadPreference::PrimaryPreferred {
224-
options: options.clone(),
225-
}),
226-
Some(SelectionCriteria::ReadPreference(ReadPreference::SecondaryPreferred {
227-
ref options,
228-
})) if options.max_staleness.is_some() || options.tag_sets.is_some() => command
229-
.set_read_preference(ReadPreference::SecondaryPreferred {
230-
options: options.clone(),
231-
}),
232-
Some(SelectionCriteria::ReadPreference(ReadPreference::Nearest { ref options })) => {
233-
command.set_read_preference(ReadPreference::Nearest {
234-
options: options.clone(),
235-
})
226+
ReadPreference::SecondaryPreferred { ref options }
227+
if options.max_staleness.is_some() || options.tag_sets.is_some() =>
228+
{
229+
command.set_read_preference(read_preference.clone())
236230
}
237231
_ => {}
238232
}

0 commit comments

Comments
 (0)