lib/gizzard/commands.rb in gizzmo-0.5.0 vs lib/gizzard/commands.rb in gizzmo-0.6.0
- old
+ new
@@ -227,10 +227,32 @@
shard_info = service.get_shard(ShardId.parse(shard_id))
output shard_info.to_unix
end
end
end
+
+ class RepairCommand < ShardCommand
+ def run
+ args = @argv.dup.map{|a| a.split(/\s+/)}.flatten
+ pairs = []
+ loop do
+ a = args.shift
+ b = args.shift
+ break unless a && b
+ pairs << [a, b]
+ end
+ pairs.each do |master, slave|
+ puts "#{master} #{slave}"
+ mprefixes = service.shards_for_hostname(master).map{|s| s.id.table_prefix}
+ sprefixes = service.shards_for_hostname(slave).map{|s| s.id.table_prefix}
+ delta = mprefixes - sprefixes
+ delta.each do |prefix|
+ puts "gizzmo copy #{master}/#{prefix} #{slave}/#{prefix}"
+ end
+ end
+ end
+ end
class WrapCommand < ShardCommand
def self.derive_wrapper_shard_id(shard_info, wrapping_class_name)
prefix_prefix = wrapping_class_name.split(".").last.downcase.gsub("shard", "") + "_"
ShardId.new("localhost", prefix_prefix + shard_info.id.table_prefix)
@@ -265,16 +287,22 @@
@name = name
end
end
def run
+ puts command_options.inspect
+ 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
sets = by_host.values
begin
sorted = sets.sort_by{|s| s.length }
@@ -282,19 +310,19 @@
shortest = sorted.first
shortest.push longest.pop
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}' #{old}"
+ 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}"
- puts "gizzmo delete #{old}"
end
end
end
end
end