On Mon, Aug 31, 2009 at 01:40:34PM -0400, Wietse Venema wrote:
> > We just pass a list of servers to the LDAP library.
> >
> > Perhaps the simplest enhancement would be to "rotate" the server list
> > when a query times out, before asking the LDAP library to re-connect.
> >
> > server-list before time-out: s1 s2 ... sN
> > server-list after time-out: s2 ... sN s1
> >
> > Any other suggestions?
>
> Reversing the list may get a quicker recovery when there are more
> than 2 servers, and the time-out happens somewhere in the middle.
>
> When there are 2 servers, then rotating is equivalent to reversing.
I am reluctant to reverse the list, because this gives us only two
possible orders (as opposed to N orders with N elements), and we are I
think promising the user to use servers in the order specified.
The rotate code is simple:
Index: src/global/dict_ldap.c
--- src/global/dict_ldap.c 27 Apr 2009 03:36:00 -0000 1.1.1.1
+++ src/global/dict_ldap.c 31 Aug 2009 18:07:17 -0000
@@ -570,7 +570,26 @@
#endif
-/* Establish a connection to the LDAP server. */
+/* dict_ldap_rotate - rotate server list */
+
+static void dict_ldap_rotate(DICT_LDAP *dict_ldap)
+{
+ char *s = dict_ldap->server_host;
+ char *s1 = mystrtok(&s, " "); /* SPC separated post initial parse */
+
+ /*
+ * If more than one LDAP server specified, rotate the first one to the end
+ * of the list.
+ */
+ if (*s) {
+ s = concatenate(s, " ", s1, (char *)0);
+ myfree(dict_ldap->server_host);
+ dict_ldap->server_host = s;
+ }
+}
+
+/* dict_ldap_connect - Establish a connection to the LDAP server. */
+
static int dict_ldap_connect(DICT_LDAP *dict_ldap)
{
const char *myname = "dict_ldap_connect";
@@ -620,6 +639,13 @@
dict_errno = DICT_ERR_RETRY;
return (-1);
}
+
+ /*
+ * The current connection has just saved the server list.
+ * Rotate the server list for any future connection attempts.
+ */
+ dict_ldap_rotate(dict_ldap);
+
mytimeval.tv_sec = dict_ldap->timeout;
mytimeval.tv_usec = 0;
if (ldap_set_option(dict_ldap->ld, LDAP_OPT_NETWORK_TIMEOUT, &mytimeval) !=
--
Viktor.
Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.
To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:[email protected]?body=unsubscribe%20postfix-users>
If my response solves your problem, the best way to thank me is to not
send an "it worked, thanks" follow-up. If you must respond, please put
"It worked, thanks" in the "Subject" so I can delete these quickly.