lib/mongo/cluster/sdam_flow.rb in mongo-2.12.4 vs lib/mongo/cluster/sdam_flow.rb in mongo-2.13.0.beta1

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2018-2019 MongoDB, Inc. +# Copyright (C) 2018-2020 MongoDB Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # @@ -56,10 +56,17 @@ # 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 + # SDAM flow must be run when topology version in the new description + # is equal to the current topology version, per the example in + # https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#what-is-the-purpose-of-topologyversion + unless updated_desc.topology_version_gte?(server.description) + return false + end + @server_description_changed = server.description != updated_desc # Always update server description, so that fields that do not # affect description equality comparisons but are part of the # description are updated. @@ -89,11 +96,20 @@ return end case topology when Topology::Single - # no changes ever + if topology.replica_set_name + if updated_desc.replica_set_name != topology.replica_set_name + log_warn( + "Server #{updated_desc.address.to_s} has an incorrect replica set name '#{updated_desc.replica_set_name}'; expected '#{topology.replica_set_name}'" + ) + @updated_desc = ::Mongo::Server::Description.new(updated_desc.address, + {}, updated_desc.average_round_trip_time) + update_server_descriptions + end + end when Topology::Unknown if updated_desc.standalone? update_unknown_with_standalone elsif updated_desc.mongos? @topology = Topology::Sharded.new(topology.options, topology.monitoring, self) @@ -109,18 +125,18 @@ update_rs_without_primary end when Topology::Sharded unless updated_desc.unknown? || updated_desc.mongos? log_warn( - "Removing server #{updated_desc.address.to_s} because it is a #{updated_desc.server_type.to_s.upcase} and not a MONGOS" + "Removing server #{updated_desc.address.to_s} because it is of the wrong type (#{updated_desc.server_type.to_s.upcase}) - expected SHARDED" ) remove end when Topology::ReplicaSetWithPrimary if updated_desc.standalone? || updated_desc.mongos? log_warn( - "Removing server #{updated_desc.address.to_s} because it is a #{updated_desc.server_type.to_s.upcase} and not a replica set member" + "Removing server #{updated_desc.address.to_s} because it is of the wrong type (#{updated_desc.server_type.to_s.upcase}) - expected a replica set member" ) remove check_if_has_primary elsif updated_desc.primary? update_rs_from_primary @@ -130,11 +146,11 @@ check_if_has_primary end when Topology::ReplicaSetNoPrimary if updated_desc.standalone? || updated_desc.mongos? log_warn( - "Removing server #{updated_desc.address.to_s} because it is a #{updated_desc.server_type.to_s.upcase} and not a replica set member" + "Removing server #{updated_desc.address.to_s} because it is of the wrong type (#{updated_desc.server_type.to_s.upcase}) - expected a replica set member" ) remove elsif updated_desc.primary? # Here we change topology type to RS with primary, however # while processing updated_desc we may find that its RS name @@ -192,11 +208,11 @@ 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}" + "incorrect replica set name '#{updated_desc.replica_set_name}'; " + + "expected '#{topology.replica_set_name}'" ) remove check_if_has_primary return end