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

Commit

Permalink
proper multishard interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Hull committed Feb 7, 2011
1 parent 61208bd commit 1ce8f69
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
15 changes: 7 additions & 8 deletions lib/gizzard/commands.rb
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/gizzard/nameserver.rb
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions lib/gizzard/transformation.rb
Expand Up @@ -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"
}

Expand All @@ -33,7 +33,7 @@ class Transformation
Op::RemoveLink => 5,
Op::DeleteShard => 6,
Op::CopyShard => 7,
Op::RepairShard => 8,
Op::RepairShards => 8,
Op::DiffShards => 9
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions lib/gizzard/transformation_op.rb
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/gizzmo.rb
Expand Up @@ -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.",
Expand Down
6 changes: 5 additions & 1 deletion test/gizzmo_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit 1ce8f69

Please sign in to comment.