Class: Aerospike::Node
- Inherits:
-
Object
- Object
- Aerospike::Node
- Defined in:
- lib/aerospike/node.rb,
lib/aerospike/node/rebalance.rb,
lib/aerospike/node/generation.rb,
lib/aerospike/node/verify/name.rb,
lib/aerospike/node/refresh/info.rb,
lib/aerospike/node/refresh/peers.rb,
lib/aerospike/node/refresh/racks.rb,
lib/aerospike/node/refresh/reset.rb,
lib/aerospike/node/refresh/failed.rb,
lib/aerospike/node/refresh/friends.rb,
lib/aerospike/node/refresh/partitions.rb,
lib/aerospike/node/verify/cluster_name.rb,
lib/aerospike/node/verify/peers_generation.rb,
lib/aerospike/node/verify/partition_generation.rb,
lib/aerospike/node/verify/rebalance_generation.rb
Defined Under Namespace
Modules: Refresh, Verify Classes: Generation, Rebalance
Constant Summary collapse
- PARTITIONS =
4096
- FULL_HEALTH =
100
- HAS_PARTITION_SCAN =
1 << 0
- HAS_QUERY_SHOW =
1 << 1
- HAS_BATCH_ANY =
1 << 2
- HAS_PARTITION_QUERY =
1 << 3
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#cluster_name ⇒ Object
readonly
Returns the value of attribute cluster_name.
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#partition_generation ⇒ Object
readonly
Returns the value of attribute partition_generation.
-
#peers_count ⇒ Object
readonly
Returns the value of attribute peers_count.
-
#peers_generation ⇒ Object
readonly
Returns the value of attribute peers_generation.
-
#rebalance_generation ⇒ Object
readonly
Returns the value of attribute rebalance_generation.
-
#reference_count ⇒ Object
readonly
Returns the value of attribute reference_count.
-
#responded ⇒ Object
readonly
Returns the value of attribute responded.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#active! ⇒ Object
Sets node as active.
-
#active? ⇒ Boolean
Checks if the node is active.
- #aliases ⇒ Object
- #batch_any? ⇒ Boolean
-
#close ⇒ Object
Marks node as inactice and closes all cached connections.
-
#decrease_health ⇒ Object
Decrease node Health as a result of bad connection or communication.
- #failed! ⇒ Object
- #failed?(threshold = 1) ⇒ Boolean
- #fill_connection_pool_up_to(min_connection_size) ⇒ Object
-
#get_connection(timeout) ⇒ Object
Get a connection to the node.
-
#get_host ⇒ Object
Retrieves host for the node.
- #has_peers? ⇒ Boolean
- #has_rack(ns, rack_id) ⇒ Object
- #hash ⇒ Object
-
#inactive! ⇒ Object
Sets node as inactive.
- #increase_reference_count! ⇒ Object
-
#initialize(cluster, nv) ⇒ Node
constructor
Initialize server node with connection parameters.
- #inspect ⇒ Object
- #partition_query? ⇒ Boolean
-
#put_connection(conn) ⇒ Object
Put back a connection to the cache.
- #query_show? ⇒ Boolean
- #referenced? ⇒ Boolean
-
#refresh_info(peers) ⇒ Object
Convenience wrappers for applying refresh operations to a node.
- #refresh_partitions(peers) ⇒ Object
- #refresh_peers(peers) ⇒ Object
- #refresh_racks ⇒ Object
- #refresh_reset ⇒ Object
- #reset_failures! ⇒ Object
- #reset_reference_count! ⇒ Object
- #reset_responded! ⇒ Object
- #responded! ⇒ Object
- #responded? ⇒ Boolean
-
#restore_health ⇒ Object
Mark the node as healthy.
- #supports_feature?(feature) ⇒ Boolean
-
#tend_connection ⇒ Object
Separate connection for refreshing.
-
#unhealthy? ⇒ Boolean
Check if the node is unhealthy.
- #update_racks(parser) ⇒ Object
Constructor Details
#initialize(cluster, nv) ⇒ Node
Initialize server node with connection parameters.
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 |
# 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 |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def cluster @cluster end |
#cluster_name ⇒ Object (readonly)
Returns the value of attribute cluster_name.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def cluster_name @cluster_name end |
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def connections @connections end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def failures @failures end |
#features ⇒ Object (readonly)
Returns the value of attribute features.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def features @features end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def name @name end |
#partition_generation ⇒ Object (readonly)
Returns the value of attribute partition_generation.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def partition_generation @partition_generation end |
#peers_count ⇒ Object (readonly)
Returns the value of attribute peers_count.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def peers_count @peers_count end |
#peers_generation ⇒ Object (readonly)
Returns the value of attribute peers_generation.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def peers_generation @peers_generation end |
#rebalance_generation ⇒ Object (readonly)
Returns the value of attribute rebalance_generation.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def rebalance_generation @rebalance_generation end |
#reference_count ⇒ Object (readonly)
Returns the value of attribute reference_count.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def reference_count @reference_count end |
#responded ⇒ Object (readonly)
Returns the value of attribute responded.
25 26 27 |
# File 'lib/aerospike/node.rb', line 25 def responded @responded end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
218 219 220 |
# File 'lib/aerospike/node.rb', line 218 def ==(other) other && other.is_a?(Node) && (@name == other.name) end |
#active! ⇒ Object
Sets node as active
150 151 152 |
# File 'lib/aerospike/node.rb', line 150 def active! @active.update { |_| true } end |
#active? ⇒ Boolean
Checks if the node is active
160 161 162 |
# File 'lib/aerospike/node.rb', line 160 def active? @active.value end |
#aliases ⇒ Object
204 205 206 |
# File 'lib/aerospike/node.rb', line 204 def aliases @aliases.value end |
#batch_any? ⇒ Boolean
74 75 76 |
# File 'lib/aerospike/node.rb', line 74 def batch_any? (@features & HAS_BATCH_ANY) != 0 end |
#close ⇒ Object
Marks node as inactice and closes all cached connections
209 210 211 212 |
# File 'lib/aerospike/node.rb', line 209 def close inactive! close_connections end |
#decrease_health ⇒ Object
Decrease node Health as a result of bad connection or communication
135 136 137 |
# File 'lib/aerospike/node.rb', line 135 def decrease_health @health.update { |v| v - 1 } end |
#failed! ⇒ Object
196 197 198 |
# File 'lib/aerospike/node.rb', line 196 def failed! @failures.update { |v| v + 1 } end |
#failed?(threshold = 1) ⇒ Boolean
192 193 194 |
# File 'lib/aerospike/node.rb', line 192 def failed?(threshold = 1) @failures.value >= threshold end |
#fill_connection_pool_up_to(min_connection_size) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# 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) ⇒ Object
Get a connection to the node. If no cached connection is not available, a new connection will be created
102 103 104 105 106 107 108 109 110 |
# 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 ⇒ Object
Retrieves host for the node
145 146 147 |
# File 'lib/aerospike/node.rb', line 145 def get_host @host end |
#has_peers? ⇒ Boolean
188 189 190 |
# File 'lib/aerospike/node.rb', line 188 def has_peers? @peers_count.value > 0 end |
#has_rack(ns, rack_id) ⇒ Object
83 84 85 86 87 |
# 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 ⇒ Object
223 224 225 |
# File 'lib/aerospike/node.rb', line 223 def hash @name.hash end |
#inactive! ⇒ Object
Sets node as inactive
155 156 157 |
# File 'lib/aerospike/node.rb', line 155 def inactive! @active.update { |_| false } end |
#increase_reference_count! ⇒ Object
164 165 166 |
# File 'lib/aerospike/node.rb', line 164 def increase_reference_count! @reference_count.update { |v| v + 1 } end |
#inspect ⇒ Object
227 228 229 |
# File 'lib/aerospike/node.rb', line 227 def inspect "#<Aerospike::Node: @name=#{@name}, @host=#{@host}>" end |
#partition_query? ⇒ Boolean
66 67 68 |
# File 'lib/aerospike/node.rb', line 66 def partition_query? (@features & HAS_PARTITION_QUERY) != 0 end |
#put_connection(conn) ⇒ Object
Put back a connection to the cache. If cache is full, the connection will be closed and discarded
114 115 116 117 |
# File 'lib/aerospike/node.rb', line 114 def put_connection(conn) conn.close unless active? @connections.offer(conn) end |
#query_show? ⇒ Boolean
70 71 72 |
# File 'lib/aerospike/node.rb', line 70 def query_show? (@features & HAS_QUERY_SHOW) != 0 end |
#referenced? ⇒ Boolean
172 173 174 |
# File 'lib/aerospike/node.rb', line 172 def referenced? @reference_count.value > 0 end |
#refresh_info(peers) ⇒ Object
Convenience wrappers for applying refresh operations to a node
235 236 237 |
# File 'lib/aerospike/node.rb', line 235 def refresh_info(peers) Node::Refresh::Info.(self, peers) end |
#refresh_partitions(peers) ⇒ Object
239 240 241 |
# File 'lib/aerospike/node.rb', line 239 def refresh_partitions(peers) Node::Refresh::Partitions.(self, peers) end |
#refresh_peers(peers) ⇒ Object
247 248 249 |
# File 'lib/aerospike/node.rb', line 247 def refresh_peers(peers) Node::Refresh::Peers.(self, peers) end |
#refresh_racks ⇒ Object
243 244 245 |
# File 'lib/aerospike/node.rb', line 243 def refresh_racks Node::Refresh::Racks.(self) end |
#refresh_reset ⇒ Object
251 252 253 |
# File 'lib/aerospike/node.rb', line 251 def refresh_reset Node::Refresh::Reset.(self) end |
#reset_failures! ⇒ Object
200 201 202 |
# File 'lib/aerospike/node.rb', line 200 def reset_failures! @failures.value = 0 end |
#reset_reference_count! ⇒ Object
168 169 170 |
# File 'lib/aerospike/node.rb', line 168 def reset_reference_count! @reference_count.value = 0 end |
#reset_responded! ⇒ Object
184 185 186 |
# File 'lib/aerospike/node.rb', line 184 def reset_responded! @responded.value = false end |
#responded! ⇒ Object
176 177 178 |
# File 'lib/aerospike/node.rb', line 176 def responded! @responded.value = true end |
#responded? ⇒ Boolean
180 181 182 |
# File 'lib/aerospike/node.rb', line 180 def responded? @responded.value == true end |
#restore_health ⇒ Object
Mark the node as healthy
128 129 130 131 132 |
# 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) ⇒ Boolean
214 215 216 |
# File 'lib/aerospike/node.rb', line 214 def supports_feature?(feature) @features.include?(feature.to_s) end |
#tend_connection ⇒ Object
Separate connection for refreshing
120 121 122 123 124 125 |
# 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? ⇒ Boolean
Check if the node is unhealthy
140 141 142 |
# File 'lib/aerospike/node.rb', line 140 def unhealthy? @health.value <= 0 end |
#update_racks(parser) ⇒ Object
78 79 80 81 |
# File 'lib/aerospike/node.rb', line 78 def update_racks(parser) new_racks = parser.update_racks @racks.value = new_racks if new_racks end |