]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/key.c
Hallvard B. Furuseth's patch for cache lock and mutex
[openldap] / servers / slapd / back-bdb / key.c
index 95109daa085ed0cfbff0cc89a12d95864e60f190..ea6433fa6eebf38301a286322ef24ab24c3ff452 100644 (file)
@@ -1,7 +1,7 @@
 /* index.c - routines for dealing with attribute indexes */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
 
 #include "slap.h"
 #include "back-bdb.h"
+#include "idl.h"
 
-#ifdef BDB_FILTER_INDICES
 /* read a key */
 int
 bdb_key_read(
-    Backend    *be,
+       Backend *be,
        DB *db,
        DB_TXN *txn,
-    struct berval *k,
-       ID **idout
+       struct berval *k,
+       ID *ids
 )
 {
-       Datum           key;
-       ID_BLOCK                *idl;
+       int rc;
+       DBT key;
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
-                  "key_read: enter\n" ));
+               "key_read: enter\n" ));
 #else
        Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
 #endif
 
-       ldbm_datum_init( key );
-       key.dptr = k->bv_val;
-       key.dsize = k->bv_len;
+       DBTzero( &key );
+       bv2DBT(k,&key);
 
-       rc = bdb_idl_fetch_key( be, db, key, idl );
+       rc = bdb_idl_fetch_key( be, db, txn, &key, ids );
 
+       if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
-                  "key_read: %ld candidates\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+               LDAP_LOG(( "index", LDAP_LEVEL_ERR,
+                       "bdb_key_read: failed (%d)\n",
+                       rc ));
 #else
-       Debug( LDAP_DEBUG_TRACE, "<= index_read %ld candidates\n",
-              idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
+               Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read: failed (%d)\n",
+                       rc, 0, 0 );
 #endif
+       } else {
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "index", LDAP_LEVEL_DETAIL1,
+                       "bdb_key_read: %ld candidates\n", (long) BDB_IDL_N(ids) ));
+#else
+               Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read %ld candidates\n",
+                       (long) BDB_IDL_N(ids), 0, 0 );
+#endif
+       }
 
-       *idout = idl;
-       return LDAP_SUCCESS;
+       return rc;
 }
-#endif
 
-#ifdef BDB_INDEX
 /* Add or remove stuff from index files */
 int
 bdb_key_change(
-    Backend *be,
-    DB *db,
+       Backend *be,
+       DB *db,
        DB_TXN *txn,
-    struct berval *k,
-    ID id,
-    int op
+       struct berval *k,
+       ID id,
+       int op
 )
 {
        int     rc;
        DBT     key;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
+       LDAP_LOG(( "index", LDAP_LEVEL_DETAIL1,
                "key_change: %s ID %lx\n",
-               op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long)id ));
+               op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long) id ));
 #else
        Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
                op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
 #endif
 
        DBTzero( &key );
-       key.data = k->bv_val;
-       key.size = k->bv_len;
+       bv2DBT(k,&key);
 
        if (op == SLAP_INDEX_ADD_OP) {
-           /* Add values */
-           rc = bdb_idl_insert_key( be, db, txn, &key, id );
+               /* Add values */
+               rc = bdb_idl_insert_key( be, db, txn, &key, id );
 
        } else {
-           /* Delete values */
-           rc = bdb_idl_delete_key( be, db, txn, &key, id );
+               /* Delete values */
+               rc = bdb_idl_delete_key( be, db, txn, &key, id );
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
+       LDAP_LOG(( "index", LDAP_LEVEL_RESULTS,
                "key_change: return %d\n", rc ));
 #else
        Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
@@ -102,4 +107,3 @@ bdb_key_change(
 
        return rc;
 }
-#endif