Navigation Menu

Skip to content

Commit

Permalink
Add new serf event absorb_data (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 28, 2014
1 parent b164229 commit a94528c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/droonga/command/serf_event_handler.rb
Expand Up @@ -18,6 +18,7 @@
require "droonga/path"
require "droonga/serf"
require "droonga/catalog_generator"
require "droonga/data_absorber"
require "droonga/safe_file_writer"

module Droonga
Expand Down Expand Up @@ -75,9 +76,15 @@ def process_event
add_replicas
when "remove_replicas"
remove_replicas
when "absorb_data"
absorb_data
end
end

def host
@serf_name.split(":").first
end

def given_hosts
hosts = @payload["hosts"]
return nil unless hosts
Expand Down Expand Up @@ -130,6 +137,28 @@ def modify_catalog
SafeFileWriter.write(Path.catalog, JSON.pretty_generate(generator.catalog))
end

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

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

current_catalog = JSON.parse(Path.catalog.read)
generator = CatalogGenerator.new
generator.load(current_catalog)

port = @payload["port"] || generator.datasets[dataset].replicas.port
tag = @payload["tag"] || generator.datasets[dataset].replicas.tag

DataAbsorber.absorb(:dataset => dataset,
:source_host => source,
:destination_host => host,
:port => port,
:tag => tag)
#TODO: how to notify that this process is successfully finished for other nodes?
end

def live_nodes
nodes = {}
members = `#{@serf} members -rpc-addr #{@serf_rpc_address}`
Expand Down

0 comments on commit a94528c

Please sign in to comment.