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

Commit

Permalink
Add support for slave shards
Browse files Browse the repository at this point in the history
  • Loading branch information
Stu Hood committed Apr 26, 2012
1 parent 54ce7ce commit e2d9ea3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
9 changes: 6 additions & 3 deletions lib/gizzard/nameserver.rb
Expand Up @@ -22,28 +22,31 @@ def parse_enumeration(table_prefix)
"ReadOnlyShard",
"WriteOnlyShard",
"BlockedShard",
"SlaveShard",
]

REPLICATING_SHARD_TYPES = ["ReplicatingShard", "FailingOverShard"]

TRANSITIONAL_SHARD_TYPES = ["BlockedShard"]

INVALID_COPY_TYPES = ["ReadOnlyShard", "BlackHoleShard", "BlockedShard", "WriteOnlyShard"]
INVALID_COPY_TYPES = ["ReadOnlyShard", "BlackHoleShard", "BlockedShard", "WriteOnlyShard", "SlaveShard"]

SHARD_SUFFIXES = {
"FailingOverShard" => 'replicating',
"ReplicatingShard" => 'replicating',
"ReadOnlyShard" => 'read_only',
"WriteOnlyShard" => 'write_only',
"BlockedShard" => 'blocked'
"BlockedShard" => 'blocked',
"SlaveShard" => 'slave',
}

SHARD_TAGS = {
"ReplicatingShard" => 'replicating',
"ReadOnlyShard" => 'read_only',
"WriteOnlyShard" => 'write_only',
"BlockedShard" => 'blocked',
"BlackHoleShard" => 'blackhole'
"BlackHoleShard" => 'blackhole',
"SlaveShard" => 'slave',
}

def id; info.id end
Expand Down
32 changes: 24 additions & 8 deletions test/gizzmo_spec.rb
Expand Up @@ -78,20 +78,35 @@ def sio(string="")
ns.create_shard info("localhost", "t_0_000", "TestShard")
ns.create_shard info("localhost", "t_0_000_replicating", "ReplicatingShard")
ns.add_link id("localhost", "t_0_000_replicating"), id("localhost", "t_0_000"), 1

gizzmo "wrap BlockedShard localhost/t_0_000"
end

it "wrap wraps a shard" do
nameserver_db[:shards].should == [info("localhost", "t_0_000", "TestShard"),
info("localhost", "t_0_000_blocked", "BlockedShard"),
info("localhost", "t_0_000_replicating", "ReplicatingShard")]
describe "wrap wraps a shard" do
it "with BlockedShard" do
gizzmo "wrap BlockedShard localhost/t_0_000"
nameserver_db[:shards].to_set.should == shards_with_wrapper("BlockedShard", "blocked")
nameserver_db[:links].to_set.should == links_with_wrapper("blocked")
end

nameserver_db[:links].should == [link(id("localhost", "t_0_000_blocked"), id("localhost", "t_0_000"), 1),
link(id("localhost", "t_0_000_replicating"), id("localhost", "t_0_000_blocked"), 1)]
it "with SlaveShard" do
gizzmo "wrap SlaveShard localhost/t_0_000"
nameserver_db[:shards].to_set.should == shards_with_wrapper("SlaveShard", "slave")
nameserver_db[:links].to_set.should == links_with_wrapper("slave")
end

def shards_with_wrapper(clazz, suffix)
[info("localhost", "t_0_000", "TestShard"),
info("localhost", "t_0_000_#{suffix}", clazz),
info("localhost", "t_0_000_replicating", "ReplicatingShard")].to_set
end

def links_with_wrapper(suffix)
[link(id("localhost", "t_0_000_#{suffix}"), id("localhost", "t_0_000"), 1),
link(id("localhost", "t_0_000_replicating"), id("localhost", "t_0_000_#{suffix}"), 1)].to_set
end
end

it "unwrap unwraps a shard" do
gizzmo "wrap BlockedShard localhost/t_0_000"
gizzmo "unwrap localhost/t_0_000_blocked"

nameserver_db[:shards].should == [info("localhost", "t_0_000", "TestShard"),
Expand All @@ -101,6 +116,7 @@ def sio(string="")
end

it "unwrap doesn't unwrap a top level shard or a leaf" do
gizzmo "wrap BlockedShard localhost/t_0_000"
gizzmo "unwrap localhost/t_0_000"
gizzmo "unwrap localhost/t_0_000_replicating"

Expand Down

0 comments on commit e2d9ea3

Please sign in to comment.