Navigation Menu

Skip to content

Commit

Permalink
Implement serf events to modify replicas
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 28, 2014
1 parent 9f3dfc1 commit 878dccc
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions lib/droonga/command/serf_event_handler.rb
Expand Up @@ -69,39 +69,56 @@ def process_event
case @event_sub_name
when "change_role"
save_status(:role, @payload["role"])
when "join"
process_node_join
when "unjoin" # TODO: Is "unjoin" clear word? How about "leave"?
process_node_unjoin
when "set_replicas"
set_replicas
when "add_replicas"
add_replicas
when "remove_replicas"
remove_replicas
end
end

def process_node_join
def given_hosts
hosts = @payload["hosts"]
return nil unless hosts
hosts = [hosts] if hosts.is_a?(String)
hosts
end

def set_replicas
dataset = @payload["dataset"]
return unless dataset

host = @payload["host"]
return unless host
hosts = given_hosts
return unless hosts

modify_catalog do |generator|
generator.datasets[dataset].replicas.hosts = hosts
end
end

def add_replicas
dataset = @payload["dataset"]
return unless dataset

return unless @payload["type"] == "replica"
hosts = given_hosts
return unless hosts

modify_catalog do |generator|
generator.datasets[dataset].replicas.hosts << host
generator.datasets[dataset].replicas.hosts += hosts
generator.datasets[dataset].replicas.hosts.uniq!
end
end

def process_node_unjoin
def remove_replica
dataset = @payload["dataset"]
return unless dataset

host = @payload["host"]
return unless host

return unless @payload["type"] == "replica"
hosts = given_hosts
return unless hosts

modify_catalog do |generator|
generator.datasets[dataset].replicas.hosts -= [host]
generator.datasets[dataset].replicas.hosts -= hosts
end
end

Expand Down

0 comments on commit 878dccc

Please sign in to comment.