lib/mongo/cluster/sdam_flow.rb
def update_rs_from_primary
      if topology.replica_set_name.nil?
        @topology = Topology::ReplicaSetWithPrimary.new(
          topology.options.merge(replica_set_name: updated_desc.replica_set_name),
          topology.monitoring, self)
      end

      if topology.replica_set_name != updated_desc.replica_set_name
        log_warn(
          "Removing server #{updated_desc.address.to_s} because it has an " +
          "incorrect replica set name (#{updated_desc.replica_set_name}); " +
          "current set name is #{topology.replica_set_name}"
        )
        remove
        check_if_has_primary
        return
      end

      if stale_primary?
        @updated_desc = ::Mongo::Server::Description.new(updated_desc.address,
          {}, updated_desc.average_round_trip_time)
        update_server_descriptions
        check_if_has_primary
        return
      end

      max_election_id = topology.new_max_election_id(updated_desc)
      max_set_version = topology.new_max_set_version(updated_desc)

      if max_election_id != topology.max_election_id ||
        max_set_version != topology.max_set_version
      then
        @topology = Topology::ReplicaSetWithPrimary.new(
          topology.options.merge(
            max_election_id: max_election_id,
            max_set_version: max_set_version
          ), topology.monitoring, self)
      end

      # At this point we have accepted the updated server description
      # and the topology (both are primary). Commit these changes so that
      # their respective SDAM events are published before SDAM events for
      # server additions/removals that follow
      publish_description_change_event

      servers_list.each do |server|
        if server.address != updated_desc.address
          if server.primary?
            server.update_description(::Mongo::Server::Description.new(
              server.address, {}, server.description.average_round_trip_time))
          end
        end
      end

      servers = add_servers_from_desc(updated_desc)
      remove_servers_not_in_desc(updated_desc)

      check_if_has_primary

      servers.each do |server|
        server.start_monitoring
      end
    end
# Updates topology which must be a ReplicaSetWithPrimary with information
# from the primary's server description.
#
# This method does not change topology type to ReplicaSetWithPrimary -
# this needs to have been done prior to calling this method.
#
# If the primary whose description is being processed is determined to be
# stale, this method will change the server description and topology
# type to unknown.
Updates topology which must be a ReplicaSetWithPrimary with information
from the primary's server description.

This method does not change topology type to ReplicaSetWithPrimary
this needs to have been done prior to calling this method.

If the primary whose description is being processed is determined to be
stale, this method will change the server description and topology
type to unknown.
Updates topology which must be a ReplicaSetWithPrimary with information from the primary ' s server description . This method does not change topology type to ReplicaSetWithPrimary this needs to have been done prior to calling this method . If the primary whose description is being processed is determined to be stale this method will change the server description and topology type to unknown .
def update_rs_from_primary
      if topology.replica_set_name.nil?
        @topology = Topology::ReplicaSetWithPrimary.new(
          topology.options.merge(replica_set_name: updated_desc.replica_set_name),
          topology.monitoring, self)
      end
      if topology.replica_set_name != updated_desc.replica_set_name
        log_warn(
          "Removing server #{updated_desc.address.to_s} because it has an " +
          "incorrect replica set name (#{updated_desc.replica_set_name}); " +
          "current set name is #{topology.replica_set_name}"
        )
        remove
        check_if_has_primary
        return
      end
      if stale_primary?
        @updated_desc = ::Mongo::Server::Description.new(updated_desc.address,
          {}, updated_desc.average_round_trip_time)
        update_server_descriptions
        check_if_has_primary
        return
      end
      max_election_id = topology.new_max_election_id(updated_desc)
      max_set_version = topology.new_max_set_version(updated_desc)
      if max_election_id != topology.max_election_id ||
        max_set_version != topology.max_set_version
      then
        @topology = Topology::ReplicaSetWithPrimary.new(
          topology.options.merge(
            max_election_id: max_election_id,
            max_set_version: max_set_version
          ), topology.monitoring, self)
      end
      publish_description_change_event
      servers_list.each do |server|
        if server.address != updated_desc.address
          if server.primary?
            server.update_description(::Mongo::Server::Description.new(
              server.address, {}, server.description.average_round_trip_time))
          end
        end
      end
      servers = add_servers_from_desc(updated_desc)
      remove_servers_not_in_desc(updated_desc)
      check_if_has_primary
      servers.each do |server|
        server.start_monitoring
      end
    end
def update_rs_from_primary if topology . replica_set_name . nil? @topology = Topology :: ReplicaSetWithPrimary . new ( topology . options . merge ( replica_set_name : updated_desc . replica_set_name ) , topology . monitoring , self ) end if topology . replica_set_name != updated_desc . replica_set_name log_warn ( "Removing server #{updated_desc.address.to_s} because it has an " + "incorrect replica set name (#{updated_desc.replica_set_name}); " + "current set name is #{topology.replica_set_name}" ) remove check_if_has_primary return end if stale_primary? @updated_desc = :: Mongo :: Server :: Description . new ( updated_desc . address , { } , updated_desc . average_round_trip_time ) update_server_descriptions check_if_has_primary return end max_election_id = topology . new_max_election_id ( updated_desc ) max_set_version = topology . new_max_set_version ( updated_desc ) if max_election_id != topology . max_election_id || max_set_version != topology . max_set_version then @topology = Topology :: ReplicaSetWithPrimary . new ( topology . options . merge ( max_election_id : max_election_id , max_set_version : max_set_version ) , topology . monitoring , self ) end publish_description_change_event servers_list . each do | server | if server . address != updated_desc . address if server . primary? server . update_description ( :: Mongo :: Server :: Description . new ( server . address , { } , server . description . average_round_trip_time ) ) end end end servers = add_servers_from_desc ( updated_desc ) remove_servers_not_in_desc ( updated_desc ) check_if_has_primary servers . each do | server | server . start_monitoring end end
Updates topology which must be a ReplicaSetWithPrimary with information
from the primary's server description.
Updates topology which must be a ReplicaSetWithPrimary with information from the primary ' s server description .
# At this point we have accepted the updated server description # and the topology (both are primary). Commit these changes so that # their respective SDAM events are published before SDAM events for # server additions/removals that follow