/// Update the replica set topology description based on the RSPrimary server description.
Update the replica set topology description based on the RSPrimary server description.
Update the replica set topology description based on the RSPrimary server description .
fn update_rs_from_primary_server(
        &mut self,
        server_description: ServerDescription,
    ) -> Result<(), String> {
        if self.set_name.is_none() {
            self.set_name = server_description.set_name()?;
        } else if self.set_name != server_description.set_name()? {
            self.servers.remove(&server_description.address);
            self.record_primary_state();
            return Ok(());
        }
        if let Some(server_set_version) = server_description.set_version()? {
            if let Some(server_election_id) = server_description.election_id()? {
                if let Some(topology_max_set_version) = self.max_set_version {
                    if let Some(ref topology_max_election_id) = self.max_election_id {
                        if topology_max_set_version > server_set_version
                            || (topology_max_set_version == server_set_version
                                && *topology_max_election_id > server_election_id)
                        {
                            self.servers.insert(
                                server_description.address.clone(),
                                ServerDescription::new(server_description.address, None),
                            );
                            self.record_primary_state();
                            return Ok(());
                        }
                    }
                }
                self.max_election_id = Some(server_election_id);
            }
        }
        if let Some(server_set_version) = server_description.set_version()? {
            if self
                .max_set_version
                .as_ref()
                .map(|topology_max_set_version| server_set_version > *topology_max_set_version)
                .unwrap_or(true)
            {
                self.max_set_version = Some(server_set_version);
            }
        }
        let addresses: Vec<_> = self.servers.keys().cloned().collect();
        // If any other servers are RSPrimary, replace them with an unknown server decscription,
        // which will cause them to be updated by a new isMaster.
        for address in addresses.clone() {
            if address == server_description.address {
                continue;
            }
            if let ServerType::RsPrimary = self.servers.get(&address).unwrap().server_type {
                self.servers
                    .insert(address.clone(), ServerDescription::new(address, None));
            }
        }
        self.add_new_servers(server_description.known_hosts()?)?;
        let known_hosts: HashSet<_> = server_description.known_hosts()?.collect();
        for address in addresses {
            if !known_hosts.contains(&address.to_string()) {
                self.servers.remove(&address);
            }
        }
        self.record_primary_state();
        Ok(())
    }
fn update_rs_from_primary_server ( & mut self , server_description : ServerDescription , ) -> Result < ( ) , String > { if self . set_name . is_none ( ) { self . set_name = server_description . set_name ( ) ? ; } else if self . set_name != server_description . set_name ( ) ? { self . servers . remove ( & server_description . address ) ; self . record_primary_state ( ) ; return Ok ( ( ) ) ; } if let Some ( server_set_version ) = server_description . set_version ( ) ? { if let Some ( server_election_id ) = server_description . election_id ( ) ? { if let Some ( topology_max_set_version ) = self . max_set_version { if let Some ( ref topology_max_election_id ) = self . max_election_id { if topology_max_set_version > server_set_version || ( topology_max_set_version == server_set_version && * topology_max_election_id > server_election_id ) { self . servers . insert ( server_description . address . clone ( ) , ServerDescription :: new ( server_description . address , None ) , ) ; self . record_primary_state ( ) ; return Ok ( ( ) ) ; } } } self . max_election_id = Some ( server_election_id ) ; } } if let Some ( server_set_version ) = server_description . set_version ( ) ? { if self . max_set_version . as_ref ( ) . map ( | topology_max_set_version | server_set_version > * topology_max_set_version ) . unwrap_or ( true ) { self . max_set_version = Some ( server_set_version ) ; } } let addresses : Vec < _ > = self . servers . keys ( ) . cloned ( ) . collect ( ) ; // If any other servers are RSPrimary, replace them with an unknown server decscription, // which will cause them to be updated by a new isMaster. for address in addresses . clone ( ) { if address == server_description . address { continue ; } if let ServerType :: RsPrimary = self . servers . get ( & address ) . unwrap ( ) . server_type { self . servers . insert ( address . clone ( ) , ServerDescription :: new ( address , None ) ) ; } } self . add_new_servers ( server_description . known_hosts ( ) ? ) ? ; let known_hosts : HashSet < _ > = server_description . known_hosts ( ) ? . collect ( ) ; for address in addresses { if ! known_hosts . contains ( & address . to_string ( ) ) { self . servers . remove ( & address ) ; } } self . record_primary_state ( ) ; Ok ( ( ) ) }
Update the replica set topology description based on the RSPrimary server description.
Update the replica set topology description based on the RSPrimary server description .
&mut self
server_description
ServerDescription