Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
bugs fixes for
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Maxwell committed Oct 1, 2010
1 parent 4c75c08 commit 82f238a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
24 changes: 16 additions & 8 deletions lib/gizzard/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def run
end
end
end

class RepairCommand < ShardCommand
def run
args = @argv.dup.map{|a| a.split(/\s+/)}.flatten
Expand Down Expand Up @@ -289,15 +289,17 @@ def initialize(name)
end

def run
puts command_options.inspect
help! "No shards specified" if @argv.empty?
shards = []
command_options.write_only_shard ||= "com.twitter.gizzard.shards.WriteOnlyShard"
additional_hosts = (command_options.hosts || "").split(/[\s,]+/)
ids = @argv.map{|arg| ShardId.new(*arg.split("/")) rescue nil }.compact
by_host = ids.inject({}) do |memo, id|
memo[id.hostname] ||= NamedArray.new(id.hostname)
memo[id.hostname] << id
memo
end

additional_hosts.each do |host|
by_host[host] ||= NamedArray.new(host)
end
Expand All @@ -312,19 +314,24 @@ def run
end while longest.length > shortest.length + 1

shard_info = nil
puts sets.map{|l|l.length}.inspect
sets.each do |set|
host = set.name
set.each do |id|
if id.hostname != host
shard_info ||= service.get_shard(id)
old = id.to_unix
id.hostname = host
puts "gizzmo create #{shard_info.class_name} -s '#{shard_info.source_type}' -d '#{shard_info.destination_type}' #{id.to_unix}"
puts "gizzmo copy #{old} #{id.to_unix}"
shards << [old, id.to_unix]
end
end
end

new_shards = shards.map{|(old, new)| new }

puts "gizzmo create #{shard_info.class_name} -s '#{shard_info.source_type}' -d '#{shard_info.destination_type}' #{new_shards.join(" ")}"
puts "gizzmo wrap #{command_options.write_only_shard} #{new_shards.join(" ")}"
shards.map {|(old, new)| puts "gizzmo copy #{old} #{new}" }
shards.map {|(old, new)| puts "gizzmo copy #{old} #{new}" }
end
end

Expand Down Expand Up @@ -359,8 +366,9 @@ def run
displayed = {}
overlaps.sort_by{|hosts, count| count }.reverse.each do |(host_a, host_b), count|
next if !host_a || !host_b || displayed[host_a] || displayed[host_b]
id_a = ids_by_host[host_a].first
id_b = ids_by_host[host_b].first
id_a = ids_by_host[host_a].find{|id| service.list_upward_links(id).size > 0 }
id_b = ids_by_host[host_b].find{|id| service.list_upward_links(id).size > 0 }
next unless id_a && id_b
weight_a = service.list_upward_links(id_a).first.weight
weight_b = service.list_upward_links(id_b).first.weight
if weight_a > weight_b
Expand Down
6 changes: 5 additions & 1 deletion lib/gizzmo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def separators(opts, string)
opts.banner = "Usage: #{zero} rebalance"
separators(opts, DOC_STRINGS["rebalance"])

opts.on("-w", "--write-only=CLASS") do |w|
subcommand_options.write_only_shard = w
end

opts.on("-h", "--hosts=list") do |h|
subcommand_options.hosts = h
end
Expand Down Expand Up @@ -158,7 +162,7 @@ def separators(opts, string)
separators(opts, DOC_STRINGS["reload"])
end,
'addlink' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} link PARENT_SHARD_ID CHILD_SHARD_ID WEIGHT"
opts.banner = "Usage: #{zero} addlink PARENT_SHARD_ID WEIGHT"
separators(opts, DOC_STRINGS["addlink"])
end,
'unlink' => OptionParser.new do |opts|
Expand Down

0 comments on commit 82f238a

Please sign in to comment.