]> git.sur5r.net Git - openldap/commitdiff
Caching non-existing index entries in the IDL cache - caching keys only
authorJong Hyuk Choi <jongchoi@openldap.org>
Fri, 18 Apr 2003 00:35:11 +0000 (00:35 +0000)
committerJong Hyuk Choi <jongchoi@openldap.org>
Fri, 18 Apr 2003 00:35:11 +0000 (00:35 +0000)
servers/slapd/back-bdb/idl.c
servers/slapd/back-bdb/init.c

index e944a291c5ef748f9e1f758aba12bf36b3eb8dc9..17e56241e80a958dc33e401001463d6572737c46 100644 (file)
@@ -356,13 +356,17 @@ bdb_idl_fetch_key(
                matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
                                              bdb_idl_entry_cmp );
                if ( matched_idl_entry != NULL ) {
-                       BDB_IDL_CPY( ids, matched_idl_entry->idl );
+                       if ( matched_idl_entry->idl )
+                               BDB_IDL_CPY( ids, matched_idl_entry->idl );
                        ldap_pvt_thread_rdwr_runlock( &bdb->bi_idl_tree_rwlock );
                        ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
                        IDL_LRU_DELETE( bdb, matched_idl_entry );
                        IDL_LRU_ADD( bdb, matched_idl_entry );
                        ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
-                       return LDAP_SUCCESS;
+                       if ( matched_idl_entry->idl )
+                               return LDAP_SUCCESS;
+                       else
+                               return DB_NOTFOUND;
                }
                ldap_pvt_thread_rdwr_runlock( &bdb->bi_idl_tree_rwlock );
        }
@@ -442,7 +446,9 @@ bdb_idl_fetch_key(
        }
 
        if( rc == DB_NOTFOUND ) {
+#ifndef SLAP_IDL_CACHE
                return rc;
+#endif
 
        } else if( rc != 0 ) {
 #ifdef NEW_LOGGING
@@ -489,10 +495,14 @@ bdb_idl_fetch_key(
                ee = (bdb_idl_cache_entry_t *) ch_malloc(
                        sizeof( bdb_idl_cache_entry_t ) );
                ee->db = db;
-               ee->idl = (ID*) ch_malloc( BDB_IDL_SIZEOF ( ids ) );
+               if ( rc == DB_NOTFOUND) {
+                       ee->idl = NULL;
+               } else {
+                       ee->idl = (ID*) ch_malloc( BDB_IDL_SIZEOF ( ids ) );
+                       BDB_IDL_CPY( ee->idl, ids );
+               }
                ee->idl_lru_prev = NULL;
                ee->idl_lru_next = NULL;
-               BDB_IDL_CPY( ee->idl, ids );
                ber_dupbv( &ee->kstr, &idl_tmp.kstr );
                ldap_pvt_thread_rdwr_wlock( &bdb->bi_idl_tree_rwlock );
                if ( avl_insert( &bdb->bi_idl_tree, (caddr_t) ee,
@@ -596,7 +606,8 @@ bdb_idl_insert_key(
                        IDL_LRU_DELETE( bdb, matched_idl_entry );
                        ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
                        free( matched_idl_entry->kstr.bv_val );
-                       free( matched_idl_entry->idl );
+                       if ( matched_idl_entry->idl )
+                               free( matched_idl_entry->idl );
                        free( matched_idl_entry );
                }
                ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock );
@@ -820,7 +831,8 @@ bdb_idl_delete_key(
                        IDL_LRU_DELETE( bdb, matched_idl_entry );
                        ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
                        free( matched_idl_entry->kstr.bv_val );
-                       free( matched_idl_entry->idl );
+                       if ( matched_idl_entry->idl )
+                               free( matched_idl_entry->idl );
                        free( matched_idl_entry );
                }
                ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock );
index d23618ddb9ee0d96e1efa3d07ed3a0e5d3bb43f8..5e6c1d3f1f01c6efb81b5506fc15f934926d8434 100644 (file)
@@ -468,7 +468,8 @@ bdb_db_close( BackendDB *be )
                        next_entry = entry->idl_lru_next;
                        avl_delete( &bdb->bi_idl_tree, (caddr_t) entry,
                                        bdb_idl_entry_cmp );
-                       free( entry->idl );
+                       if ( entry->idl )
+                               free( entry->idl );
                        free( entry->kstr.bv_val );
                        free( entry );
                        entry = next_entry;