Class: Node
- Defined in:
- lib/adhd/models/node_doc.rb
Instance Method Summary collapse
- #get_content_db(shard_db_name) ⇒ Object
- #get_node_db ⇒ Object
- #get_shard_db ⇒ Object
- #replicate_from(local_db, other_node, remote_db) ⇒ Object
-
#replicate_to(local_db, other_node, remote_db) ⇒ Object
Replicating databases and marking nodes as unavailable In the future we should hook these into a “replication manager” for databases.
Instance Method Details
#get_content_db(shard_db_name) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/adhd/models/node_doc.rb', line 89 def get_content_db(shard_db_name) server = CouchRest.new("#{url}") db = server.database!("#{name}_#{shard_db_name}_content_db") # puts "Open db #{db}" db end |
#get_node_db ⇒ Object
75 76 77 78 79 80 |
# File 'lib/adhd/models/node_doc.rb', line 75 def get_node_db server = CouchRest.new("#{url}") db = server.database!("#{name}_node_db") # puts "Open db #{db}" db end |
#get_shard_db ⇒ Object
82 83 84 85 86 87 |
# File 'lib/adhd/models/node_doc.rb', line 82 def get_shard_db server = CouchRest.new("#{url}") db = server.database!("#{name}_shard_db") # puts "Open db #{db}" db end |
#replicate_from(local_db, other_node, remote_db) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/adhd/models/node_doc.rb', line 119 def replicate_from(local_db, other_node, remote_db) # Do not try to contact unavailable nodes return false if other_node.status == "UNAVAILABLE" # No point replicating to ourselves return false if (name == other_node.name) begin # Replicate to other node is possible local_db.replicate_from(remote_db) return true rescue Exception => e # Other node turns out to be unavailable other_node.status = "UNAVAILABLE" other_node.save return false end end |
#replicate_to(local_db, other_node, remote_db) ⇒ Object
Replicating databases and marking nodes as unavailable In the future we should hook these into a “replication manager” for databases. The manager should set up continuous replication across databases, and only do a replication after some time lapses.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/adhd/models/node_doc.rb', line 101 def replicate_to(local_db, other_node, remote_db) # Do not try to contact unavailable nodes return false if other_node.status == "UNAVAILABLE" # No point replicating to ourselves return false if (name == other_node.name) begin # Replicate to other node is possible local_db.replicate_to(remote_db) return true rescue Exception => e # Other node turns out to be unavailable other_node.status = "UNAVAILABLE" other_node.save return false end end |