Module: Aerospike::Node::Refresh::Peers

Defined in:
lib/aerospike/node/refresh/peers.rb

Class Method Summary collapse

Class Method Details

.call(node, peers) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/aerospike/node/refresh/peers.rb', line 25

def call(node, peers)
  return unless should_refresh?(node)

  ::Aerospike.logger.debug("Update peers for node #{node.name}")

  cluster = node.cluster

  collection = ::Aerospike::Peers::Fetch.(cluster, node.tend_connection)
  peers.peers = collection.peers
  node.peers_count.value = peers.peers.size
  peers_validated = true

  peers.peers.each do |peer|
    next if ::Aerospike::Cluster::FindNode.(cluster, peers, peer.node_name)

    node_validated = false

    peer.hosts.each do |host|
      begin
        nv = NodeValidator.new(cluster, host, cluster.connection_timeout, cluster.cluster_name, cluster.tls_options)

        if nv.name != peer.node_name
          ::Aerospike.logger.warn("Peer node #{peer.node_name} is different than actual node #{nv.name} for host #{host}");
          # Must look for new node name in the unlikely event that node names do not agree.
          # Node already exists. Do not even try to connect to hosts.
          if Cluster::FindNode.(cluster, peers, nv.name)
            node_validated = true
            break;
          end
        end

        new_node = cluster.create_node(nv)
        peers.nodes[nv.name] = new_node
        node_validated = true
        break;
      rescue ::Aerospike::Exceptions::Aerospike => e
        Aerospike.logger.warn("Add node #{host} failed: #{e.inspect}")
      end

      peers_validated = false unless node_validated
    end
  end

  # Only set new peers generation if all referenced peers are added to
  # the cluster.
  node.peers_generation.update(collection.generation) if peers_validated
  peers.refresh_count += 1
rescue ::Aerospike::Exceptions::Aerospike => e
  Refresh::Failed.(node, e)
end

.should_refresh?(node) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/aerospike/node/refresh/peers.rb', line 76

def should_refresh?(node)
  node.failures.value == 0 && node.active?
end