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

Commit

Permalink
add back forwardings filter by table_id. more robust retry
Browse files Browse the repository at this point in the history
  • Loading branch information
freels committed Nov 5, 2010
1 parent 411cec7 commit 323f84e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/gizzard/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def output(string)
end
end
end

class RetryProxy
def initialize(retries, object)
@inner = object
@retries_left = retries
end

def method_missing(*args)
@inner.send(*args)
rescue
Expand All @@ -63,7 +63,7 @@ def method_missing(*args)

class ShardCommand < Command
def self.make_service(global_options, log)
RetryProxy.new global_options.retry.to_i,
RetryProxy.new global_options.retry.to_i,
Gizzard::Thrift::ShardManager.new(global_options.host, global_options.port, log, global_options.dry)
end
end
Expand Down Expand Up @@ -680,7 +680,7 @@ def self.make_service(global_options, log)
def run
puts "querying nameserver..."
table_id = (@argv.first || 0).to_i
templates = nameserver.manifest.templates.inject({}) do |h, (t, fs)|
templates = nameserver.manifest(table_id).templates.inject({}) do |h, (t, fs)|
h.update t.to_config.inspect => fs
end

Expand Down
14 changes: 8 additions & 6 deletions lib/gizzard/nameserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Gizzard
class Nameserver

DEFAULT_PORT = 7917
RETRIES = 3
PARALLELISM = 20
RETRIES = 20
PARALLELISM = 10

attr_reader :hosts, :logfile, :dryrun
alias dryrun? dryrun
Expand Down Expand Up @@ -68,8 +68,8 @@ def method_missing(method, *args, &block)
client.respond_to?(method) ? with_retry { client.send(method, *args, &block) } : super
end

def manifest
Manifest.new(self)
def manifest(table_id=nil)
Manifest.new(self, table_id)
end

private
Expand All @@ -95,7 +95,7 @@ def with_retry
yield
rescue ThriftClient::Simple::ThriftException, NoMethodError
times -= 1
(times < 0) ? raise : (sleep 0.1; retry)
(times < 0) ? raise : (sleep 2; retry)
end


Expand All @@ -109,9 +109,11 @@ def id; info.id; end
class Manifest
attr_reader :forwardings, :links, :shard_infos, :trees, :templates

def initialize(nameserver)
def initialize(nameserver, table_id=nil)
@forwardings = nameserver.get_forwardings

@forwardings.reject! {|f| f.table_id != table_id } if table_id

@links = nameserver.get_all_links(forwardings).inject({}) do |h, link|
(h[link.up_id] ||= []) << [link.down_id, link.weight]; h
end
Expand Down

0 comments on commit 323f84e

Please sign in to comment.