]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/pcache.c
trim listed modules
[openldap] / servers / slapd / overlays / pcache.c
index 0dc0c942bdd783f06bd5935b9ec7361cdf94bfef..56bf2a29b21bdf7d51abf6d18dca544022268a49 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2006 The OpenLDAP Foundation.
+ * Copyright 2003-2007 The OpenLDAP Foundation.
  * Portions Copyright 2003 IBM Corporation.
  * Portions Copyright 2003 Symas Corporation.
  * All rights reserved.
@@ -49,6 +49,7 @@ struct query_template_s;
 typedef struct Qbase_s {
        Avlnode *scopes[4];             /* threaded AVL trees of cached queries */
        struct berval base;
+       int queries;
 } Qbase;
 
 /* struct representing a cached query */
@@ -106,7 +107,7 @@ struct query_manager_s;
  * 2) query addition, 3) cache replacement
  */
 typedef CachedQuery *  (QCfunc)(Operation *op, struct query_manager_s*, Query*, QueryTemplate*);
-typedef void   (AddQueryfunc)(struct query_manager_s*, Query*, QueryTemplate*, struct berval*);
+typedef CachedQuery *  (AddQueryfunc)(Operation *op, struct query_manager_s*, Query*, QueryTemplate*, int positive);
 typedef void   (CRfunc)(struct query_manager_s*, struct berval * );
 
 /* LDAP query cache */
@@ -215,7 +216,8 @@ merge_entry(
                        rc = 0;
                }
        } else {
-               be_entry_release_w( op, e );
+               if ( op->ora_e == e )
+                       be_entry_release_w( op, e );
                rc = 1;
        }
 
@@ -233,6 +235,18 @@ static int pcache_dn_cmp( const void *v1, const void *v2 )
        return rc;
 }
 
+static int lex_bvcmp( struct berval *bv1, struct berval *bv2 )
+{
+       int len, dif;
+       dif = bv1->bv_len - bv2->bv_len;
+       len = bv1->bv_len;
+       if ( dif > 0 ) len -= dif;
+       len = memcmp( bv1->bv_val, bv2->bv_val, len );
+       if ( !len )
+               len = dif;
+       return len;
+}
+
 /* compare the first value in each filter */
 static int pcache_filter_cmp( const void *v1, const void *v2 )
 {
@@ -268,15 +282,14 @@ static int pcache_filter_cmp( const void *v1, const void *v2 )
                switch( weight1 ) {
                case 0: return 0;
                case 1:
-                       rc = ber_bvcmp( &q1->first->f_ava->aa_value,
-                               &q2->first->f_ava->aa_value );
+                       rc = lex_bvcmp( &q1->first->f_av_value, &q2->first->f_av_value );
                        break;
                case 2:
                        if ( q1->first->f_choice == LDAP_FILTER_SUBSTRINGS ) {
                                rc = 0;
                                if ( !BER_BVISNULL( &q1->first->f_sub_initial )) {
                                        if ( !BER_BVISNULL( &q2->first->f_sub_initial )) {
-                                               rc = ber_bvcmp( &q1->first->f_sub_initial,
+                                               rc = lex_bvcmp( &q1->first->f_sub_initial,
                                                        &q2->first->f_sub_initial );
                                        } else {
                                                rc = 1;
@@ -287,7 +300,7 @@ static int pcache_filter_cmp( const void *v1, const void *v2 )
                                if ( rc ) break;
                                if ( q1->first->f_sub_any ) {
                                        if ( q2->first->f_sub_any ) {
-                                               rc = ber_bvcmp( q1->first->f_sub_any,
+                                               rc = lex_bvcmp( q1->first->f_sub_any,
                                                        q2->first->f_sub_any );
                                        } else {
                                                rc = 1;
@@ -298,7 +311,7 @@ static int pcache_filter_cmp( const void *v1, const void *v2 )
                                if ( rc ) break;
                                if ( !BER_BVISNULL( &q1->first->f_sub_final )) {
                                        if ( !BER_BVISNULL( &q2->first->f_sub_final )) {
-                                               rc = ber_bvcmp( &q1->first->f_sub_final,
+                                               rc = lex_bvcmp( &q1->first->f_sub_final,
                                                        &q2->first->f_sub_final );
                                        } else {
                                                rc = 1;
@@ -307,7 +320,7 @@ static int pcache_filter_cmp( const void *v1, const void *v2 )
                                        rc = -1;
                                }
                        } else {
-                               rc = ber_bvcmp( &q1->first->f_mr_value,
+                               rc = lex_bvcmp( &q1->first->f_mr_value,
                                        &q2->first->f_mr_value );
                        }
                        break;
@@ -322,7 +335,6 @@ static void
 add_query_on_top (query_manager* qm, CachedQuery* qc)
 {
        CachedQuery* top = qm->lru_top;
-       Query* q = (Query*)qc;
 
        qm->lru_top = qc;
 
@@ -334,7 +346,7 @@ add_query_on_top (query_manager* qm, CachedQuery* qc)
        qc->lru_down = top;
        qc->lru_up = NULL;
        Debug( pcache_debug, "Base of added query = %s\n",
-                       q->base.bv_val, 0, 0 );
+                       qc->qbase->base.bv_val, 0, 0 );
 }
 
 /* remove_query from LRU list */
@@ -553,9 +565,8 @@ find_filter( Operation *op, Avlnode *root, Filter *inputf, Filter *first )
 {
        Filter* fs;
        Filter* fi;
-       const char* text;
        MatchingRule* mrule = NULL;
-       int res=0;
+       int res=0, eqpass= 0;
        int ret, rc, dir;
        Avlnode *ptr;
        CachedQuery cq, *qc;
@@ -571,7 +582,7 @@ find_filter( Operation *op, Avlnode *root, Filter *inputf, Filter *first )
                dir = TAVL_DIR_LEFT;
        } else {
                ptr = tavl_find3( root, &cq, pcache_filter_cmp, &ret );
-               dir = (first->f_choice == LDAP_FILTER_LE) ? TAVL_DIR_LEFT :
+               dir = (first->f_choice == LDAP_FILTER_GE) ? TAVL_DIR_LEFT :
                        TAVL_DIR_RIGHT;
        }
 
@@ -579,6 +590,30 @@ find_filter( Operation *op, Avlnode *root, Filter *inputf, Filter *first )
                qc = ptr->avl_data;
                fi = inputf;
                fs = qc->filter;
+
+               /* an incoming substr query can only be satisfied by a cached
+                * substr query.
+                */
+               if ( first->f_choice == LDAP_FILTER_SUBSTRINGS &&
+                       qc->first->f_choice != LDAP_FILTER_SUBSTRINGS )
+                       break;
+
+               /* an incoming eq query can be satisfied by a cached eq or substr
+                * query
+                */
+               if ( first->f_choice == LDAP_FILTER_EQUALITY ) {
+                       if ( eqpass == 0 ) {
+                               if ( qc->first->f_choice != LDAP_FILTER_EQUALITY ) {
+nextpass:                      eqpass = 1;
+                                       ptr = tavl_end( root, 1 );
+                                       dir = TAVL_DIR_LEFT;
+                                       continue;
+                               }
+                       } else {
+                               if ( qc->first->f_choice != LDAP_FILTER_SUBSTRINGS )
+                                       break;
+                       }
+               }
                do {
                        res=0;
                        switch (fs->f_choice) {
@@ -604,6 +639,8 @@ find_filter( Operation *op, Avlnode *root, Filter *inputf, Filter *first )
                                if (rc != LDAP_SUCCESS) {
                                        return NULL;
                                }
+                               if ( fi==first && fi->f_choice==LDAP_FILTER_EQUALITY && ret )
+                                       goto nextpass;
                        }
                        switch (fs->f_choice) {
                        case LDAP_FILTER_OR:
@@ -683,7 +720,7 @@ query_containment(Operation *op, query_manager *qm,
                Filter *first;
 
                Debug( pcache_debug, "Lock QC index = %p\n",
-                               templa, 0, 0 );
+                               (void *) templa, 0, 0 );
                qbase.base = query->base;
 
                first = filter_first( query->filter );
@@ -759,7 +796,7 @@ query_containment(Operation *op, query_manager *qm,
 
                Debug( pcache_debug,
                        "Not answerable: Unlock QC index=%p\n",
-                       templa, 0, 0 );
+                       (void *) templa, 0, 0 );
                ldap_pvt_thread_rdwr_runlock(&templa->t_rwlock);
        }
        return NULL;
@@ -775,21 +812,23 @@ free_query (CachedQuery* qc)
 
 
 /* Add query to query cache */
-static void add_query(
+static CachedQuery * add_query(
+       Operation *op,
        query_manager* qm,
        Query* query,
        QueryTemplate *templ,
-       struct berval* uuid)
+       int positive)
 {
        CachedQuery* new_cached_query = (CachedQuery*) ch_malloc(sizeof(CachedQuery));
        Qbase *qbase, qb;
+       Filter *first;
+       int rc;
 
        new_cached_query->qtemp = templ;
-       if ( uuid ) {
-               new_cached_query->q_uuid = *uuid;
+       BER_BVZERO( &new_cached_query->q_uuid );
+       if ( positive ) {
                new_cached_query->expiry_time = slap_get_time() + templ->ttl;
        } else {
-               BER_BVZERO( &new_cached_query->q_uuid );
                new_cached_query->expiry_time = slap_get_time() + templ->negttl;
        }
        new_cached_query->lru_up = NULL;
@@ -799,13 +838,13 @@ static void add_query(
 
        new_cached_query->scope = query->scope;
        new_cached_query->filter = query->filter;
-       new_cached_query->first = filter_first( query->filter );
+       new_cached_query->first = first = filter_first( query->filter );
 
        qb.base = query->base;
 
        /* Adding a query    */
        Debug( pcache_debug, "Lock AQ index = %p\n",
-                       templ, 0, 0 );
+                       (void *) templ, 0, 0 );
        ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
        qbase = avl_find( templ->qbase, &qb, pcache_dn_cmp );
        if ( !qbase ) {
@@ -816,28 +855,39 @@ static void add_query(
                qbase->base.bv_val[qbase->base.bv_len] = '\0';
                avl_insert( &templ->qbase, qbase, pcache_dn_cmp, avl_dup_error );
        }
-       if (templ->query == NULL)
-               templ->query_last = new_cached_query;
-       else
-               templ->query->prev = new_cached_query;
        new_cached_query->next = templ->query;
        new_cached_query->prev = NULL;
        new_cached_query->qbase = qbase;
-       tavl_insert( &qbase->scopes[query->scope], new_cached_query,
-               pcache_filter_cmp, avl_dup_ok );
-       templ->query = new_cached_query;
-       templ->no_of_queries++;
+       rc = tavl_insert( &qbase->scopes[query->scope], new_cached_query,
+               pcache_filter_cmp, avl_dup_error );
+       if ( rc == 0 ) {
+               qbase->queries++;
+               if (templ->query == NULL)
+                       templ->query_last = new_cached_query;
+               else
+                       templ->query->prev = new_cached_query;
+               templ->query = new_cached_query;
+               templ->no_of_queries++;
+       } else {
+               ch_free( new_cached_query );
+               new_cached_query = find_filter( op, qbase->scopes[query->scope],
+                                                       query->filter, first );
+               filter_free( query->filter );
+       }
        Debug( pcache_debug, "TEMPLATE %p QUERIES++ %d\n",
-                       templ, templ->no_of_queries, 0 );
+                       (void *) templ, templ->no_of_queries, 0 );
 
        Debug( pcache_debug, "Unlock AQ index = %p \n",
-                       templ, 0, 0 );
+                       (void *) templ, 0, 0 );
        ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
 
        /* Adding on top of LRU list  */
-       ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
-       add_query_on_top(qm, new_cached_query);
-       ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
+       if ( rc == 0 ) {
+               ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
+               add_query_on_top(qm, new_cached_query);
+               ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
+       }
+       return rc == 0 ? new_cached_query : NULL;
 }
 
 static void
@@ -856,10 +906,8 @@ remove_from_template (CachedQuery* qc, QueryTemplate* template)
                qc->prev->next = qc->next;
        }
        tavl_delete( &qc->qbase->scopes[qc->scope], qc, pcache_filter_cmp );
-       if ( qc->qbase->scopes[0] == NULL &&
-               qc->qbase->scopes[1] == NULL &&
-               qc->qbase->scopes[2] == NULL &&
-               qc->qbase->scopes[3] == NULL ) {
+       qc->qbase->queries--;
+       if ( qc->qbase->queries == 0 ) {
                avl_delete( &template->qbase, qc->qbase, pcache_dn_cmp );
                ch_free( qc->qbase );
                qc->qbase = NULL;
@@ -895,12 +943,12 @@ static void cache_replacement(query_manager* qm, struct berval *result)
        *result = bottom->q_uuid;
        bottom->q_uuid.bv_val = NULL;
 
-       Debug( pcache_debug, "Lock CR index = %p\n", temp, 0, 0 );
+       Debug( pcache_debug, "Lock CR index = %p\n", (void *) temp, 0, 0 );
        ldap_pvt_thread_rdwr_wlock(&temp->t_rwlock);
        remove_from_template(bottom, temp);
        Debug( pcache_debug, "TEMPLATE %p QUERIES-- %d\n",
-               temp, temp->no_of_queries, 0 );
-       Debug( pcache_debug, "Unlock CR index = %p\n", temp, 0, 0 );
+               (void *) temp, temp->no_of_queries, 0 );
+       Debug( pcache_debug, "Unlock CR index = %p\n", (void *) temp, 0, 0 );
        ldap_pvt_thread_rdwr_wunlock(&temp->t_rwlock);
        free_query(bottom);
 }
@@ -1212,7 +1260,6 @@ pcache_response(
        slap_overinst *on = si->on;
        cache_manager *cm = on->on_bi.bi_private;
        query_manager*          qm = cm->qm;
-       struct berval uuid;
 
        if ( si->save_attrs != NULL ) {
                rs->sr_attrs = si->save_attrs;
@@ -1246,29 +1293,40 @@ pcache_response(
                }
 
        } else if ( rs->sr_type == REP_RESULT ) {
-               QueryTemplate* templ = si->qtemp;
-               if (( si->count && cache_entries( op, rs, &uuid ) == 0 ) ||
-                       ( templ->negttl && !si->count && !si->over &&
+               if ( si->count ||
+                       ( si->qtemp->negttl && !si->count && !si->over &&
                                rs->sr_err == LDAP_SUCCESS )) {
-                       qm->addfunc(qm, &si->query, si->qtemp,
-                               si->count ? &uuid : NULL);
-
-                       ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
-                       cm->num_cached_queries++;
-                       Debug( pcache_debug, "STORED QUERIES = %lu\n",
-                                       cm->num_cached_queries, 0, 0 );
-                       ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
+                       CachedQuery *qc = qm->addfunc(op, qm, &si->query, si->qtemp,
+                               si->count);
+
+                       if ( qc != NULL ) {
+                               if ( si->count )
+                                       cache_entries( op, rs, &qc->q_uuid );
+                               ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
+                               cm->num_cached_queries++;
+                               Debug( pcache_debug, "STORED QUERIES = %lu\n",
+                                               cm->num_cached_queries, 0, 0 );
+                               ldap_pvt_thread_mutex_unlock(&cm->cache_mutex);
 
-                       /* If the consistency checker suspended itself,
-                        * wake it back up
-                        */
-                       if ( cm->cc_paused ) {
-                               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
+                               /* If the consistency checker suspended itself,
+                                * wake it back up
+                                */
                                if ( cm->cc_paused ) {
-                                       cm->cc_paused = 0;
-                                       ldap_pvt_runqueue_resched( &slapd_rq, cm->cc_arg, 0 );
+                                       ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
+                                       if ( cm->cc_paused ) {
+                                               cm->cc_paused = 0;
+                                               ldap_pvt_runqueue_resched( &slapd_rq, cm->cc_arg, 0 );
+                                       }
+                                       ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
+                               }
+                       } else if ( si->count ) {
+                               /* duplicate query, free it */
+                               Entry *e;
+                               for (;si->head; si->head=e) {
+                                       e = si->head->e_private;
+                                       si->head->e_private = NULL;
+                                       entry_free(si->head);
                                }
-                               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
                        }
                } else {
                        filter_free( si->query.filter );
@@ -1427,7 +1485,7 @@ pcache_op_search(
                                continue;
                        cacheable = 1;
                        qtemp = qt;
-                       Debug( LDAP_DEBUG_NONE, "Entering QC, querystr = %s\n",
+                       Debug( pcache_debug, "Entering QC, querystr = %s\n",
                                        op->ors_filterstr.bv_val, 0, 0 );
                        answerable = (*(qm->qcfunc))(op, qm, &query, qt);
 
@@ -1445,7 +1503,6 @@ pcache_op_search(
 
                Debug( pcache_debug, "QUERY ANSWERABLE\n", 0, 0, 0 );
                op->o_tmpfree( filter_attrs, op->o_tmpmemctx );
-               ldap_pvt_thread_rdwr_runlock(&qtemp->t_rwlock);
                if ( BER_BVISNULL( &answerable->q_uuid )) {
                        /* No entries cached, just an empty result set */
                        i = rs->sr_err = 0;
@@ -1455,6 +1512,7 @@ pcache_op_search(
                        op->o_callback = NULL;
                        i = cm->db.bd_info->bi_op_search( op, rs );
                }
+               ldap_pvt_thread_rdwr_runlock(&qtemp->t_rwlock);
                op->o_bd = save_bd;
                op->o_callback = save_cb;
                return i;
@@ -1579,7 +1637,7 @@ consistency_check(
        Operation *op;
 
        SlapReply rs = {REP_RESULT};
-       CachedQuery* query, *query_prev;
+       CachedQuery* query;
        int return_val, pause = 1;
        QueryTemplate* templ;
 
@@ -1597,15 +1655,23 @@ consistency_check(
                if ( query ) pause = 0;
                op->o_time = slap_get_time();
                while (query && (query->expiry_time < op->o_time)) {
+                       int rem = 0;
                        Debug( pcache_debug, "Lock CR index = %p\n",
-                                       templ, 0, 0 );
+                                       (void *) templ, 0, 0 );
                        ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
-                       remove_from_template(query, templ);
-                       Debug( pcache_debug, "TEMPLATE %p QUERIES-- %d\n",
-                                       templ, templ->no_of_queries, 0 );
-                       Debug( pcache_debug, "Unlock CR index = %p\n",
-                                       templ, 0, 0 );
+                       if ( query == templ->query_last ) {
+                               rem = 1;
+                               remove_from_template(query, templ);
+                               Debug( pcache_debug, "TEMPLATE %p QUERIES-- %d\n",
+                                               (void *) templ, templ->no_of_queries, 0 );
+                               Debug( pcache_debug, "Unlock CR index = %p\n",
+                                               (void *) templ, 0, 0 );
+                       }
                        ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
+                       if ( !rem ) {
+                               query = templ->query_last;
+                               continue;
+                       }
                        ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
                        remove_query(qm, query);
                        ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
@@ -1625,9 +1691,8 @@ consistency_check(
                                "STALE QUERY REMOVED, CACHE ="
                                "%d entries\n",
                                cm->cur_entries, 0, 0 );
-                       query_prev = query;
-                       query = query->prev;
-                       free_query(query_prev);
+                       free_query(query);
+                       query = templ->query_last;
                }
        }
        ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
@@ -1861,7 +1926,7 @@ pc_cf_gen( ConfigArgs *c )
                        return( 1 );
                }
 
-               if ( !backend_db_init( c->argv[1], &cm->db )) {
+               if ( !backend_db_init( c->argv[1], &cm->db, -1 )) {
                        snprintf( c->msg, sizeof( c->msg ), "unknown backend type (arg #1)" );
                        Debug( LDAP_DEBUG_CONFIG, "%s: %s.\n", c->log, c->msg, 0 );
                        return( 1 );
@@ -2017,8 +2082,6 @@ pc_cf_gen( ConfigArgs *c )
                                Debug( pcache_debug, "\t%s\n",
                                        attrarray[i].an_name.bv_val, 0, 0 );
                }
-               temp++; 
-               temp->querystr.bv_val = NULL;
                break;
        case PC_RESP:
                if ( strcasecmp( c->argv[1], "head" ) == 0 ) {
@@ -2066,8 +2129,7 @@ pcache_db_config(
 
 static int
 pcache_db_init(
-       BackendDB *be
-)
+       BackendDB *be )
 {
        slap_overinst *on = (slap_overinst *)be->bd_info;
        cache_manager *cm;
@@ -2109,8 +2171,7 @@ pcache_db_init(
 
 static int
 pcache_db_open(
-       BackendDB *be
-)
+       BackendDB *be )
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
        cache_manager   *cm = on->on_bi.bi_private;
@@ -2151,6 +2212,13 @@ pcache_db_open(
        cm->db.be_acl = be->be_acl;
        cm->db.be_dfltaccess = be->be_dfltaccess;
 
+       if ( SLAP_DBMONITORING( be ) ) {
+               SLAP_DBFLAGS( &cm->db ) |= SLAP_DBFLAG_MONITORING;
+
+       } else {
+               SLAP_DBFLAGS( &cm->db ) &= ~SLAP_DBFLAG_MONITORING;
+       }
+
        rc = backend_startup_one( &cm->db );
 
        /* There is no runqueue in TOOL mode */
@@ -2207,7 +2275,7 @@ pcache_db_close(
        if ( cm->db.bd_info->bi_db_close ) {
                rc = cm->db.bd_info->bi_db_close( &cm->db );
        }
-       while ( tm = qm->templates ) {
+       while ( (tm = qm->templates) != NULL ) {
                CachedQuery *qc, *qn;
                qm->templates = tm->qmnext;
                for ( qc = tm->query; qc; qc = qn ) {
@@ -2239,16 +2307,8 @@ pcache_db_destroy(
        cache_manager *cm = on->on_bi.bi_private;
        query_manager *qm = cm->qm;
 
-       /* cleanup stuff inherited from the original database... */
-       cm->db.be_suffix = NULL;
-       cm->db.be_nsuffix = NULL;
-       BER_BVZERO( &cm->db.be_rootdn );
-       BER_BVZERO( &cm->db.be_rootndn );
-       BER_BVZERO( &cm->db.be_rootpw );
-       /* FIXME: there might be more... */
-
        if ( cm->db.be_private != NULL ) {
-               backend_destroy_one( &cm->db, 0 );
+               backend_stopdown_one( &cm->db );
        }
 
        ldap_pvt_thread_mutex_destroy( &qm->lru_mutex );
@@ -2268,31 +2328,16 @@ static char *obsolete_names[] = {
 
 int pcache_initialize()
 {
-       LDAPAttributeType *at;
        int code;
-       const char *err;
        struct berval debugbv = BER_BVC("pcache");
 
        if (( code = slap_loglevel_get( &debugbv, &pcache_debug )))
                return code;
 
-       at = ldap_str2attributetype( queryid_schema, &code, &err,
-               LDAP_SCHEMA_ALLOW_ALL );
-       if ( !at ) {
-               Debug( LDAP_DEBUG_ANY,
-                       "pcache_initialize: ldap_str2attributetype failed %s %s\n",
-                       ldap_scherr2str(code), err, 0 );
-               return code;
-       }
-       code = at_add( at, 0, NULL, &err );
-       if ( !code ) {
-               slap_str2ad( at->at_names[0], &ad_queryid, &err );
-       }
-       ldap_memfree( at );
+       code = register_at( queryid_schema, &ad_queryid, 0 );
        if ( code ) {
                Debug( LDAP_DEBUG_ANY,
-                       "pcache_initialize: at_add failed %s %s\n",
-                       scherr2str(code), err, 0 );
+                       "pcache_initialize: register_at failed\n", 0, 0, 0 );
                return code;
        }