diff --git a/lib/gizzard/commands.rb b/lib/gizzard/commands.rb index bdde150..e6daf11 100644 --- a/lib/gizzard/commands.rb +++ b/lib/gizzard/commands.rb @@ -503,22 +503,21 @@ def run end end - class RepairShardCommand < Command + class RepairShardsCommand < Command def run shard_id_strings = @argv help!("Requires at least two shard ids") unless shard_id_strings.size >= 2 - shard_id = shard_id_strings.map{|s| ShardId.parse(s)} - manager.repair_shard(shard_id) + shard_ids = shard_id_strings.map{|s| ShardId.parse(s)} + manager.repair_shards(shard_ids) end end class DiffShardsCommand < Command def run - from_shard_id_string, to_shard_id_string = @argv - help!("Requires source, destination shard id") unless from_shard_id_string && to_shard_id_string - from_shard_id = ShardId.parse(from_shard_id_string) - to_shard_id = ShardId.parse(to_shard_id_string) - manager.diff_shards([from_shard_id, to_shard_id]) + shard_id_strings = @argv + help!("Requires at least two shard ids") unless shard_id_strings.size >= 2 + shard_ids = shard_id_strings.map{|s| ShardId.parse(s)} + manager.diff_shards(shard_ids) end end diff --git a/lib/gizzard/nameserver.rb b/lib/gizzard/nameserver.rb index 33b8d86..bcb295b 100644 --- a/lib/gizzard/nameserver.rb +++ b/lib/gizzard/nameserver.rb @@ -123,9 +123,9 @@ def copy_shard(from_shard_id, to_shard_id) with_retry { c.copy_shard(from_shard_id, to_shard_id) } end - def repair_shard(*shards) + def repair_shards(*shards) c = random_client - with_retry { c.repair_shard(*shards) } + with_retry { c.repair_shards(*shards) } end def diff_shards(*shards) diff --git a/lib/gizzard/transformation.rb b/lib/gizzard/transformation.rb index 1867cb0..31d4f79 100644 --- a/lib/gizzard/transformation.rb +++ b/lib/gizzard/transformation.rb @@ -13,7 +13,7 @@ class Transformation Op::AddLink => "add_link", Op::SetForwarding => "set_forwarding", Op::CopyShard => "copy_shard", - Op::RepairShard => "repair_shard", + Op::RepairShards => "repair_shards", Op::DiffShards => "diff_shards" } @@ -33,7 +33,7 @@ class Transformation Op::RemoveLink => 5, Op::DeleteShard => 6, Op::CopyShard => 7, - Op::RepairShard => 8, + Op::RepairShards => 8, Op::DiffShards => 9 } @@ -94,6 +94,7 @@ def inspect prepare_inspect = op_inspect[:prepare].empty? ? "" : " PREPARE\n#{op_inspect[:prepare]}\n" copy_inspect = op_inspect[:copy].empty? ? "" : " COPY\n#{op_inspect[:copy]}\n" repair_inspect = op_inspect[:repair].empty? ? "" : " REPAIR\n#{op_inspect[:repair]}\n" + diff_inspect = op_inspect[:diff].empty? ? "" : " DIFF\n#{op_inspect[:diff]}\n" cleanup_inspect = op_inspect[:cleanup].empty? ? "" : " CLEANUP\n#{op_inspect[:cleanup]}\n" op_inspect = [prepare_inspect, copy_inspect, repair_inspect, cleanup_inspect].join @@ -129,7 +130,7 @@ def collapse_jobs(jobs) end def expand_jobs(jobs) - expanded = jobs.inject({:prepare => [], :copy => [], :repair => [], :cleanup => []}) do |ops, job| + expanded = jobs.inject({:prepare => [], :copy => [], :repair => [], :cleanup => [], :diff => []}) do |ops, job| job_ops = job.expand(self.copy_source, involved_in_copy?(job.template), @copy_dest_wrapper) ops.update(job_ops) {|k,a,b| a + b } end diff --git a/lib/gizzard/transformation_op.rb b/lib/gizzard/transformation_op.rb index ef792c2..c3018e9 100644 --- a/lib/gizzard/transformation_op.rb +++ b/lib/gizzard/transformation_op.rb @@ -52,26 +52,22 @@ def apply(nameserver, table_id, base_id, table_prefix, translations) end end - class RepairShard < BaseOp + class RepairShards < BaseOp attr_reader :from, :to alias template to - def initialize(from, to) - @from = from - @to = to + def initialize(*shards) + @shards = shards end def expand(*args); { :repair => [self] } end def involved_shards(table_prefix, translations) - [to.to_shard_id(table_prefix, translations)] + shards.map{|s| s.to_shard_id(table_prefix, translations)} end def apply(nameserver, table_id, base_id, table_prefix, translations) - from_shard_id = from.to_shard_id(table_prefix, translations) - to_shard_id = to.to_shard_id(table_prefix, translations) - - nameserver.repair_shard(from_shard_id, to_shard_id) + nameserver.repair_shards(involved_shards(table_prefix, translations)) end end diff --git a/lib/gizzmo.rb b/lib/gizzmo.rb index 8b4ae7b..699bbd5 100644 --- a/lib/gizzmo.rb +++ b/lib/gizzmo.rb @@ -24,8 +24,8 @@ class HelpNeededError < RuntimeError; end "markbusy" => "Mark a shard as busy.", "pair" => "Report the replica pairing structure for a list of hosts.", "reload" => "Instruct application servers to reload the nameserver state.", - "repair-shards" => "Repair shard", - "diff-shards" => "Diff shards", + "repair-shards" => "Reconcile n shards by detecting differences and rescheduling them", + "diff-shards" => "Log differences between n shards", "report" => "Show each unique replica structure for a given list of shards. Usually this shard list comes from << gizzmo forwardings | awk '{ print $3 }' >>.", "setup-replica" => "Add a replica to be parallel to an existing replica, in write-only mode, ready to be copied to.", "wrap" => "Wrapping creates a new (virtual, e.g. blocking, replicating, etc.) shard, and relinks SHARD_ID_TO_WRAP's parent links to run through the new shard.", diff --git a/test/gizzmo_spec.rb b/test/gizzmo_spec.rb index ae1de8f..257aecc 100644 --- a/test/gizzmo_spec.rb +++ b/test/gizzmo_spec.rb @@ -318,7 +318,11 @@ def nameserver_db it "works" end - describe "repair-shard" do + describe "repair-shards" do + it "works" + end + + describe "diff-shards" do it "works" end