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

Commit

Permalink
resolves 'Gizzmo subtree doesn't reach grandparents'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Maxwell committed Jul 14, 2010
1 parent 7e7d1c8 commit 2e72256
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/gizzard/commands.rb
Expand Up @@ -65,23 +65,23 @@ def run
@roots = []
argv.each do |arg|
@id = ShardId.parse(arg)
@roots << up(@id)
@roots += roots_of(@id)
end
@roots.uniq.each do |root|
output root.to_unix
down(root, 1)
end
end

def up(id)
def roots_of(id)
links = service.list_upward_links(id)
if links.empty?
id
[id]
else
links.map { |link| link.up_id }.find { |up_id| up(up_id) }
links.map { |link| roots_of(link.up_id) }.flatten
end
end

def down(id, depth = 0)
service.list_downward_links(id).map do |link|
printable = " " * depth + link.down_id.to_unix
Expand Down
10 changes: 10 additions & 0 deletions test/expected/deep.txt
@@ -0,0 +1,10 @@
localhost/table_deep_repl_0
localhost/table_deep_repl_1
localhost/table_deep_repl_2
localhost/table_deep_repl_3
localhost/table_deep_repl_4
localhost/table_deep_repl_5
localhost/table_deep_repl_6
localhost/table_deep_repl_7
localhost/table_deep_repl_8
localhost/table_deep_repl_9
2 changes: 0 additions & 2 deletions test/expected/subtree-info.txt
Expand Up @@ -29,5 +29,3 @@ localhost/table_b_8 com.twitter.service.flock.edges.SqlShard unbusy
localhost/table_repl_9 com.twitter.service.flock.edges.ReplicatingShard unbusy
localhost/table_a_9 com.twitter.service.flock.edges.SqlShard unbusy
localhost/table_b_9 com.twitter.service.flock.edges.SqlShard unbusy
localhost/replicating_table_b_0 com.twitter.service.flock.edges.ReplicatingShard unbusy
localhost/table_b_0 com.twitter.service.flock.edges.SqlShard unbusy
2 changes: 0 additions & 2 deletions test/expected/subtree.txt
Expand Up @@ -10,8 +10,6 @@ localhost/table_repl_1
localhost/table_repl_2
localhost/table_a_2
localhost/table_b_2
localhost/blocked_table_a_3
localhost/table_a_3
localhost/table_repl_4
localhost/table_a_4
localhost/table_b_4
Expand Down
11 changes: 11 additions & 0 deletions test/test.sh
Expand Up @@ -62,3 +62,14 @@ g links localhost/table_b_0 | expect empty-file.txt
g wrap com.twitter.gizzard.shards.BlockedShard localhost/table_a_3
g find -hlocalhost | xargs ../bin/gizzmo -Cconfig.yaml subtree 2>&1 | expect subtree.txt
g find -hlocalhost | ../bin/gizzmo -Cconfig.yaml subtree 2>&1 | expect subtree.txt

# test a deep tree
g create localhost "table_deep_repl_0" com.twitter.service.flock.edges.ReplicatingShard
for i in {1..9}
do
last=$((i-1))
g create localhost "table_deep_repl_$i" com.twitter.service.flock.edges.ReplicatingShard
g addlink "localhost/table_deep_repl_$last" "localhost/table_deep_repl_$i" 2
done

g subtree localhost/table_deep_repl_5 | expect deep.txt

0 comments on commit 2e72256

Please sign in to comment.