whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit 9de053a: retry once per host (min 2), with delay
Date Fri, 05 Feb 2016 13:11:01 GMT
Commit 9de053ae07ee30e521df7f4e46322fd71dac1b01:
    retry once per host (min 2), with delay


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
lib/whimsy/asf/ldap.rb                                       | +++++ ----
------------------------------------------------------------
33 changes: 18 additions, 15 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index d326cf2..17fcd27 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -122,7 +122,7 @@ def self.ldap
     @ldap || self.init_ldap
   end
 
-  # search with a scope of one
+  # search with a scope of one, with automatic retry/failover
   def self.search_one(base, filter, attrs=nil)
 
     target = @ldap.get_option(::LDAP::LDAP_OPT_HOST_NAME) rescue '?'
@@ -131,23 +131,26 @@ def self.search_one(base, filter, attrs=nil)
 
     Wunderbar.info "[#{target}] #{cmd}"
 
-    # simple-minded single retry
+    # retry once per host, with a minimum of two retries
+    attempts_left = [ASF::LDAP.hosts.length, 2].min
     begin
-      _search_one(base, filter, attrs)
+      attempts_left -= 1
+      init_ldap unless @ldap
+      return [] unless @ldap
+
+      result = @ldap.search2(base, ::LDAP::LDAP_SCOPE_ONELEVEL, filter, attrs)
     rescue Exception => re
-      Wunderbar.warn "[#{target}] => #{re.inspect} for #{cmd}, retrying ..."
-      @ldap.unbind rescue nil
-      @ldap = false # force new connection
-      # Let this one fail 
-      _search_one(base, filter, attrs)
+      if attempts_left == 0
+        Wunderbar.error "[#{target}] => #{re.inspect} for #{cmd}"
+        raise
+      else
+        Wunderbar.warn "[#{target}] => #{re.inspect} for #{cmd}, retrying ..."
+        @ldap.unbind rescue nil
+        @ldap = nil # force new connection
+        sleep 1
+        retry
+      end
     end
-  end
-
-  def self._search_one(base, filter, attrs)
-    init_ldap unless @ldap
-    return [] unless @ldap
-
-    result = @ldap.search2(base, ::LDAP::LDAP_SCOPE_ONELEVEL, filter, attrs)
 
     result.map! {|hash| hash[attrs]} if String === attrs
 

Mime
View raw message