class Aerospike::Node
Constants
- FULL_HEALTH
- HAS_BATCH_ANY
- HAS_PARTITION_QUERY
- HAS_PARTITION_SCAN
- HAS_QUERY_SHOW
- PARTITIONS
Attributes
cluster[R]
cluster_name[R]
connections[R]
failures[R]
features[R]
host[R]
name[R]
partition_generation[R]
peers_count[R]
peers_generation[R]
rebalance_generation[R]
reference_count[R]
responded[R]
Public Class Methods
new(cluster, nv)
click to toggle source
Initialize server node with connection parameters.
# File lib/aerospike/node.rb, line 36 def initialize(cluster, nv) @cluster = cluster @name = nv.name @aliases = Atomic.new(nv.aliases) @host = nv.host @features = nv.features @cluster_name = nv.cluster_name # TODO: Re-use connection from node validator @tend_connection = nil # Assign host to first IP alias because the server identifies nodes # by IP address (not hostname). @host = nv.aliases[0] @health = Atomic.new(FULL_HEALTH) @peers_count = Atomic.new(0) @peers_generation = ::Aerospike::Node::Generation.new @partition_generation = ::Aerospike::Node::Generation.new @rebalance_generation = ::Aerospike::Node::Rebalance.new @reference_count = Atomic.new(0) @responded = Atomic.new(false) @active = Atomic.new(true) @failures = Atomic.new(0) @replica_index = Atomic.new(0) @racks = Atomic.new(nil) @connections = ::Aerospike::ConnectionPool.new(cluster, host) end
Public Instance Methods
==(other)
click to toggle source
# File lib/aerospike/node.rb, line 218 def ==(other) other && other.is_a?(Node) && (@name == other.name) end
Also aliased as: eql?
active!()
click to toggle source
Sets node as active
# File lib/aerospike/node.rb, line 150 def active! @active.update { |_| true } end
active?()
click to toggle source
Checks if the node is active
# File lib/aerospike/node.rb, line 160 def active? @active.value end
aliases()
click to toggle source
# File lib/aerospike/node.rb, line 204 def aliases @aliases.value end
batch_any?()
click to toggle source
# File lib/aerospike/node.rb, line 74 def batch_any? (@features & HAS_BATCH_ANY) != 0 end
close()
click to toggle source
Marks node as inactice and closes all cached connections
# File lib/aerospike/node.rb, line 209 def close inactive! close_connections end
decrease_health()
click to toggle source
Decrease node Health as a result of bad connection or communication
# File lib/aerospike/node.rb, line 135 def decrease_health @health.update { |v| v - 1 } end
failed!()
click to toggle source
# File lib/aerospike/node.rb, line 196 def failed! @failures.update { |v| v + 1 } end
failed?(threshold = 1)
click to toggle source
# File lib/aerospike/node.rb, line 192 def failed?(threshold = 1) @failures.value >= threshold end
fill_connection_pool_up_to(min_connection_size)
click to toggle source
# File lib/aerospike/node.rb, line 89 def fill_connection_pool_up_to(min_connection_size) current_number_of_connections = @connections.length if min_connection_size > 0 while current_number_of_connections < min_connection_size conn = @connections.create @connections.offer(conn) current_number_of_connections += 1 end end end
get_connection(timeout)
click to toggle source
Get a connection to the node. If no cached connection is not available, a new connection will be created
# File lib/aerospike/node.rb, line 102 def get_connection(timeout) loop do conn = @connections.poll if conn.connected? conn.timeout = timeout.to_f return conn end end end
get_host()
click to toggle source
Retrieves host for the node
# File lib/aerospike/node.rb, line 145 def get_host @host end
has_peers?()
click to toggle source
# File lib/aerospike/node.rb, line 188 def has_peers? @peers_count.value > 0 end
has_rack(ns, rack_id)
click to toggle source
# File lib/aerospike/node.rb, line 83 def has_rack(ns, rack_id) racks = @racks.value return false unless racks racks[ns] == rack_id end
hash()
click to toggle source
# File lib/aerospike/node.rb, line 223 def hash @name.hash end
inactive!()
click to toggle source
Sets node as inactive
# File lib/aerospike/node.rb, line 155 def inactive! @active.update { |_| false } end
increase_reference_count!()
click to toggle source
# File lib/aerospike/node.rb, line 164 def increase_reference_count! @reference_count.update { |v| v + 1 } end
inspect()
click to toggle source
# File lib/aerospike/node.rb, line 227 def inspect "#<Aerospike::Node: @name=#{@name}, @host=#{@host}>" end
partition_query?()
click to toggle source
# File lib/aerospike/node.rb, line 66 def partition_query? (@features & HAS_PARTITION_QUERY) != 0 end
put_connection(conn)
click to toggle source
Put back a connection to the cache. If cache is full, the connection will be closed and discarded
# File lib/aerospike/node.rb, line 114 def put_connection(conn) conn.close unless active? @connections.offer(conn) end
query_show?()
click to toggle source
# File lib/aerospike/node.rb, line 70 def query_show? (@features & HAS_QUERY_SHOW) != 0 end
referenced?()
click to toggle source
# File lib/aerospike/node.rb, line 172 def referenced? @reference_count.value > 0 end
refresh_info(peers)
click to toggle source
Convenience wrappers for applying refresh operations to a node
# File lib/aerospike/node.rb, line 235 def refresh_info(peers) Node::Refresh::Info.(self, peers) end
refresh_partitions(peers)
click to toggle source
# File lib/aerospike/node.rb, line 239 def refresh_partitions(peers) Node::Refresh::Partitions.(self, peers) end
refresh_peers(peers)
click to toggle source
# File lib/aerospike/node.rb, line 247 def refresh_peers(peers) Node::Refresh::Peers.(self, peers) end
refresh_racks()
click to toggle source
# File lib/aerospike/node.rb, line 243 def refresh_racks Node::Refresh::Racks.(self) end
refresh_reset()
click to toggle source
# File lib/aerospike/node.rb, line 251 def refresh_reset Node::Refresh::Reset.(self) end
reset_failures!()
click to toggle source
# File lib/aerospike/node.rb, line 200 def reset_failures! @failures.value = 0 end
reset_reference_count!()
click to toggle source
# File lib/aerospike/node.rb, line 168 def reset_reference_count! @reference_count.value = 0 end
reset_responded!()
click to toggle source
# File lib/aerospike/node.rb, line 184 def reset_responded! @responded.value = false end
responded!()
click to toggle source
# File lib/aerospike/node.rb, line 176 def responded! @responded.value = true end
responded?()
click to toggle source
# File lib/aerospike/node.rb, line 180 def responded? @responded.value == true end
restore_health()
click to toggle source
Mark the node as healthy
# File lib/aerospike/node.rb, line 128 def restore_health # There can be cases where health is full, but active is false. # Once a node has been marked inactive, it stays inactive. @health.value = FULL_HEALTH end
supports_feature?(feature)
click to toggle source
# File lib/aerospike/node.rb, line 214 def supports_feature?(feature) @features.include?(feature.to_s) end
tend_connection()
click to toggle source
Separate connection for refreshing
# File lib/aerospike/node.rb, line 120 def tend_connection if @tend_connection.nil? || @tend_connection.closed? @tend_connection = Cluster::CreateConnection.(cluster, host) end @tend_connection end
unhealthy?()
click to toggle source
Check if the node is unhealthy
# File lib/aerospike/node.rb, line 140 def unhealthy? @health.value <= 0 end
update_racks(parser)
click to toggle source
# File lib/aerospike/node.rb, line 78 def update_racks(parser) new_racks = parser.update_racks @racks.value = new_racks if new_racks end
Private Instance Methods
close_connections()
click to toggle source
# File lib/aerospike/node.rb, line 257 def close_connections @tend_connection.close if @tend_connection # drain connections and close all of them # non-blocking, does not call create_block when passed false while conn = @connections.poll(false) conn.close if conn end end