lib/mongo/server_selector/primary_preferred.rb in mongo-2.13.0.beta1 vs lib/mongo/server_selector/primary_preferred.rb in mongo-2.13.0.rc1
- old
+ new
@@ -19,11 +19,10 @@
# Encapsulates specifications for selecting servers, with the
# primary preferred, given a list of candidates.
#
# @since 2.0.0
class PrimaryPreferred < Base
- include Selectable
# Name of the this read preference in the server's format.
#
# @since 2.5.0
SERVER_FORMATTED_NAME = 'primaryPreferred'.freeze
@@ -91,22 +90,20 @@
private
# Select servers taking into account any defined tag sets and
# local threshold, with the primary preferred.
#
- # @example Select servers given a list of candidates,
- # with the primary preferred.
- # preference = Mongo::ServerSelector::PrimaryPreferred.new
- # preference.select([candidate_1, candidate_2])
- #
# @return [ Array ] A list of servers matching tag sets and acceptable
# latency with the primary preferred.
#
# @since 2.0.0
- def select(candidates)
- primary = primary(candidates)
- secondaries = near_servers(secondaries(candidates))
- primary.first ? primary : secondaries
+ def select_in_replica_set(candidates)
+ primaries = primary(candidates)
+ if primaries.first
+ primaries
+ else
+ near_servers(secondaries(candidates))
+ end
end
def max_staleness_allowed?
true
end