Class: CouchProxy::Cluster
- Inherits:
-
Object
- Object
- CouchProxy::Cluster
- Defined in:
- lib/couchproxy/cluster.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #<<(node) ⇒ Object
- #any_node ⇒ Object
- #any_partition ⇒ Object
-
#initialize(nodes, couchjs, reducers) ⇒ Cluster
constructor
A new instance of Cluster.
- #partition(doc_id) ⇒ Object
- #partitions ⇒ Object
- #reducer ⇒ Object
Constructor Details
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
5 6 7 |
# File 'lib/couchproxy/cluster.rb', line 5 def nodes @nodes end |
Instance Method Details
#<<(node) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/couchproxy/cluster.rb', line 17 def <<(node) @nodes << node @partitions = @nodes.inject(0) do |acc, n| acc + n.partitions.size end self end |
#any_node ⇒ Object
31 32 33 |
# File 'lib/couchproxy/cluster.rb', line 31 def any_node @nodes[rand(@nodes.size)] end |
#any_partition ⇒ Object
35 36 37 |
# File 'lib/couchproxy/cluster.rb', line 35 def any_partition any_node.any_partition end |
#partition(doc_id) ⇒ Object
25 26 27 28 29 |
# File 'lib/couchproxy/cluster.rb', line 25 def partition(doc_id) num = Zlib.crc32(doc_id.to_s).abs % @partitions node = @nodes.find {|n| n.hosts?(num) } node.partition(num) end |
#partitions ⇒ Object
39 40 41 |
# File 'lib/couchproxy/cluster.rb', line 39 def partitions @nodes.map {|n| n.partitions}.flatten end |
#reducer ⇒ Object
13 14 15 |
# File 'lib/couchproxy/cluster.rb', line 13 def reducer @reducers[rand(@reducers.size)] end |