You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2017/12/13 16:55:48 UTC

svn commit: r1818040 - in /httpd/httpd/trunk: CHANGES modules/ldap/util_ldap.c modules/ldap/util_ldap_cache.c modules/ldap/util_ldap_cache.h modules/ldap/util_ldap_cache_mgr.c

Author: covener
Date: Wed Dec 13 16:55:48 2017
New Revision: 1818040

URL: http://svn.apache.org/viewvc?rev=1818040&view=rev
Log:
PR61891: looping over mostly full LDAP cache

  *) mod_ldap: Fix a case where a full LDAP cache would continually fail to
     purge old entries and log AH01323. PR61891.



Submitted By: Hendrik Harms <hendrik.harms gmail.com>
Committed By: covener


Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/modules/ldap/util_ldap.c
    httpd/httpd/trunk/modules/ldap/util_ldap_cache.c
    httpd/httpd/trunk/modules/ldap/util_ldap_cache.h
    httpd/httpd/trunk/modules/ldap/util_ldap_cache_mgr.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1818040&r1=1818039&r2=1818040&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Wed Dec 13 16:55:48 2017
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.1
 
+  *) mod_ldap: Fix a case where a full LDAP cache would continually fail to 
+     purge old entries and log AH01323. PR61891.  
+     [Hendrik Harms <hendrik.harms gmail.com>]
+
   *) mod_md: name change in configuration directives. The old names are still working
      in this version, so you can safely upgrade. They will give warnings in the log and
      will disappear in the immediate future. ManagedDomain is now MDomain,

Modified: httpd/httpd/trunk/modules/ldap/util_ldap.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ldap/util_ldap.c?rev=1818040&r1=1818039&r2=1818040&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ldap/util_ldap.c (original)
+++ httpd/httpd/trunk/modules/ldap/util_ldap.c Wed Dec 13 16:55:48 2017
@@ -2245,7 +2245,7 @@ static const char *util_ldap_set_opcache
         return err;
     }
 
-    st->compare_cache_ttl = atol(ttl) * 1000000;
+    st->compare_cache_ttl = atol(ttl) * APR_USEC_PER_SEC;
 
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01301)
                  "ldap cache: Setting operation cache TTL to %ld microseconds.",
@@ -2816,9 +2816,9 @@ static void *util_ldap_create_config(apr
 #endif
 
     st->cache_bytes = 500000;
-    st->search_cache_ttl = 600000000;
+    st->search_cache_ttl = 600 * APR_USEC_PER_SEC; /* 10 minutes */
     st->search_cache_size = 1024;
-    st->compare_cache_ttl = 600000000;
+    st->compare_cache_ttl = 600 * APR_USEC_PER_SEC; /* 10 minutes */
     st->compare_cache_size = 1024;
     st->connections = NULL;
     st->ssl_supported = 0;

Modified: httpd/httpd/trunk/modules/ldap/util_ldap_cache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ldap/util_ldap_cache.c?rev=1818040&r1=1818039&r2=1818040&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ldap/util_ldap_cache.c (original)
+++ httpd/httpd/trunk/modules/ldap/util_ldap_cache.c Wed Dec 13 16:55:48 2017
@@ -114,6 +114,7 @@ void util_ldap_url_node_display(request_
                    "<td nowrap>%ld</td>"
                    "<td nowrap>%ld</td>"
                    "<td nowrap>%ld</td>"
+                   "<td nowrap>%ld</td>"
                    "<td nowrap>%s</td>"
                    "</tr>",
                    node->url,
@@ -121,6 +122,7 @@ void util_ldap_url_node_display(request_
                    cache_node->size,
                    cache_node->maxentries,
                    cache_node->numentries,
+                   cache_node->ttl / APR_USEC_PER_SEC,
                    cache_node->fullmark,
                    date_str);
     }
@@ -452,6 +454,7 @@ apr_status_t util_ldap_cache_init(apr_po
     st->util_ldap_cache =
         util_ald_create_cache(st,
                               st->search_cache_size,
+                              st->search_cache_ttl,
                               util_ldap_url_node_hash,
                               util_ldap_url_node_compare,
                               util_ldap_url_node_copy,

Modified: httpd/httpd/trunk/modules/ldap/util_ldap_cache.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ldap/util_ldap_cache.h?rev=1818040&r1=1818039&r2=1818040&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ldap/util_ldap_cache.h (original)
+++ httpd/httpd/trunk/modules/ldap/util_ldap_cache.h Wed Dec 13 16:55:48 2017
@@ -46,6 +46,7 @@ struct util_ald_cache {
     unsigned long numentries;           /* Current number of cache entries */
     unsigned long fullmark;             /* Used to keep track of when cache becomes 3/4 full */
     apr_time_t marktime;                /* Time that the cache became 3/4 full */
+    unsigned long ttl;                  /* Time to live for items in cache */
     unsigned long (*hash)(void *);      /* Func to hash the payload */
     int (*compare)(void *, void *);     /* Func to compare two payloads */
     void * (*copy)(util_ald_cache_t *cache, void *); /* Func to alloc mem and copy payload to new mem */
@@ -188,6 +189,7 @@ void util_ald_cache_purge(util_ald_cache
 util_url_node_t *util_ald_create_caches(util_ldap_state_t *s, const char *url);
 util_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st,
                                 long cache_size,
+                                long cache_ttl,
                                 unsigned long (*hashfunc)(void *),
                                 int (*comparefunc)(void *, void *),
                                 void * (*copyfunc)(util_ald_cache_t *cache, void *),

Modified: httpd/httpd/trunk/modules/ldap/util_ldap_cache_mgr.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ldap/util_ldap_cache_mgr.c?rev=1818040&r1=1818039&r2=1818040&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ldap/util_ldap_cache_mgr.c (original)
+++ httpd/httpd/trunk/modules/ldap/util_ldap_cache_mgr.c Wed Dec 13 16:55:48 2017
@@ -233,15 +233,22 @@ void util_ald_cache_purge(util_ald_cache
 {
     unsigned long i;
     util_cache_node_t *p, *q, **pp;
-    apr_time_t t;
+    apr_time_t now;
 
     if (!cache)
         return;
 
-    cache->last_purge = apr_time_now();
+    now = cache->last_purge = apr_time_now();
     cache->npurged = 0;
     cache->numpurges++;
 
+    /* If the marktime is farther back than TTL from now, 
+       move the marktime forward to include additional expired entries.
+    */
+    if (now - cache->ttl > cache->marktime) {
+        cache->marktime = now - cache->ttl;
+    }
+
     for (i=0; i < cache->size; ++i) {
         pp = cache->nodes + i;
         p = *pp;
@@ -261,9 +268,9 @@ void util_ald_cache_purge(util_ald_cache
         }
     }
 
-    t = apr_time_now();
+    now = apr_time_now();
     cache->avg_purgetime =
-         ((t - cache->last_purge) + (cache->avg_purgetime * (cache->numpurges-1))) /
+         ((now - cache->last_purge) + (cache->avg_purgetime * (cache->numpurges-1))) /
          cache->numpurges;
 }
 
@@ -281,6 +288,7 @@ util_url_node_t *util_ald_create_caches(
     /* create the three caches */
     search_cache = util_ald_create_cache(st,
                       st->search_cache_size,
+                      st->search_cache_ttl,
                       util_ldap_search_node_hash,
                       util_ldap_search_node_compare,
                       util_ldap_search_node_copy,
@@ -288,6 +296,7 @@ util_url_node_t *util_ald_create_caches(
                       util_ldap_search_node_display);
     compare_cache = util_ald_create_cache(st,
                       st->compare_cache_size,
+                      st->compare_cache_ttl,
                       util_ldap_compare_node_hash,
                       util_ldap_compare_node_compare,
                       util_ldap_compare_node_copy,
@@ -295,6 +304,7 @@ util_url_node_t *util_ald_create_caches(
                       util_ldap_compare_node_display);
     dn_compare_cache = util_ald_create_cache(st,
                       st->compare_cache_size,
+                      st->compare_cache_ttl,
                       util_ldap_dn_compare_node_hash,
                       util_ldap_dn_compare_node_compare,
                       util_ldap_dn_compare_node_copy,
@@ -323,6 +333,7 @@ util_url_node_t *util_ald_create_caches(
 
 util_ald_cache_t *util_ald_create_cache(util_ldap_state_t *st,
                                 long cache_size,
+                                long cache_ttl,
                                 unsigned long (*hashfunc)(void *),
                                 int (*comparefunc)(void *, void *),
                                 void * (*copyfunc)(util_ald_cache_t *cache, void *),
@@ -381,8 +392,10 @@ util_ald_cache_t *util_ald_create_cache(
     cache->free = freefunc;
     cache->display = displayfunc;
 
+    
     cache->fullmark = cache->maxentries / 4 * 3;
     cache->marktime = 0;
+    cache->ttl = cache_ttl;
     cache->avg_purgetime = 0.0;
     cache->numpurges = 0;
     cache->last_purge = 0;
@@ -727,6 +740,10 @@ char *util_ald_cache_display(request_rec
                                "<td bgcolor='#ffffff'><font size='-1' face='Arial,Helvetica' color='#000000'><b>%ld</b></font></td>"
                                "</tr>\n"
                                "<tr>\n"
+                               "<td bgcolor='#000000'><font size='-1' face='Arial,Helvetica' color='#ffffff'><b>TTL (sec):</b></font></td>"
+                               "<td bgcolor='#ffffff'><font size='-1' face='Arial,Helvetica' color='#000000'><b>%ld</b></font></td>"
+                               "</tr>\n"
+                               "<tr>\n"
                                "<td bgcolor='#000000'><font size='-1' face='Arial,Helvetica' color='#ffffff'><b>Full Mark:</b></font></td>"
                                "<td bgcolor='#ffffff'><font size='-1' face='Arial,Helvetica' color='#000000'><b>%ld</b></font></td>"
                                "</tr>\n"
@@ -738,6 +755,7 @@ char *util_ald_cache_display(request_rec
                                util_ldap_cache->size,
                                util_ldap_cache->maxentries,
                                util_ldap_cache->numentries,
+                               util_ldap_cache->ttl / APR_USEC_PER_SEC,
                                util_ldap_cache->fullmark,
                                date_str);
 
@@ -748,6 +766,7 @@ char *util_ald_cache_display(request_rec
                              "<td><font size='-1' face='Arial,Helvetica' color='#ffffff'><b>Size</b></font></td>"
                              "<td><font size='-1' face='Arial,Helvetica' color='#ffffff'><b>Max Entries</b></font></td>"
                              "<td><font size='-1' face='Arial,Helvetica' color='#ffffff'><b># Entries</b></font></td>"
+                             "<td><font size='-1' face='Arial,Helvetica' color='#ffffff'><b>TTL (sec)</b></font></td>"
                              "<td><font size='-1' face='Arial,Helvetica' color='#ffffff'><b>Full Mark</b></font></td>"
                              "<td><font size='-1' face='Arial,Helvetica' color='#ffffff'><b>Full Mark Time</b></font></td>"
                              "</tr>\n", r