Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

report and drill apparently work

  • Loading branch information...
commit 47a1fc83dacfcc29ed7ef5e69e9bb20bb5623bc8 1 parent 3886188
Kyle Maxwell authored
Showing with 31 additions and 39 deletions.
  1. +25 −37 lib/gizzard/commands.rb
  2. +6 −2 lib/gizzmo.rb
View
62 lib/gizzard/commands.rb
@@ -396,38 +396,13 @@ def run
end
group(things).each do |string, things|
- puts "=== " + ::Digest::MD5.hexdigest(string)[0..10] + ": #{things.length}" + " ===================="
+ puts "=== " + sign(string) + ": #{things.length}" + " ===================="
puts string
end
-
- # def run
- # @roots = []
- # argv.each do |arg|
- # @id = ShardId.parse(arg)
- # @roots += roots_of(@id)
- # end
- # @roots.uniq.each do |root|
- # output root.to_unix
- # down(root, 1)
- # end
- # end
- #
- # def roots_of(id)
- # links = service.list_upward_links(id)
- # if links.empty?
- # [id]
- # else
- # 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
- # output printable
- # down(link.down_id, depth + 1)
- # end
- # end
+ end
+
+ def sign(string)
+ ::Digest::MD5.hexdigest(string)[0..10]
end
def group(arr)
@@ -435,23 +410,23 @@ def group(arr)
m[e] ||= []
m[e] << e
m
- end
+ end.to_a.sort_by{|k, v| v.length}.reverse
end
- def parse(obj, id = nil, depth = 0)
+ def parse(obj, id = nil, depth = 0, sub = true)
case obj
when Hash
- id, prefix = parse(obj.keys.first, id, depth)
- [prefix] + parse(obj.values.first, id, depth + 1)
+ id, prefix = parse(obj.keys.first, id, depth, sub)
+ [prefix] + parse(obj.values.first, id, depth + 1, sub)
when String
host, prefix = obj.split("/")
- host = "db" if host != "localhost"
+ host = "db" if host != "localhost" && sub
id ||= prefix[/\w+ward_\d+_\d+/]
- prefix = (" " * depth) + host + "/" + prefix.sub(id, "[ID]")
+ prefix = (" " * depth) + host + "/" + (sub ? prefix.sub(id, "[ID]") : prefix)
[id, prefix]
when Array
obj.map do |e|
- parse e, id, depth
+ parse e, id, depth, sub
end
end
end
@@ -463,6 +438,19 @@ def down(id)
{id.to_unix => vals}
end
end
+
+ class DrillCommand < ReportCommand
+ def run
+ signature = @argv.shift
+ @argv.map do |shard|
+ if sign(parse(down(ShardId.parse(shard))).join("\n")) == signature
+ puts parse(down(ShardId.parse(shard)), nil, 0, false).join("\n")
+ end
+ end
+ end
+ end
+
+
class FindCommand < ShardCommand
def run
View
8 lib/gizzmo.rb
@@ -162,6 +162,10 @@ def separators(opts, string)
opts.banner = "Usage: #{zero} reload"
separators(opts, DOC_STRINGS["reload"])
end,
+ 'drill' => OptionParser.new do |opts|
+ opts.banner = "Usage: #{zero} drill SIGNATURE"
+ separators(opts, DOC_STRINGS["drill"])
+ end,
'addlink' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} addlink PARENT_SHARD_ID CHILD_SHARD_ID WEIGHT"
separators(opts, DOC_STRINGS["addlink"])
@@ -339,12 +343,12 @@ def custom_timeout(seconds)
begin
require "rubygems"
require "system_timer"
- SystemTimer.timeout_after(seconds) do
+ SystemTimer.timeout_after(seconds.to_i) do
yield
end
rescue LoadError
require "timeout"
- Timeout.timeout(seconds) do
+ Timeout.timeout(seconds.to_i) do
yield
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.