Navigation Menu

Skip to content

Commit

Permalink
Generate catalog.json for multiple hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 24, 2014
1 parent 323a1cc commit 2394b2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
10 changes: 3 additions & 7 deletions bin/droonga-catalog-generate
Expand Up @@ -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|
Expand All @@ -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
Expand Down
15 changes: 7 additions & 8 deletions lib/droonga/catalog_generator.rb
Expand Up @@ -87,10 +87,9 @@ def to_catalog

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
Expand All @@ -103,16 +102,16 @@ def to_json
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",
Expand All @@ -121,13 +120,13 @@ def generate_replica
}
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
Expand Down

0 comments on commit 2394b2d

Please sign in to comment.