s3-libads: Use a reducing page size to try and cope with a slow LDAP server
authorAndrew Bartlett <abartlet@samba.org>
Fri, 18 May 2012 12:01:14 +0000 (22:01 +1000)
committerKarolin Seeger <kseeger@samba.org>
Sat, 30 Jun 2012 11:44:06 +0000 (13:44 +0200)
If we cannot get 1000 users downloaded in 15seconds, try with 500, 250
and then 125 users at a time.

Andrew Bartlett
(cherry picked from commit 8572ce0e5ff17bfe0df2823078119be9182a0378)

source3/include/ads.h
source3/libads/ads_struct.c
source3/libads/ldap.c
source3/libads/ldap_utils.c

index 62d51ce03b58c15b428828b5bb7b674559928bd6..ff3dc123b48948bc27d478b40b1d862bde3d1c4e 100644 (file)
@@ -108,6 +108,7 @@ typedef struct ads_struct {
                time_t current_time;
                char *schema_path;
                char *config_path;
+               int ldap_page_size;
        } config;
 
        /* info about the current LDAP connection */
index aef35ad822e08ff67cfff1b4c200dbe086d1169f..2d9ea17faac8147c44e988359ddea3a40cc32ff3 100644 (file)
@@ -148,6 +148,10 @@ ADS_STRUCT *ads_init(const char *realm,
 
        ads->auth.flags = wrap_flags;
 
+       /* Start with a page size of 1000 when the connection is new,
+        * we will drop it by half we get a timeout.   */
+       ads->config.ldap_page_size     = 1000;
+
        return ads;
 }
 
index f18ded15d9f5cbb23336865a0c93ebd24454e424..99ec2e46dc6d0edf15d500ba3cc99e507df2f0ea 100644 (file)
@@ -924,11 +924,11 @@ static ADS_STATUS ads_do_paged_search_args(ADS_STRUCT *ads,
 
        cookie_be = ber_alloc_t(LBER_USE_DER);
        if (*cookie) {
-               ber_printf(cookie_be, "{iO}", (ber_int_t) 1000, *cookie);
+               ber_printf(cookie_be, "{iO}", (ber_int_t) ads->config.ldap_page_size, *cookie);
                ber_bvfree(*cookie); /* don't need it from last time */
                *cookie = NULL;
        } else {
-               ber_printf(cookie_be, "{io}", (ber_int_t) 1000, "", 0);
+               ber_printf(cookie_be, "{io}", (ber_int_t) ads->config.ldap_page_size, "", 0);
        }
        ber_flatten(cookie_be, &cookie_bv);
        PagedResults.ldctl_oid = CONST_DISCARD(char *, ADS_PAGE_CTL_OID);
index 871449a81af4bc8233b1ab2571d432757afae890..dee3c03a2166dd22febea561977cc62f28fd9233 100644 (file)
@@ -68,6 +68,13 @@ static ADS_STATUS ads_do_search_retry_internal(ADS_STRUCT *ads, const char *bind
 
        while (--count) {
 
+               if (NT_STATUS_EQUAL(ads_ntstatus(status), NT_STATUS_IO_TIMEOUT) && ads->config.ldap_page_size >= 250) {
+                       int new_page_size = (ads->config.ldap_page_size / 2);
+                       DEBUG(1, ("Reducing LDAP page size from %d to %d due to IO_TIMEOUT\n",
+                                 ads->config.ldap_page_size, new_page_size));
+                       ads->config.ldap_page_size = new_page_size;
+               }
+
                if (*res) 
                        ads_msgfree(ads, *res);
                *res = NULL;