Class: Droonga::Catalog::ReplicasVolume
- Inherits:
-
Object
- Object
- Droonga::Catalog::ReplicasVolume
- Includes:
- Enumerable
- Defined in:
- lib/droonga/catalog/replicas_volume.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #all_nodes ⇒ Object
- #compute_routes(message, active_nodes) ⇒ Object
- #each(&block) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(dataset, raw) ⇒ ReplicasVolume
constructor
A new instance of ReplicasVolume.
- #live_replicas(active_nodes = nil) ⇒ Object
- #replicas ⇒ Object
- #select(how = nil, active_nodes = nil) ⇒ Object
- #sliced? ⇒ Boolean
Constructor Details
#initialize(dataset, raw) ⇒ ReplicasVolume
Returns a new instance of ReplicasVolume.
21 22 23 24 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 21 def initialize(dataset, raw) @dataset = dataset @raw = raw end |
Instance Method Details
#==(other) ⇒ Object
30 31 32 33 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 30 def ==(other) other.is_a?(self.class) and to_a == other.to_a end |
#all_nodes ⇒ Object
70 71 72 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 70 def all_nodes @all_nodes ||= collect_all_nodes end |
#compute_routes(message, active_nodes) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 83 def compute_routes(, active_nodes) routes = [] case ["type"] when "broadcast" replicas = select(["replica"].to_sym, active_nodes) replicas.each do |volume| routes.concat(volume.compute_routes(, active_nodes)) end when "scatter" #TODO: we should choose suitable replica from differently sliced replicas. replicas = select(["replica"].to_sym, active_nodes) replicas.each do |volume| routes.concat(volume.compute_routes(, active_nodes)) end end routes end |
#each(&block) ⇒ Object
26 27 28 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 26 def each(&block) replicas.each(&block) end |
#eql?(other) ⇒ Boolean
35 36 37 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 35 def eql?(other) self == other end |
#hash ⇒ Object
39 40 41 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 39 def hash to_a.hash end |
#live_replicas(active_nodes = nil) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 74 def live_replicas(active_nodes=nil) return replicas unless active_nodes replicas.select do |volume| dead_nodes = volume.all_nodes - active_nodes dead_nodes.empty? end end |
#replicas ⇒ Object
66 67 68 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 66 def replicas @replicas ||= create_replicas end |
#select(how = nil, active_nodes = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 43 def select(how=nil, active_nodes=nil) case how when :top replicas = live_replicas(active_nodes) if replicas.empty? [] else [replicas.first] end when :random replicas = live_replicas(active_nodes) if replicas.empty? [] else [replicas.sample] end when :all live_replicas(active_nodes) else super end end |
#sliced? ⇒ Boolean
101 102 103 104 105 |
# File 'lib/droonga/catalog/replicas_volume.rb', line 101 def sliced? replicas.any? do |volume| volume.sliced? end end |