Permalink
Browse files

repair

  • Loading branch information...
1 parent 9b86e82 commit 28df0dcc27bd7ed71cb3d9114246ec95c9b890f7 Kyle Maxwell committed Aug 24, 2010
Showing with 39 additions and 3 deletions.
  1. +30 −2 lib/gizzard/commands.rb
  2. +9 −1 lib/gizzmo.rb
View
@@ -229,6 +229,28 @@ def run
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)
@@ -267,12 +289,18 @@ def initialize(name)
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
@@ -284,16 +312,16 @@ 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}' #{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
View
@@ -81,8 +81,16 @@ def separators(opts, string)
separators(opts, DOC_STRINGS["report"])
end,
'rebalance' => OptionParser.new do |opts|
- opts.banner = "Usage: #{zero} rebalance RUBY_REGEX"
+ opts.banner = "Usage: #{zero} rebalance"
separators(opts, DOC_STRINGS["rebalance"])
+
+ opts.on("-h", "--hosts=list") do |h|
+ subcommand_options.hosts = h
+ end
+ end,
+ 'repair' => OptionParser.new do |opts|
+ opts.banner = "Usage: #{zero} repair MASTER SLAVE [MASTER SLAVE...]"
+ separators(opts, DOC_STRINGS["repair"])
end,
'pair' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} pair"

0 comments on commit 28df0dc

Please sign in to comment.