lib/moped/cluster.rb in moped-1.0.0.rc vs lib/moped/cluster.rb in moped-1.0.0

- old
+ new

@@ -42,31 +42,35 @@ @nodes = hosts.map { |host| Node.new(host) } end # Returns the list of available nodes, refreshing 1) any nodes which were # down and ready to be checked again and 2) any nodes whose information is - # out of date. + # out of date. Arbiter nodes are not returned. # # @example Get the available nodes. # cluster.nodes # # @return [ Array<Node> ] the list of available nodes. # # @since 1.0.0 def nodes + current_time = Time.new + down_boundary = current_time - @options[:down_interval] + refresh_boundary = current_time - @options[:refresh_interval] + # Find the nodes that were down but are ready to be refreshed, or those # with stale connection information. needs_refresh, available = @nodes.partition do |node| - (node.down? && node.down_at < (Time.new - @options[:down_interval])) || - node.needs_refresh?(Time.new - @options[:refresh_interval]) + (node.down? && node.down_at < down_boundary) || node.needs_refresh?(refresh_boundary) end # Refresh those nodes. available.concat refresh(needs_refresh) - # Now return all the nodes that are available. - available.reject(&:down?) + # Now return all the nodes that are available and participating in the + # replica set. + available.reject { |node| node.down? || node.arbiter? } end # Refreshes information for each of the nodes provided. The node list # defaults to the list of all known nodes. # @@ -189,9 +193,13 @@ raise( Errors::ConnectionFailure, "Could not connect to any secondary or primary nodes for replica set #{inspect}" ) end + end + + def inspect + "<#{self.class.name} nodes=#{@nodes.inspect}>" end private def initialize_copy(_)