/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2011 The OpenLDAP Foundation.
+ * Copyright 2000-2012 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "back-mdb.h"
#include "lutil_hash.h"
-static char presence_keyval[] = {0,0};
-static struct berval presence_key = BER_BVC(presence_keyval);
+static char presence_keyval[] = {0,0,0,0,0};
+static struct berval presence_key[2] = {BER_BVC(presence_keyval), BER_BVNULL};
AttrInfo *mdb_index_mask(
Backend *be,
case LDAP_FILTER_PRESENT:
type = SLAP_INDEX_PRESENT;
if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
- *prefixp = presence_key;
+ *prefixp = presence_key[0];
goto done;
}
break;
static int indexer(
Operation *op,
MDB_txn *txn,
- MDB_dbi dbi,
+ struct mdb_attrinfo *ai,
AttributeDescription *ad,
struct berval *atname,
BerVarray vals,
{
int rc, i;
struct berval *keys;
+ MDB_cursor *mc = ai->ai_cursor;
+ mdb_idl_keyfunc *keyfunc;
+ char *err;
assert( mask != 0 );
+ if ( !mc ) {
+ err = "c_open";
+ rc = mdb_cursor_open( txn, ai->ai_dbi, &mc );
+ if ( rc ) goto done;
+ if ( slapMode & SLAP_TOOL_QUICK )
+ ai->ai_cursor = mc;
+ }
+
+ if ( opid == SLAP_INDEX_ADD_OP ) {
+#ifdef MDB_TOOL_IDL_CACHING
+ if (( slapMode & SLAP_TOOL_QUICK ) && slap_tool_thread_max > 2 ) {
+ keyfunc = mdb_tool_idl_add;
+ mc = (MDB_cursor *)ai;
+ } else
+#endif
+ keyfunc = mdb_idl_insert_keys;
+ } else
+ keyfunc = mdb_idl_delete_keys;
+
if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
- rc = mdb_key_change( op->o_bd, txn, dbi, &presence_key, id, opid );
+ rc = keyfunc( mc, presence_key, id );
if( rc ) {
+ err = "presence";
goto done;
}
}
atname, vals, &keys, op->o_tmpmemctx );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i].bv_val != NULL; i++ ) {
- rc = mdb_key_change( op->o_bd, txn, dbi, &keys[i], id, opid );
- if( rc ) {
- ber_bvarray_free_x( keys, op->o_tmpmemctx );
- goto done;
- }
- }
+ rc = keyfunc( mc, keys, id );
ber_bvarray_free_x( keys, op->o_tmpmemctx );
+ if ( rc ) {
+ err = "equality";
+ goto done;
+ }
}
rc = LDAP_SUCCESS;
}
atname, vals, &keys, op->o_tmpmemctx );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i].bv_val != NULL; i++ ) {
- rc = mdb_key_change( op->o_bd, txn, dbi, &keys[i], id, opid );
- if( rc ) {
- ber_bvarray_free_x( keys, op->o_tmpmemctx );
- goto done;
- }
- }
+ rc = keyfunc( mc, keys, id );
ber_bvarray_free_x( keys, op->o_tmpmemctx );
+ if ( rc ) {
+ err = "approx";
+ goto done;
+ }
}
rc = LDAP_SUCCESS;
atname, vals, &keys, op->o_tmpmemctx );
if( rc == LDAP_SUCCESS && keys != NULL ) {
- for( i=0; keys[i].bv_val != NULL; i++ ) {
- rc = mdb_key_change( op->o_bd, txn, dbi, &keys[i], id, opid );
- if( rc ) {
- ber_bvarray_free_x( keys, op->o_tmpmemctx );
- goto done;
- }
- }
+ rc = keyfunc( mc, keys, id );
ber_bvarray_free_x( keys, op->o_tmpmemctx );
+ if( rc ) {
+ err = "substr";
+ goto done;
+ }
}
rc = LDAP_SUCCESS;
}
done:
+ if ( !(slapMode & SLAP_TOOL_QUICK))
+ mdb_cursor_close( mc );
switch( rc ) {
/* The callers all know how to deal with these results */
case 0:
if ( ai->ai_cr ) {
ComponentReference *cr;
for( cr = ai->ai_cr ; cr ; cr = cr->cr_next ) {
- rc = indexer( op, txn, ai->ai_dbi, cr->cr_ad, &type->sat_cname,
+ rc = indexer( op, txn, ai, cr->cr_ad, &type->sat_cname,
cr->cr_nvals, id, ixop,
cr->cr_indexmask );
}
*/
mask = ai->ai_newmask ? ai->ai_newmask : ai->ai_indexmask;
if( mask ) {
- rc = indexer( op, txn, ai->ai_dbi, ad, &type->sat_cname,
+ rc = indexer( op, txn, ai, ad, &type->sat_cname,
vals, id, ixop, mask );
if( rc ) return rc;
else
mask = ai->ai_newmask ? ai->ai_newmask : ai->ai_indexmask;
if ( mask ) {
- rc = indexer( op, txn, ai->ai_dbi, desc, &desc->ad_cname,
+ rc = indexer( op, txn, ai, desc, &desc->ad_cname,
vals, id, ixop, mask );
if( rc ) {
if( type->sat_ad ) {
slot = mdb_attr_slot( mdb, type->sat_ad, NULL );
if ( slot >= 0 ) {
- ir[slot].ai = mdb->mi_attrs[slot];
+ ir[slot].ir_ai = mdb->mi_attrs[slot];
al = ch_malloc( sizeof( AttrList ));
al->attr = a;
- al->next = ir[slot].attrs;
- ir[slot].attrs = al;
+ al->next = ir[slot].ir_attrs;
+ ir[slot].ir_attrs = al;
}
}
if( tags->bv_len ) {
if( desc ) {
slot = mdb_attr_slot( mdb, desc, NULL );
if ( slot >= 0 ) {
- ir[slot].ai = mdb->mi_attrs[slot];
+ ir[slot].ir_ai = mdb->mi_attrs[slot];
al = ch_malloc( sizeof( AttrList ));
al->attr = a;
- al->next = ir[slot].attrs;
- ir[slot].attrs = al;
+ al->next = ir[slot].ir_attrs;
+ ir[slot].ir_attrs = al;
}
}
}
/* Apply the indices for the recset */
int mdb_index_recrun(
Operation *op,
+ MDB_txn *txn,
struct mdb_info *mdb,
IndexRec *ir0,
ID id,
if ( id == 0 )
return 0;
- for (i=base; i<mdb->mi_nattrs; i+=slap_tool_thread_max) {
+ for (i=base; i<mdb->mi_nattrs; i+=slap_tool_thread_max-1) {
ir = ir0 + i;
- if ( !ir->ai ) continue;
- while (( al = ir->attrs )) {
- ir->attrs = al->next;
- rc = indexer( op, NULL, ir->ai->ai_dbi, ir->ai->ai_desc,
- &ir->ai->ai_desc->ad_type->sat_cname,
+ if ( !ir->ir_ai ) continue;
+ while (( al = ir->ir_attrs )) {
+ ir->ir_attrs = al->next;
+ rc = indexer( op, txn, ir->ir_ai, ir->ir_ai->ai_desc,
+ &ir->ir_ai->ai_desc->ad_type->sat_cname,
al->attr->a_nvals, id, SLAP_INDEX_ADD_OP,
- ir->ai->ai_indexmask );
+ ir->ir_ai->ai_indexmask );
free( al );
if ( rc ) break;
}
Debug( LDAP_DEBUG_TRACE, "=> index_entry_%s( %ld, \"%s\" )\n",
opid == SLAP_INDEX_DELETE_OP ? "del" : "add",
- (long) e->e_id, e->e_dn );
+ (long) e->e_id, e->e_dn ? e->e_dn : "" );
/* add each attribute to the indexes */
for ( ; ap != NULL; ap = ap->a_next ) {
Debug( LDAP_DEBUG_TRACE, "<= index_entry_%s( %ld, \"%s\" ) success\n",
opid == SLAP_INDEX_DELETE_OP ? "del" : "add",
- (long) e->e_id, e->e_dn );
+ (long) e->e_id, e->e_dn ? e->e_dn : "" );
return LDAP_SUCCESS;
}