about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-08-26 21:38:54 +0000
committerEric Wong <e@80x24.org>2016-08-31 02:48:17 +0000
commit622d5ab17846bc58c2e0cfd98b3a8b73ad341c0d (patch)
tree68929dfbff84640fc1ea8a8264ee62ed04a9b42d
parentcea8d77382e42132f4a433d59a5dc37fcc295ec3 (diff)
downloadmogilefs-client-622d5ab17846bc58c2e0cfd98b3a8b73ad341c0d.tar.gz
This can be useful for specifying a different timeout for
establishing a connection.  Some requests could be expensive and
want a higher :timeout measured in seconds, while the time to
establish a TCP connection on a healthy LAN could be less than
a millisecond.

This defaults to 3s to match the existing :timeout, but only
affects the amount of time the client will wait for establishing
a TCP connection to a tracker.
-rw-r--r--lib/mogilefs/backend.rb3
-rw-r--r--lib/mogilefs/client.rb4
-rw-r--r--lib/mogilefs/mogilefs.rb4
3 files changed, 9 insertions, 2 deletions
diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb
index 632d6f1..4cf2526 100644
--- a/lib/mogilefs/backend.rb
+++ b/lib/mogilefs/backend.rb
@@ -79,6 +79,7 @@ class MogileFS::Backend
 
     @mutex = Mutex.new
     @timeout = args[:timeout] || 3
+    @connect_timeout = args[:connect_timeout] || 3
     @socket = nil
     @lasterr = nil
     @lasterrstr = nil
@@ -347,7 +348,7 @@ class MogileFS::Backend
 
       begin
         addr, port = host.split(':'.freeze)
-        @socket = MogileFS::Socket.tcp(addr, port, @timeout)
+        @socket = MogileFS::Socket.tcp(addr, port, @connect_timeout)
         @active_host = host
       rescue SystemCallError, MogileFS::Timeout => err
         @dead[host] = [ MogileFS.now, err ]
diff --git a/lib/mogilefs/client.rb b/lib/mogilefs/client.rb
index 7a808f1..1e30874 100644
--- a/lib/mogilefs/client.rb
+++ b/lib/mogilefs/client.rb
@@ -27,6 +27,7 @@ class MogileFS::Client
     @readonly = args[:readonly] ? true : false
     @timeout = args[:timeout]
     @fail_timeout = args[:fail_timeout]
+    @connect_timeout = args[:connect_timeout]
 
     reload
   end
@@ -37,7 +38,8 @@ class MogileFS::Client
   def reload
     @backend = MogileFS::Backend.new(:hosts => @hosts,
                                      :timeout => @timeout,
-                                     :fail_timeout => @fail_timeout)
+                                     :fail_timeout => @fail_timeout,
+                                     :connect_timeout => @connect_timeout)
   end
 
   ##
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index f454a0f..d17f0b8 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -64,6 +64,10 @@ class MogileFS::MogileFS < MogileFS::Client
   #   Timeout for tracker backend responses.
   #   Defaults to 3 seconds.
   #
+  # [:connect_timeout => Integer]
+  #
+  #   Timeout for connecting to a tracker
+  #   Defaults to 3 seconds
   def initialize(args = {})
     @domain = args[:domain]