]> git.sur5r.net Git - openldap/commitdiff
ITS#5860
authorQuanah Gibson-Mount <quanah@openldap.org>
Mon, 26 Jan 2009 21:23:35 +0000 (21:23 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Mon, 26 Jan 2009 21:23:35 +0000 (21:23 +0000)
CHANGES
servers/slapd/back-bdb/cache.c

diff --git a/CHANGES b/CHANGES
index 4f09699e6d3a86c3d403f68f70ae488636f4b1af..9f3c5db2bb0991d8515d498d97e0c9017d9b5af9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,7 @@ OpenLDAP 2.4.14 Engineering
        Fixed slapd syncrepl replication with glued DB (ITS#5866)
        Fixed slapd syncrepl replication with moddn (ITS#5901)
        Fixed slapd wake_sds close on Windows (ITS#5855)
+       Fixed slapd-bdb/hdb dncachesize handling (ITS#5860)
        Fixed slapd-bdb/hdb RFC4528 control support (ITS#5861)
        Fixed slapd-ldap idassert-bind validity checking (ITS#5863)
        Fixed slapd-ldif numerous bugs (ITS#5408)
index e5652b1313aa4d369744ee442ddd4bbf41cfeab1..4b5edcfac3c71b952a52e3973564495f21944895 100644 (file)
@@ -662,7 +662,16 @@ bdb_cache_lru_purge( struct bdb_info *bdb )
        /* Wait for the mutex; we're the only one trying to purge. */
        ldap_pvt_thread_mutex_lock( &bdb->bi_cache.c_lru_mutex );
 
-       if ( bdb->bi_cache.c_cursize <= bdb->bi_cache.c_maxsize ) {
+       /* maximum number of EntryInfo leaves to cache. In slapcat
+        * we always free all leaf nodes.
+        */
+       if ( slapMode & SLAP_TOOL_READONLY )
+               eimax = 0;
+       else
+               eimax = bdb->bi_cache.c_eimax;
+
+       if ( bdb->bi_cache.c_cursize <= bdb->bi_cache.c_maxsize &&
+               bdb->bi_cache.c_leaves <= eimax ) {
                ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.c_lru_mutex );
                bdb->bi_cache.c_purging = 0;
                return;
@@ -676,14 +685,6 @@ bdb_cache_lru_purge( struct bdb_info *bdb )
 
        count = 0;
 
-       /* maximum number of EntryInfo leaves to cache. In slapcat
-        * we always free all leaf nodes.
-        */
-       if ( slapMode & SLAP_TOOL_READONLY )
-               eimax = 0;
-       else
-               eimax = bdb->bi_cache.c_eimax;
-
        /* Look for an unused entry to remove */
        for ( elru = bdb->bi_cache.c_lruhead; elru; elru = elnext ) {
                elnext = elru->bei_lrunext;
@@ -719,14 +720,21 @@ bdb_cache_lru_purge( struct bdb_info *bdb )
 
                        /* Free entry for this node if it's present */
                        if ( elru->bei_e ) {
-                               elru->bei_e->e_private = NULL;
+                               if ( bdb->bi_cache.c_cursize > bdb->bi_cache.c_maxsize &&
+                                       count < bdb->bi_cache.c_minfree ) {
+                                       elru->bei_e->e_private = NULL;
 #ifdef SLAP_ZONE_ALLOC
-                               bdb_entry_return( bdb, elru->bei_e, elru->bei_zseq );
+                                       bdb_entry_return( bdb, elru->bei_e, elru->bei_zseq );
 #else
-                               bdb_entry_return( elru->bei_e );
+                                       bdb_entry_return( elru->bei_e );
 #endif
-                               elru->bei_e = NULL;
-                               count++;
+                                       elru->bei_e = NULL;
+                                       count++;
+                               } else {
+                                       /* Keep this node cached, skip to next */
+                                       bdb_cache_entry_db_unlock( bdb, lockp );
+                                       goto next;
+                               }
                        }
                        bdb_cache_entry_db_unlock( bdb, lockp );
 
@@ -744,13 +752,17 @@ bdb_cache_lru_purge( struct bdb_info *bdb )
                        }       /* Leave on list until we need to free it */
                }
 
+next:
                if ( islocked )
                        bdb_cache_entryinfo_unlock( elru );
 
-               if ( (unsigned) count >= bdb->bi_cache.c_minfree ) {
-                       ldap_pvt_thread_mutex_lock( &bdb->bi_cache.c_count_mutex );
-                       bdb->bi_cache.c_cursize -= count;
-                       ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.c_count_mutex );
+               if (( bdb->bi_cache.c_cursize <= bdb->bi_cache.c_maxsize ||
+                       (unsigned) count >= bdb->bi_cache.c_minfree ) && bdb->bi_cache.c_leaves <= eimax ) {
+                       if ( count ) {
+                               ldap_pvt_thread_mutex_lock( &bdb->bi_cache.c_count_mutex );
+                               bdb->bi_cache.c_cursize -= count;
+                               ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.c_count_mutex );
+                       }
                        break;
                }
 bottom:
@@ -986,16 +998,19 @@ load1:
                int purge = 0;
 
                if ( load ) {
+                       ldap_pvt_thread_mutex_lock( &bdb->bi_cache.c_count_mutex );
                        if ( !( flag & ID_NOCACHE )) {
-                               ldap_pvt_thread_mutex_lock( &bdb->bi_cache.c_count_mutex );
                                bdb->bi_cache.c_cursize++;
                                if ( bdb->bi_cache.c_cursize > bdb->bi_cache.c_maxsize &&
                                        !bdb->bi_cache.c_purging ) {
                                        purge = 1;
                                        bdb->bi_cache.c_purging = 1;
                                }
-                               ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.c_count_mutex );
+                       } else if ( bdb->bi_cache.c_leaves > bdb->bi_cache.c_eimax && !bdb->bi_cache.c_purging ) {
+                               purge = 1;
+                               bdb->bi_cache.c_purging = 1;
                        }
+                       ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.c_count_mutex );
                }
                if ( purge )
                        bdb_cache_lru_purge( bdb );