]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-mdb/index.c
Merge remote branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_4
[openldap] / servers / slapd / back-mdb / index.c
index b4f7d56d16ae8062329d0a59d5f4dd62748bc9e8..6acdfc09ee1a9037cf277d49f656d2d3975497fd 100644 (file)
@@ -2,7 +2,7 @@
 /* $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
@@ -25,7 +25,7 @@
 #include "back-mdb.h"
 #include "lutil_hash.h"
 
-static char presence_keyval[] = {0,0};
+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(
@@ -164,7 +164,7 @@ done:
 static int indexer(
        Operation *op,
        MDB_txn *txn,
-       MDB_dbi dbi,
+       struct mdb_attrinfo *ai,
        AttributeDescription *ad,
        struct berval *atname,
        BerVarray vals,
@@ -174,23 +174,33 @@ static int indexer(
 {
        int rc, i;
        struct berval *keys;
-       MDB_cursor *mc;
+       MDB_cursor *mc = ai->ai_cursor;
        mdb_idl_keyfunc *keyfunc;
        char *err;
 
        assert( mask != 0 );
 
-       err = "c_open";
-       rc = mdb_cursor_open( txn, dbi, &mc );
-       if ( rc ) goto done;
+       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 )
-               keyfunc = mdb_idl_insert_keys;
-       else
+       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 = keyfunc( mc, (MDB_val *)presence_key, id );
+               rc = keyfunc( mc, presence_key, id );
                if( rc ) {
                        err = "presence";
                        goto done;
@@ -206,7 +216,7 @@ static int indexer(
                        atname, vals, &keys, op->o_tmpmemctx );
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
-                       rc = keyfunc( mc, (MDB_val *)keys, id );
+                       rc = keyfunc( mc, keys, id );
                        ber_bvarray_free_x( keys, op->o_tmpmemctx );
                        if ( rc ) {
                                err = "equality";
@@ -225,7 +235,7 @@ static int indexer(
                        atname, vals, &keys, op->o_tmpmemctx );
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
-                       rc = keyfunc( mc, (MDB_val *)keys, id );
+                       rc = keyfunc( mc, keys, id );
                        ber_bvarray_free_x( keys, op->o_tmpmemctx );
                        if ( rc ) {
                                err = "approx";
@@ -245,7 +255,7 @@ static int indexer(
                        atname, vals, &keys, op->o_tmpmemctx );
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
-                       rc = keyfunc( mc, (MDB_val *)keys, id );
+                       rc = keyfunc( mc, keys, id );
                        ber_bvarray_free_x( keys, op->o_tmpmemctx );
                        if( rc ) {
                                err = "substr";
@@ -257,7 +267,8 @@ static int indexer(
        }
 
 done:
-       mdb_cursor_close( mc );
+       if ( !(slapMode & SLAP_TOOL_QUICK))
+               mdb_cursor_close( mc );
        switch( rc ) {
        /* The callers all know how to deal with these results */
        case 0:
@@ -305,7 +316,7 @@ static int index_at_values(
                        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 );
                                }
@@ -323,7 +334,7 @@ static int index_at_values(
                         */
                                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;
@@ -344,7 +355,7 @@ static int index_at_values(
                                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 ) {
@@ -400,11 +411,11 @@ mdb_index_recset(
        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 ) {
@@ -414,11 +425,11 @@ mdb_index_recset(
                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;
                        }
                }
        }
@@ -428,6 +439,7 @@ mdb_index_recset(
 /* Apply the indices for the recset */
 int mdb_index_recrun(
        Operation *op,
+       MDB_txn *txn,
        struct mdb_info *mdb,
        IndexRec *ir0,
        ID id,
@@ -441,15 +453,15 @@ int mdb_index_recrun(
        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;
                }
@@ -484,7 +496,7 @@ mdb_index_entry(
 
        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 ) {
@@ -557,7 +569,7 @@ mdb_index_entry(
 
        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;
 }