YUKI Hiroshi
null+****@clear*****
Sun Jun 29 01:14:58 JST 2014
YUKI Hiroshi 2014-06-29 01:14:58 +0900 (Sun, 29 Jun 2014) New Revision: b16422963b9ea0d0584e7f594d578c69e134fca2 https://github.com/droonga/droonga-engine/commit/b16422963b9ea0d0584e7f594d578c69e134fca2 Message: Re-implement join command based on serf events partially Modified files: bin/droonga-engine-join Modified: bin/droonga-engine-join (+31 -44) =================================================================== --- bin/droonga-engine-join 2014-06-29 01:08:25 +0900 (fd99e94) +++ bin/droonga-engine-join 2014-06-29 01:14:58 +0900 (9a1678e) @@ -50,27 +50,14 @@ end parser.separator("") parser.separator("Connections:") +parser.on("--host=HOST", + "Host name of the node to be joined.") do |host| + options.joining_host = host +end parser.on("--replica-source-host=HOST", "Host name of the soruce cluster to be connected.") do |host| options.replica_source_host = host end -parser.on("--my-host=HOST", - "Host name of this node.") do |host| - options.my_host = host -end - -parser.separator("") -parser.separator("Commands:") -parser.on("--drndump=PATH", - "Path to the drndump command.", - "(#{options.drndump})") do |path| - options.drndump = path -end -parser.on("--droonga-request=PATH", - "Path to the droonga-request command.", - "(#{options.client})") do |path| - options.client = path -end parser.parse!(ARGV) @@ -86,14 +73,14 @@ end source_catalog = JSON.parse(catalog_path.read) +unless options.joining_host + raise "You must specify the host name or the IP address of the node " + + "to be joined via --host option." +end unless options.replica_source_host raise "You must specify the host name or the IP address of a node " + "of an existing cluster via --replica-source-host option." end -unless options.my_host - raise "You must specify the host name or the IP address of this node " + - "via --my-host option." -end generator = Droonga::CatalogGenerator.new @@ -112,21 +99,29 @@ options.tag = dataset.tag options.port = dataset.port options.other_hosts = dataset.hosts +options.joining_node = "#{options.joining_host}:#{options.port}/#{options.tag}" +options.source_node = "#{options.replica_source_host}:#{options.port}/#{options.tag}" + if options.copy - puts "Initializing replica..." + puts "Initializing new replica..." - dataset.replicas.hosts = [options.my_host] - destination_catalog = generator.catalog - Droonga::SafeFileWriter.write(catalog_path, JSON.pretty_generate(destination_catalog)) + Droonga::Serf.send_event(options.joining_node, "set_replicas", + "dataset" => options.dataset, + "hosts" => [options.joining_host]) sleep(1) # wait for restart puts "Copying data..." - Droonga::DataAbsorber.absorb(:drndump => options.drndump, - :client => options.client, - :dataset => options.dataset, +#TODO: currently there is no way to wait the absorb command is successfully finished via serf... +# +# Droonga::Serf.send_event(options.joining_node, "absorb_data", +# "source" => options.replica_source_host, +# "dataset" => options.dataset, +# "port" => options.port, +# "tag" => options.tag) + Droonga::DataAbsorber.absorb(:dataset => options.dataset, :source_host => options.replica_source_host, - :destination_host => options.my_host, + :destination_host => options.joining_host, :port => options.port, :tag => options.tag) do |dump| puts dump @@ -134,21 +129,13 @@ if options.copy sleep(1) end -puts "Restarting replica..." - -dataset.replicas.hosts = options.other_hosts + [options.my_host] -dataset.replicas.hosts.uniq! -final_catalog = generator.catalog -Droonga::SafeFileWriter.write(catalog_path, JSON.pretty_generate(final_catalog)) - -sleep(1) # wait for restart - -puts "Joining to the cluster..." - -name = "#{options.my_host}:#{options.port}/#{options.tag}" -Droonga::Serf.send_event(name, "join", "dataset" => options.dataset, - "type" => "replica", - "host" => options.my_host) +puts "Joining new replica to the cluster..." +Droonga::Serf.send_event(options.joining_node, "add_replicas", + "dataset" => options.dataset, + "hosts" => options.other_hosts) +Droonga::Serf.send_event(options.source_node, "add_replicas", + "dataset" => options.dataset, + "hosts" => [options.joining_host]) puts "Done." -------------- next part -------------- HTML����������������������������...다운로드