return rc;
}
-int hdb_entryinfo_load(
+/* Used by hdb_dn2idl when loading the EntryInfo for all the children
+ * of a given node
+ */
+int hdb_cache_load(
struct bdb_info *bdb,
EntryInfo *ei,
EntryInfo **res )
EntryInfo *ei2;
int rc;
+ /* See if we already have this one */
bdb_cache_entryinfo_lock( ei->bei_parent );
ei2 = (EntryInfo *)avl_find( ei->bei_parent->bei_kids, ei, bdb_rdn_cmp );
bdb_cache_entryinfo_unlock( ei->bei_parent );
+
if ( !ei2 ) {
+ /* Not found, add it */
+ struct berval bv;
+
+ /* bei_rdn was not malloc'd before, do it now */
+ ber_dupbv( &bv, &ei->bei_rdn );
+ ei->bei_rdn = bv;
+
rc = bdb_entryinfo_add_internal( bdb, ei, res );
bdb_cache_entryinfo_unlock( ei->bei_parent );
ldap_pvt_thread_rdwr_wunlock( &bdb->bi_cache.c_rwlock );
} else {
+ /* Found, return it */
*res = ei2;
- free( ei->bei_rdn.bv_val );
return 0;
}
return rc;
return rc;
}
-static void
-hdb_dn2ei(
- char *buf,
- int len,
- EntryInfo *ei )
-{
- diskNode *d = (diskNode *)buf;
- char *ptr;
-
- AC_MEMCPY( &ei->bei_id, &d->entryID, sizeof(ID) );
- AC_MEMCPY( &ei->bei_nrdn.bv_len, &d->nrdnlen, sizeof(d->nrdnlen) );
- ber_str2bv( d->nrdn, ei->bei_nrdn.bv_len, 0, &ei->bei_nrdn );
- ei->bei_rdn.bv_len = len - sizeof(diskNode) - ei->bei_nrdn.bv_len;
- ptr = d->nrdn + ei->bei_nrdn.bv_len + 1;
- ber_str2bv( ptr, ei->bei_rdn.bv_len, 1, &ei->bei_rdn );
-}
-
int
hdb_dn2id_parent(
Operation *op,
Operation *op;
};
+/* Stuff for iterating over a bei_kids AVL tree and adding the
+ * IDs to an IDL
+ */
struct apply_arg {
ID *idl;
EntryInfo **ei;
#endif
BDB_IDL_ZERO( cx->tmp );
+ /* If number of kids in the cache differs from on-disk, load
+ * up all the kids from the database
+ */
if ( cx->ei->bei_ckids+1 != cx->ei->bei_dkids ) {
EntryInfo ei;
ei.bei_parent = cx->ei;
if ( cx->rc == DB_NOTFOUND ) goto saveit;
if ( cx->rc ) return cx->rc;
+ /* If the on-disk count is zero we've never checked it.
+ * Count it now.
+ */
if ( !cx->ei->bei_dkids ) {
db_recno_t dkids;
cx->dbc->c_count( cx->dbc, &dkids, 0 );
cx->ei->bei_dkids = dkids;
}
+ /* If there are kids and this is a subtree search, allocate
+ * temp storage for the list of kids.
+ */
if ( cx->prefix == DN_SUBTREE_PREFIX && cx->ei->bei_dkids > 1 ) {
eilist = cx->op->o_tmpalloc( sizeof(EntryInfo *) * cx->ei->bei_dkids, cx->op->o_tmpmemctx );
eilist[cx->ei->bei_dkids-1] = NULL;
DB_MULTIPLE_NEXT( cx->ptr, &cx->data, j, len );
if (j) {
EntryInfo *ei2;
- hdb_dn2ei( j, len, &ei );
+ diskNode *d = (diskNode *)j;
+
+ AC_MEMCPY( &ei.bei_id, &d->entryID, sizeof(ID) );
+ AC_MEMCPY( &ei.bei_nrdn.bv_len, &d->nrdnlen, sizeof(d->nrdnlen) );
+ /* nrdn/rdn are set in-place.
+ * hdb_cache_load will copy them as needed
+ */
+ ei.bei_nrdn.bv_val = d->nrdn;
+ ei.bei_rdn.bv_len = len - sizeof(diskNode) - ei.bei_nrdn.bv_len;
+ ei.bei_rdn.bv_val = d->nrdn + ei.bei_nrdn.bv_len + 1;
bdb_idl_insert( cx->tmp, ei.bei_id );
- hdb_entryinfo_load( cx->bdb, &ei, &ei2 );
+ hdb_cache_load( cx->bdb, &ei, &ei2 );
if ( eilist )
*ptr++ = ei2;
}
}
cx->dbc->c_close( cx->dbc );
} else {
+ /* The in-memory cache is in sync with the on-disk data.
+ * do we have any kids?
+ */
if ( cx->ei->bei_ckids > 0 ) {
struct apply_arg ap;
+
+ /* Temp storage for subtree search */
if ( cx->prefix == DN_SUBTREE_PREFIX ) {
eilist = cx->op->o_tmpalloc( sizeof(EntryInfo *) * cx->ei->bei_dkids, cx->op->o_tmpmemctx );
eilist[cx->ei->bei_dkids-1] = NULL;
}
+
+ /* Walk the kids tree; order is irrelevant since bdb_idl_insert
+ * will insert in sorted order.
+ */
ap.idl = cx->tmp;
ap.ei = eilist;
bdb_cache_entryinfo_lock( cx->ei );
cx->ei = *ptr;
cx->id = cx->ei->bei_id;
hdb_dn2idl_internal( cx );
+ }
cx->op->o_tmpfree( eilist, cx->op->o_tmpmemctx );
cx->rc = 0;
} else {