Add some initial BDB_INDEX code... needs much work.

This commit is contained in:
Kurt Zeilenga 2001-10-04 22:29:34 +00:00
parent 75c7331743
commit 5160da05e5
8 changed files with 165 additions and 15 deletions

View File

@ -3,12 +3,12 @@
SRCS = init.c tools.c config.c \
add.c bind.c compare.c delete.c modify.c modrdn.c search.c \
extended.c passwd.c referral.c \
attr.c index.c \
attr.c index.c key.c dbcache.c \
dn2entry.c dn2id.c error.c id2entry.c idl.c nextid.c
OBJS = init.lo tools.lo config.lo \
add.lo bind.lo compare.lo delete.lo modify.lo modrdn.lo search.lo \
extended.lo passwd.lo referral.lo \
attr.lo index.lo \
attr.lo index.lo key.lo dbcache.lo \
dn2entry.lo dn2id.lo error.lo id2entry.lo idl.lo nextid.lo
LDAP_INCDIR= ../../../include

View File

@ -57,7 +57,6 @@ ainfo_cmp(
#endif
}
#if 0
void
bdb_attr_mask(
struct bdb_info *bdb,
@ -75,7 +74,6 @@ bdb_attr_mask(
*indexmask = a != NULL ? a->ai_indexmask : 0;
}
#endif
int
bdb_attr_index_config(

View File

@ -1,7 +1,7 @@
/* back-bdb.h - ldap ldbm back-end header file */
/* back-bdb.h - bdb back-end header file */
/* $OpenLDAP$ */
/*
* Copyright 2000 The OpenLDAP Foundation, All Rights Reserved.
* Copyright 2000-2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
@ -15,7 +15,7 @@
LDAP_BEGIN_DECL
/* #define BDB_INDEX 1 */
#define BDB_INDEX 1
/* #define BDB_REINDEX 1 */
/* #define BDB_FILTER_INDICES 1 */
#define BDB_CONFIG_INDICES 1

View File

@ -0,0 +1,28 @@
/* dbcache.c - manage cache of open databases */
/* $OpenLDAP$ */
/*
* Copyright 1998-2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "portable.h"
#include <stdio.h>
#include <ac/errno.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
#include <sys/stat.h>
#include "slap.h"
#include "back-bdb.h"
int
bdb_db_cache(
Backend *be,
const char *name,
DB *db )
{
return -1;
}

View File

@ -440,7 +440,7 @@ approx_candidates(
ID_BLOCK *save;
ID_BLOCK *tmp;
rc = key_read( be, db, keys[i], &tmp );
rc = bdb_key_read( be, db, keys[i], tmp );
if( rc != LDAP_SUCCESS ) {
idl_free( idl );
@ -562,7 +562,7 @@ substring_candidates(
ID_BLOCK *save;
ID_BLOCK *tmp;
rc = key_read( be, db, keys[i], &tmp );
rc = bdb_key_read( be, db, keys[i], &tmp );
if( rc != LDAP_SUCCESS ) {
idl_free( idl );
@ -595,4 +595,4 @@ substring_candidates(
return( idl );
}
#endif
#endif

View File

@ -29,7 +29,7 @@ static slap_mask_t index_mask(
/* we do not support indexing of binary attributes */
if( slap_ad_is_binary( desc ) ) return 0;
attr_mask( be->be_private, desc->ad_cname->bv_val, &mask );
bdb_attr_mask( be->be_private, desc->ad_cname->bv_val, &mask );
if( mask ) {
*atname = desc->ad_cname->bv_val;
@ -39,7 +39,7 @@ static slap_mask_t index_mask(
if( slap_ad_is_lang( desc ) ) {
/* has language tag */
attr_mask( be->be_private, desc->ad_type->sat_cname, &mask );
bdb_attr_mask( be->be_private, desc->ad_type->sat_cname, &mask );
if( mask & SLAP_INDEX_AUTO_LANG ) {
*atname = desc->ad_cname->bv_val;
@ -55,7 +55,7 @@ static slap_mask_t index_mask(
/* see if supertype defined mask for its subtypes */
for( at = desc->ad_type; at != NULL ; at = at->sat_sup ) {
attr_mask( be->be_private, at->sat_cname, &mask );
bdb_attr_mask( be->be_private, at->sat_cname, &mask );
if( mask & SLAP_INDEX_AUTO_SUBTYPES ) {
*atname = desc->ad_type->sat_cname;
@ -252,7 +252,7 @@ static int index_at_values(
dbnamep, &tmpmask );
}
attr_mask( be->be_private, type->sat_cname, &mask );
bdb_attr_mask( be->be_private, type->sat_cname, &mask );
if( mask ) {
*dbnamep = type->sat_cname;
@ -275,7 +275,7 @@ static int index_at_values(
sprintf( lname, "%s;%s", type->sat_cname, lang );
attr_mask( be->be_private, lname, &tmpmask );
bdb_attr_mask( be->be_private, lname, &tmpmask );
if( tmpmask ) {
dbname = lname;

View File

@ -0,0 +1,105 @@
/* index.c - routines for dealing with attribute indexes */
/* $OpenLDAP$ */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* 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-bdb.h"
#ifdef BDB_FILTER_INDICES
/* read a key */
int
bdb_key_read(
Backend *be,
DB *db,
DB_TXN *txn,
struct berval *k,
ID **idout
)
{
Datum key;
ID_BLOCK *idl;
#ifdef NEW_LOGGING
LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
"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;
rc = bdb_idl_fetch_key( be, db, key, idl );
#ifdef NEW_LOGGING
LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
"key_read: %ld candidates\n",
idl ? ID_BLOCK_NIDS(idl) : 0 ));
#else
Debug( LDAP_DEBUG_TRACE, "<= index_read %ld candidates\n",
idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
#endif
*idout = idl;
return LDAP_SUCCESS;
}
#endif
#ifdef BDB_INDEX
/* Add or remove stuff from index files */
int
bdb_key_change(
Backend *be,
DB *db,
DB_TXN *txn,
struct berval *k,
ID id,
int op
)
{
int rc;
DBT key;
#ifdef NEW_LOGGING
LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
"key_change: %s ID %lx\n",
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;
if (op == SLAP_INDEX_ADD_OP) {
/* 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 );
}
#ifdef NEW_LOGGING
LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
"key_change: return %d\n", rc ));
#else
Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
#endif
return rc;
}
#endif

View File

@ -39,6 +39,15 @@ int bdb_attr_index_config LDAP_P(( struct bdb_info *bdb,
void bdb_attr_index_destroy LDAP_P(( Avlnode *tree ));
/*
* dbcache.c
*/
int
bdb_db_cache(
Backend *be,
const char *name,
DB *db );
/*
* dn2entry.c
*/
@ -205,8 +214,18 @@ extern int
bdb_key_read(
Backend *be,
DB *db,
DB_TXN *txn,
struct berval *k,
ID *ids );
extern int
bdb_key_change(
Backend *be,
DB *db,
DB_TXN *txn,
struct berval *k,
ID id,
int op );
/*
* nextid.c