lib/mongo/cluster/topology/replica_set.rb in mongo-2.6.1 vs lib/mongo/cluster/topology/replica_set.rb in mongo-2.6.2
- old
+ new
@@ -211,10 +211,16 @@
description.hosts.empty? ||
!member_of_this_set?(description))
end
# Whether a specific server in the cluster can be removed, given a description.
+ # As described in the SDAM spec, a server should be removed if the server's
+ # address does not match the "me" field of the isMaster response, if the server
+ # has a different replica set name, or if an isMaster response from the primary
+ # does not contain the server's address in the list of known hosts. Note that as
+ # described by the spec, a server determined to be of type Unknown from its
+ # isMaster response is NOT removed from the topology.
#
# @example Check if a specific server can be removed from the cluster.
# topology.remove_server?(description, server)
#
# @param [ Mongo::Server::Description ] description The description.
@@ -222,12 +228,14 @@
#
# @return [ true, false ] Whether the server can be removed from the cluster.
#
# @since 2.0.6
def remove_server?(description, server)
+ ((server.address == description.address) && description.me_mismatch?) ||
remove_self?(description, server) ||
(member_of_this_set?(description) &&
+ description.server_type == :primary &&
!description.servers.empty? &&
!description.lists_server?(server))
end
# A replica set topology is not sharded.
@@ -314,13 +322,17 @@
def member_of_this_set?(description)
description.replica_set_member? &&
description.replica_set_name == replica_set_name
end
+ # As described by the SDAM spec, a server should be removed from the
+ # topology upon receiving its isMaster response if no error occurred
+ # and replica set name does not match that of the topology.
def remove_self?(description, server)
- !member_of_this_set?(description) &&
- description.is_server?(server) &&
- !description.ghost?
+ !description.unknown? &&
+ !member_of_this_set?(description) &&
+ description.is_server?(server) &&
+ !description.ghost?
end
end
end
end
end