lib/mongo/server_selector/base.rb in mongo-2.15.1 vs lib/mongo/server_selector/base.rb in mongo-2.16.0.alpha1
- old
+ new
@@ -171,10 +171,14 @@
# @raise [ Error::LintError ] An unexpected condition was detected, and
# lint mode is enabled.
#
# @since 2.0.0
def select_server(cluster, ping = nil, session = nil)
+ if cluster.topology.is_a?(Cluster::Topology::LoadBalanced)
+ return cluster.servers.first
+ end
+
server_selection_timeout = cluster.options[:server_selection_timeout] || SERVER_SELECTION_TIMEOUT
# Special handling for zero timeout: if we have to select a server,
# and the timeout is zero, fail immediately (since server selection
# will take some non-zero amount of time in any case).
@@ -245,10 +249,10 @@
unless cluster.topology.compatible?
raise Error::UnsupportedFeatures, cluster.topology.compatibility_error.to_s
end
if session && session.starting_transaction? && cluster.sharded?
- session.pin(server)
+ session.pin_to_server(server)
end
return server
end