2000-06-05 06:59:38 +08:00
|
|
|
/* index.c - routines for dealing with attribute indexes */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2002-01-05 05:17:25 +08:00
|
|
|
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
2000-06-05 06:59:38 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
|
|
|
|
|
|
|
/* read a key */
|
|
|
|
int
|
|
|
|
key_read(
|
|
|
|
Backend *be,
|
|
|
|
DBCache *db,
|
|
|
|
struct berval *k,
|
|
|
|
ID_BLOCK **idout
|
|
|
|
)
|
|
|
|
{
|
2001-01-18 01:01:19 +08:00
|
|
|
Datum key;
|
2000-06-05 06:59:38 +08:00
|
|
|
ID_BLOCK *idl;
|
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, ENTRY, "key_read: enter\n", 0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
2000-06-05 06:59:38 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-05 06:59:38 +08:00
|
|
|
|
|
|
|
ldbm_datum_init( key );
|
|
|
|
key.dptr = k->bv_val;
|
|
|
|
key.dsize = k->bv_len;
|
|
|
|
|
|
|
|
idl = idl_fetch( be, db, key );
|
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, ENTRY,
|
|
|
|
"key_read: %ld candidates\n", idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
2000-06-05 06:59:38 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= index_read %ld candidates\n",
|
|
|
|
idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-05 06:59:38 +08:00
|
|
|
|
|
|
|
*idout = idl;
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add or remove stuff from index files */
|
|
|
|
int
|
|
|
|
key_change(
|
|
|
|
Backend *be,
|
|
|
|
DBCache *db,
|
|
|
|
struct berval *k,
|
|
|
|
ID id,
|
|
|
|
int op
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
2001-01-18 01:01:19 +08:00
|
|
|
Datum key;
|
2000-06-05 06:59:38 +08:00
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, ENTRY, "key_change: %s ID %lx\n",
|
|
|
|
op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long)id, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
2000-06-05 06:59:38 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
|
|
|
|
op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-05 06:59:38 +08:00
|
|
|
|
|
|
|
ldbm_datum_init( key );
|
|
|
|
key.dptr = k->bv_val;
|
|
|
|
key.dsize = k->bv_len;
|
|
|
|
|
2001-10-12 02:12:53 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
|
2000-06-05 06:59:38 +08:00
|
|
|
if (op == SLAP_INDEX_ADD_OP) {
|
|
|
|
/* Add values */
|
|
|
|
rc = idl_insert_key( be, db, key, id );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Delete values */
|
|
|
|
rc = idl_delete_key( be, db, key, id );
|
|
|
|
}
|
2001-10-12 02:12:53 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
|
2000-06-05 06:59:38 +08:00
|
|
|
|
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( INDEX, ENTRY, "key_change: return %d\n", rc, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
2000-06-05 06:59:38 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-05 06:59:38 +08:00
|
|
|
|
|
|
|
ldap_pvt_thread_yield();
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|