]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/index.c
filter2bv can't de-normalize UUIDs, must do it explicitly for back-ldap
[openldap] / servers / slapd / back-bdb / index.c
index ffa2f27ce0e8a432c2cc70ceb2c3934cebaca07a..de4cf3d8363c3bb17e5d08da083252a18233ce3b 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@ static AttrInfo *index_mask(
                /* has tagging option */
                ai = bdb_attr_mask( be->be_private, desc->ad_type->sat_ad );
 
-               if ( ai && ( ai->ai_indexmask ^ SLAP_INDEX_NOTAGS ) ) {
+               if ( ai && !( ai->ai_indexmask & SLAP_INDEX_NOTAGS ) ) {
                        *atname = desc->ad_type->sat_cname;
                        return ai;
                }
@@ -61,7 +61,7 @@ static AttrInfo *index_mask(
 
                ai = bdb_attr_mask( be->be_private, at->sat_ad );
 
-               if ( ai && ( ai->ai_indexmask ^ SLAP_INDEX_NOSUBTYPES ) ) {
+               if ( ai && !( ai->ai_indexmask & SLAP_INDEX_NOSUBTYPES ) ) {
                        *atname = at->sat_cname;
                        return ai;
                }
@@ -170,7 +170,7 @@ static int indexer(
        DB *db;
        struct berval *keys;
 
-       assert( mask );
+       assert( mask != 0 );
 
        rc = bdb_db_cache( op->o_bd, atname->bv_val, &db );
        
@@ -254,6 +254,16 @@ static int indexer(
        }
 
 done:
+       switch( rc ) {
+       /* The callers all know how to deal with these results */
+       case 0:
+       case DB_LOCK_DEADLOCK:
+       case DB_LOCK_NOTGRANTED:
+               break;
+       /* Anything else is bad news */
+       default:
+               rc = LDAP_OTHER;
+       }
        return rc;
 }
 
@@ -294,7 +304,7 @@ static int index_at_values(
                                ComponentReference *cr;
                                for( cr = ai->ai_cr ; cr ; cr = cr->cr_next ) {
                                        rc = indexer( op, txn, cr->cr_ad, &type->sat_cname,
-                                               cr->cr_nvals, id, opid,
+                                               cr->cr_nvals, id, ixop,
                                                cr->cr_indexmask );
                                }
                        }
@@ -367,6 +377,80 @@ int bdb_index_values(
        return rc;
 }
 
+/* Get the list of which indices apply to this attr */
+int
+bdb_index_recset(
+       struct bdb_info *bdb,
+       Attribute *a,
+       AttributeType *type,
+       struct berval *tags,
+       IndexRec *ir )
+{
+       int rc, slot;
+       AttrList *al;
+
+       if( type->sat_sup ) {
+               /* recurse */
+               rc = bdb_index_recset( bdb, a, type->sat_sup, tags, ir );
+               if( rc ) return rc;
+       }
+       /* If this type has no AD, we've never used it before */
+       if( type->sat_ad ) {
+               slot = bdb_attr_slot( bdb, type->sat_ad, NULL );
+               if ( slot >= 0 ) {
+                       ir[slot].ai = bdb->bi_attrs[slot];
+                       al = ch_malloc( sizeof( AttrList ));
+                       al->attr = a;
+                       al->next = ir[slot].attrs;
+                       ir[slot].attrs = al;
+               }
+       }
+       if( tags->bv_len ) {
+               AttributeDescription *desc;
+
+               desc = ad_find_tags( type, tags );
+               if( desc ) {
+                       slot = bdb_attr_slot( bdb, desc, NULL );
+                       if ( slot >= 0 ) {
+                               ir[slot].ai = bdb->bi_attrs[slot];
+                               al = ch_malloc( sizeof( AttrList ));
+                               al->attr = a;
+                               al->next = ir[slot].attrs;
+                               ir[slot].attrs = al;
+                       }
+               }
+       }
+       return LDAP_SUCCESS;
+}
+
+/* Apply the indices for the recset */
+int bdb_index_recrun(
+       Operation *op,
+       struct bdb_info *bdb,
+       IndexRec *ir0,
+       ID id,
+       int base )
+{
+       IndexRec *ir;
+       AttrList *al;
+       int i, rc = 0;
+
+       for (i=base; i<bdb->bi_nattrs; i+=slap_tool_thread_max) {
+               ir = ir0 + i;
+               if ( !ir->ai ) continue;
+               while (( al = ir->attrs )) {
+                       ir->attrs = al->next;
+                       rc = indexer( op, NULL, ir->ai->ai_desc,
+                               &ir->ai->ai_desc->ad_type->sat_cname,
+                               al->attr->a_nvals, id, SLAP_INDEX_ADD_OP,
+                               ir->ai->ai_indexmask );
+                       free( al );
+                       if ( rc ) break;
+               }
+       }
+       return rc;
+}
+
 int
 bdb_index_entry(
        Operation *op,
@@ -379,7 +463,7 @@ bdb_index_entry(
 #ifdef LDAP_COMP_MATCH
        ComponentReference *cr_list = NULL;
        ComponentReference *cr = NULL, *dupped_cr = NULL;
-       void* decoded_comp, *extracted_comp;
+       void* decoded_comp;
        ComponentSyntaxInfo* csi_attr;
        Syntax* syn;
        AttributeType* at;