Class: NodeDB
Overview
Key Restrictions ok internal_IDs: must only contain [a-z0-9-]
Instance Attribute Summary collapse
-
#local_node_db ⇒ Object
Returns the value of attribute local_node_db.
-
#our_node ⇒ Object
Returns the value of attribute our_node.
Instance Method Summary collapse
- #available_node_list ⇒ Object
- #head_management_node ⇒ Object
-
#initialize(our_nodev) ⇒ NodeDB
constructor
A new instance of NodeDB.
- #sync ⇒ Object
Constructor Details
#initialize(our_nodev) ⇒ NodeDB
Returns a new instance of NodeDB.
7 8 9 10 11 12 |
# File 'lib/adhd/models/node_doc.rb', line 7 def initialize(our_nodev) @our_node = our_nodev # Get the address of the CDB from the node @local_node_db = our_nodev.get_node_db end |
Instance Attribute Details
#local_node_db ⇒ Object
Returns the value of attribute local_node_db.
5 6 7 |
# File 'lib/adhd/models/node_doc.rb', line 5 def local_node_db @local_node_db end |
#our_node ⇒ Object
Returns the value of attribute our_node.
5 6 7 |
# File 'lib/adhd/models/node_doc.rb', line 5 def our_node @our_node end |
Instance Method Details
#available_node_list ⇒ Object
41 42 43 44 45 |
# File 'lib/adhd/models/node_doc.rb', line 41 def available_node_list # Returns all nodes marked as available all_nodes = Node.by_name return all_nodes.select {|node| node.status == "RUNNING"} end |
#head_management_node ⇒ Object
47 48 49 50 51 |
# File 'lib/adhd/models/node_doc.rb', line 47 def head_management_node management_nodes = Node.by_is_management.reverse hmn = management_nodes.find {|node| node.status == "RUNNING"} return hmn end |
#sync ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/adhd/models/node_doc.rb', line 14 def sync # We replicate our state to the management node(s) management_nodes = Node.by_is_management.reverse # NOTE: randomize the order for load balancing here # NOTE2: How to build skynet (TODO) # ------------------- # If length of management is zero, then chose 3 different random # nodes at each sync, and sync with them in node_name order. # This guarantees that any updates on nodes are communicated in # O(log N) ephocs, at the cost of O(3 * N) connections per epoch. # It also guarantees any new management servers are discovered in # this O(log N) time, creating "jelly fish" or "partition proof" # availability. management_nodes.each do |mng_node| remote_db = mng_node.get_node_db bool_from = @our_node.replicate_from(local_node_db, mng_node, remote_db) bool_to = @our_node.replicate_to(local_node_db, mng_node, remote_db) if bool_from && bool_to && !our_node.is_management #puts "Pushed to management" break end #puts "Did not push to management" end end |