Skip to content

Commit

Permalink
Split complex functions to simple one
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Dec 5, 2014
1 parent f3d0e6d commit d6aa915
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/droonga/catalog/dataset.rb
Expand Up @@ -64,7 +64,7 @@ def all_nodes
end

def compute_routes(message, live_nodes)
compute_routes_from_replicas(replicas, message, live_nodes)
routes_from_replicas(replicas, message, live_nodes)
end

def single_slice?
Expand All @@ -77,34 +77,40 @@ def single_slice?
end

private
def compute_routes_from_replicas(replicas, message, live_nodes)
def routes_from_replicas(replicas, message, live_nodes)
routes = []
case message["type"]
when "broadcast"
replicas = replicas.select(message["replica"].to_sym, live_nodes)
replicas.each do |replica|
slices = replica.select_slices
slices.each do |slice|
if slice.replicas
routes += compute_routes_from_replicas(slice.replicas, message, live_nodes)
else
routes << slice.volume.address.to_s
end
end
routes += routes_from_slices(slices, message, live_nodes)
end
when "scatter"
replicas = replicas.select(message["replica"].to_sym, live_nodes)
replicas.each do |replica|
slice = replica.choose_slice(message["record"])
if slice.replicas
routes += compute_routes_from_replicas(slice.replicas, message, live_nodes)
else
routes << slice.volume.address.to_s
end
routes += routes_from_slice(slice, message, live_nodes)
end
end
routes
end

def routes_from_slices(slices, message, live_nodes)
routes = []
slices.each do |slice|
routes += routes_from_slice(slice, message, live_nodes)
end
routes
end

def routes_from_slice(slice, message, live_nodes)
if slice.replicas
routes_from_replicas(slice.replicas, message, live_nodes)
else
[slice.volume.address.to_s]
end
end
end
end
end

0 comments on commit d6aa915

Please sign in to comment.