lib/mongo/cluster/sdam_flow.rb in mongo-2.10.5 vs lib/mongo/cluster/sdam_flow.rb in mongo-2.11.0.rc0

- old
+ new

@@ -26,11 +26,11 @@ extend Forwardable def initialize(cluster, previous_desc, updated_desc) @cluster = cluster @topology = cluster.topology - @previous_desc = previous_desc + @original_desc = @previous_desc = previous_desc @updated_desc = updated_desc end attr_reader :cluster @@ -46,22 +46,25 @@ # @return Mongo::Cluster::Topology The current topology. attr_reader :topology attr_reader :previous_desc attr_reader :updated_desc + attr_reader :original_desc def_delegators :topology, :replica_set_name # Updates descriptions on all servers whose address matches # updated_desc's address. def update_server_descriptions servers_list.each do |server| if server.address == updated_desc.address changed = server.description != updated_desc - # Always update server description, so that fields like - # last_update_time reflect the last ismaster response + # Always update server description, so that fields that do not + # affect description equality comparisons but are part of the + # description are updated. server.update_description(updated_desc) + server.update_last_scan # But return if there was a content difference between # descriptions, and if there wasn't we'll skip the remainder of # sdam flow return changed end @@ -409,10 +412,11 @@ # # The tricky part here is that the server description changes are # not all processed together. publish_description_change_event + start_pool_if_data_bearing topology_changed_event_published = false if topology.object_id != cluster.topology.object_id || @need_topology_changed_event # We are about to publish topology changed event. # Recreate the topology instance to get its server descriptions @@ -445,10 +449,22 @@ @topology = topology.class.new(topology.options, topology.monitoring, cluster) # This sends the SDAM event cluster.update_topology(topology) end + # If the server being processed is identified as data bearing, creates the + # server's connection pool so it can start populating + def start_pool_if_data_bearing + return if !updated_desc.data_bearing? + + servers_list.each do |server| + if server.address == @updated_desc.address + server.pool + end + end + end + # Checks if the cluster has a primary, and if not, transitions the topology # to ReplicaSetNoPrimary. Topology must be ReplicaSetWithPrimary when # invoking this method. def check_if_has_primary unless topology.replica_set? @@ -474,8 +490,15 @@ updated_desc.election_id < topology.max_election_id)) return true end end false + end + + # Returns whether the server whose description this flow processed + # was not previously unknown, and is now. Used to decide, in particular, + # whether to clear the server's connection pool. + def became_unknown? + updated_desc.unknown? && !original_desc.unknown? end end end