about summary refs log tree commit homepage
path: root/lib/mogilefs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mogilefs')
-rw-r--r--lib/mogilefs/backend.rb7
-rw-r--r--lib/mogilefs/client.rb5
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb
index f33c42d..a45cbed 100644
--- a/lib/mogilefs/backend.rb
+++ b/lib/mogilefs/backend.rb
@@ -70,6 +70,7 @@ class MogileFS::Backend
 
   def initialize(args)
     @hosts = args[:hosts]
+    @fail_timeout = args[:fail_timeout] || 5
     raise ArgumentError, "must specify at least one host" unless @hosts
     raise ArgumentError, "must specify at least one host" if @hosts.empty?
     unless @hosts == @hosts.select { |h| h =~ /:\d+$/ } then
@@ -361,17 +362,15 @@ class MogileFS::Backend
   def socket
     return @socket if @socket and not @socket.closed?
 
-    now = Time.now
-
     @hosts.shuffle.each do |host|
-      next if @dead.include?(host) and @dead[host][0] > now - 5
+      next if dead = @dead[host] and dead[0] > (Time.now - @fail_timeout)
 
       begin
         addr, port = host.split(/:/)
         @socket = MogileFS::Socket.tcp(addr, port, @timeout)
         @active_host = host
       rescue SystemCallError, MogileFS::Timeout => err
-        @dead[host] = [ now, err ]
+        @dead[host] = [ Time.now, err ]
         next
       end
 
diff --git a/lib/mogilefs/client.rb b/lib/mogilefs/client.rb
index 696f31f..7a808f1 100644
--- a/lib/mogilefs/client.rb
+++ b/lib/mogilefs/client.rb
@@ -26,6 +26,7 @@ class MogileFS::Client
     @hosts = args[:hosts]
     @readonly = args[:readonly] ? true : false
     @timeout = args[:timeout]
+    @fail_timeout = args[:fail_timeout]
 
     reload
   end
@@ -34,7 +35,9 @@ class MogileFS::Client
   # Creates a new MogileFS::Backend.
 
   def reload
-    @backend = MogileFS::Backend.new :hosts => @hosts, :timeout => @timeout
+    @backend = MogileFS::Backend.new(:hosts => @hosts,
+                                     :timeout => @timeout,
+                                     :fail_timeout => @fail_timeout)
   end
 
   ##