lib/aerospike/cluster.rb
def refresh_nodes
      cluster_config_changed = false

      nodes = self.nodes
      if nodes.empty?
        seed_nodes
        cluster_config_changed = true
        nodes = self.nodes
      end

      peers = Peers.new

      # Clear node reference count
      nodes.each do |node|
        node.refresh_reset
      end

      peers.use_peers = supports_peers_protocol?

      # refresh all known nodes
      nodes.each do |node|
        node.refresh_info(peers)
      end

      # refresh peers when necessary
      if peers.generation_changed?
        # Refresh peers for all nodes that responded the first time even if only
        # one node's peers changed.
        peers.reset_refresh_count!

        nodes.each do |node|
          node.refresh_peers(peers)
        end
      end

      nodes.each do |node|
        node.refresh_partitions(peers) if node.partition_generation.changed?
      end

      if peers.generation_changed? || !peers.use_peers?
        nodes_to_remove = find_nodes_to_remove(peers.refresh_count)
        if nodes_to_remove.any?
          remove_nodes(nodes_to_remove)
          cluster_config_changed = true
        end
      end

      # Add any new nodes from peer refresh
      if peers.nodes.any?
        # peers.nodes is a Hash. Pass only values, ie. the array of nodes
        add_nodes(peers.nodes.values)
        cluster_config_changed = true
      end

      cluster_config_changed
    end
def refresh_nodes
      cluster_config_changed = false

      nodes = self.nodes
      if nodes.empty?
        seed_nodes
        cluster_config_changed = true
        nodes = self.nodes
      end

      peers = Peers.new

      # Clear node reference count
      nodes.each do |node|
        node.refresh_reset
      end

      peers.use_peers = supports_peers_protocol?

      # refresh all known nodes
      nodes.each do |node|
        node.refresh_info(peers)
      end

      # refresh peers when necessary
      if peers.generation_changed?
        # Refresh peers for all nodes that responded the first time even if only
        # one node's peers changed.
        peers.reset_refresh_count!

        nodes.each do |node|
          node.refresh_peers(peers)
        end
      end

      nodes.each do |node|
        node.refresh_partitions(peers) if node.partition_generation.changed?
      end

      if peers.generation_changed? || !peers.use_peers?
        nodes_to_remove = find_nodes_to_remove(peers.refresh_count)
        if nodes_to_remove.any?
          remove_nodes(nodes_to_remove)
          cluster_config_changed = true
        end
      end

      # Add any new nodes from peer refresh
      if peers.nodes.any?
        # peers.nodes is a Hash. Pass only values, ie. the array of nodes
        add_nodes(peers.nodes.values)
        cluster_config_changed = true
      end

      cluster_config_changed
    end
Refresh status of all nodes in cluster. Adds new nodes and/or removes
 unhealty ones