YUKI Hiroshi
null+****@clear*****
Thu Apr 24 19:03:59 JST 2014
YUKI Hiroshi 2014-04-24 19:03:59 +0900 (Thu, 24 Apr 2014) New Revision: 2394b2defeb84d8d6bf770a7377eb408c1c0e196 https://github.com/droonga/droonga-engine/commit/2394b2defeb84d8d6bf770a7377eb408c1c0e196 Message: Generate catalog.json for multiple hosts Modified files: bin/droonga-catalog-generate lib/droonga/catalog_generator.rb Modified: bin/droonga-catalog-generate (+3 -7) =================================================================== --- bin/droonga-catalog-generate 2014-04-24 18:49:16 +0900 (2922ead) +++ bin/droonga-catalog-generate 2014-04-24 19:03:59 +0900 (68ff3af) @@ -45,9 +45,9 @@ parser.on("--n-workers=N", Integer, "Use N workers for the current dataset.") do |n| current_dataset[:n_workers] = n end -parser.on("--host=NAME", - "Use the NAME as the host for the current dataset.") do |host| - current_dataset[:host] = host +parser.on("--hosts=NAME1,NAME2,...", Array, + "Use given hosts for replicas of the current dataset.") do |hosts| + current_dataset[:hosts] = hosts end parser.on("--port=PORT", Integer, "Use the PORT as the port for the current dataset.") do |port| @@ -57,10 +57,6 @@ parser.on("--tag=TAG", "Use the TAG as the tag for the current dataset.") do |tag| current_dataset[:tag] = tag end -parser.on("--n-replicas=N", Integer, - "Use N replicas for the current dataset.") do |n| - current_dataset[:n_replicas] = n -end parser.on("--n-slices=N", Integer, "Use N slices for each replica.") do |n| current_dataset[:n_slices] = n Modified: lib/droonga/catalog_generator.rb (+7 -8) =================================================================== --- lib/droonga/catalog_generator.rb 2014-04-24 18:49:16 +0900 (e207785) +++ lib/droonga/catalog_generator.rb 2014-04-24 19:03:59 +0900 (a7b4f55) @@ -87,10 +87,9 @@ module Droonga class Replicas def initialize(parameters={}) - @host = parameters[:host] || "127.0.0.1" + @hosts = parameters[:hosts] || ["127.0.0.1"] @port = parameters[:port] || 10031 @tag = parameters[:tag] || "droonga" - @n_replicas = parameters[:n_replicas] || 2 @n_slices = parameters[:n_slices] || 1 @n_volumes = 0 @@ -103,16 +102,16 @@ module Droonga private def generate_json replicas = [] - @n_replicas.times do |index| - replicas << generate_replica + @hosts.each do |host| + replicas << generate_replica(host) end replicas end - def generate_replica + def generate_replica(host) slices = [] @n_slices.times do |index| - slices << generate_slice + slices << generate_slice(host) end { "dimension" => "_key", @@ -121,13 +120,13 @@ module Droonga } end - def generate_slice + def generate_slice(host) name = sprintf('%03d', @n_volumes) @n_volumes += 1 { "weight" => weight, "volume" => { - "address" => "#{@host}:#{@port}/#{@tag}.#{name}", + "address" => "#{host}:#{@port}/#{@tag}.#{name}", }, } end -------------- next part -------------- HTML����������������������������...Download