Permalink
Browse files

Do line-only-buffering of log entries, and name all retryable operations

  • Loading branch information...
1 parent 2bbf8fc commit 0c2d781325da2f96bbcaec1bd78ef1982abdd6f4 @stuhood stuhood committed May 9, 2012
Showing with 14 additions and 11 deletions.
  1. +13 −11 lib/gizzard/nameserver.rb
  2. +1 −0 lib/gizzard/thrift.rb
View
@@ -145,31 +145,33 @@ def initialize(*hosts)
end
def get_shards(ids)
- ids.map {|id| with_retry(1) { random_client.get_shard(id) } }
+ ids.map {|id| with_retry("get_shards", 1) { random_client.get_shard(id) } }
end
def reload_updated_forwardings
- on_all_servers "reload_updated_forwardings" do |c|
- with_retry(MAX_BACKOFF_SECS/4) { c.reload_updated_forwardings }
+ opname = "reload_updated_forwardings"
+ on_all_servers opname do |c|
+ with_retry(opname, MAX_BACKOFF_SECS/4) { c.reload_updated_forwardings }
end
end
def reload_config
- on_all_servers "reload_config" do |c|
- with_retry(MAX_BACKOFF_SECS/4) { c.reload_config }
+ opname = "reload_config"
+ on_all_servers opname do |c|
+ with_retry(opname, MAX_BACKOFF_SECS/4) { c.reload_config }
end
end
def copy_shard(*shards)
- with_retry(MAX_BACKOFF_SECS/2) { random_client.copy_shard(*shards) }
+ with_retry("copy_shard", MAX_BACKOFF_SECS/2) { random_client.copy_shard(*shards) }
end
def repair_shards(*shards)
- with_retry(MAX_BACKOFF_SECS/2) { random_client.repair_shard(*shards) }
+ with_retry("repair_shards", MAX_BACKOFF_SECS/2) { random_client.repair_shard(*shards) }
end
def diff_shards(*shards)
- with_retry(MAX_BACKOFF_SECS/2) { random_client.diff_shards(*shards) }
+ with_retry("diff_shards", MAX_BACKOFF_SECS/2) { random_client.diff_shards(*shards) }
end
def respond_to?(method)
@@ -180,7 +182,7 @@ def method_missing(method, *args, &block)
if client.respond_to?(method)
# operations without specialized backoff use a backoff which assumes cheap, easily
# retryable operations: if this isn't the case, methods should specialize as above
- with_retry(0.1) { random_client.send(method, *args, &block) }
+ with_retry(method, 0.1) { random_client.send(method, *args, &block) }
else
super
end
@@ -297,11 +299,11 @@ def create_client(host)
private
- def with_retry(min_backoff_secs)
+ def with_retry(opname, min_backoff_secs)
times ||= @retries
yield
rescue Exception => e
- STDERR.puts "\nException: #{e.class}: #{e.description rescue "(no description)"}"
+ STDERR.puts "\nException for #{opname}: #{e.class}: #{e.description rescue "(no description)"}"
STDERR.puts "Retrying #{times} more time#{'s' if times > 1}..." if times > 0
times -= 1
sleep_time = [min_backoff_secs, MAX_BACKOFF_SECS / [times, 1].max].max
View
@@ -209,6 +209,7 @@ def _proxy(method_name, *args)
puts "Skipped writing: #{printable(method_name, args)}"
else
@log.puts printable(method_name, args, true)
+ @log.flush
super(method_name, *args)
end
end

0 comments on commit 0c2d781

Please sign in to comment.