From 5160da05e533ead252525894414dfead55300ff8 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Thu, 4 Oct 2001 22:29:34 +0000 Subject: [PATCH] Add some initial BDB_INDEX code... needs much work. --- servers/slapd/back-bdb/Makefile.in | 4 +- servers/slapd/back-bdb/attr.c | 2 - servers/slapd/back-bdb/back-bdb.h | 6 +- servers/slapd/back-bdb/dbcache.c | 28 +++++++ servers/slapd/back-bdb/filterindex.c | 6 +- servers/slapd/back-bdb/index.c | 10 +-- servers/slapd/back-bdb/key.c | 105 +++++++++++++++++++++++++++ servers/slapd/back-bdb/proto-bdb.h | 19 +++++ 8 files changed, 165 insertions(+), 15 deletions(-) create mode 100644 servers/slapd/back-bdb/dbcache.c create mode 100644 servers/slapd/back-bdb/key.c diff --git a/servers/slapd/back-bdb/Makefile.in b/servers/slapd/back-bdb/Makefile.in index c284240f5a..c68ca75cc2 100644 --- a/servers/slapd/back-bdb/Makefile.in +++ b/servers/slapd/back-bdb/Makefile.in @@ -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 diff --git a/servers/slapd/back-bdb/attr.c b/servers/slapd/back-bdb/attr.c index fb69dddb2e..6ce4fbb00b 100644 --- a/servers/slapd/back-bdb/attr.c +++ b/servers/slapd/back-bdb/attr.c @@ -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( diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index ed45513c1f..b3fd31f383 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -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 diff --git a/servers/slapd/back-bdb/dbcache.c b/servers/slapd/back-bdb/dbcache.c new file mode 100644 index 0000000000..1837ed4e1b --- /dev/null +++ b/servers/slapd/back-bdb/dbcache.c @@ -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 + +#include +#include +#include +#include +#include + +#include "slap.h" +#include "back-bdb.h" + +int +bdb_db_cache( + Backend *be, + const char *name, + DB *db ) +{ + return -1; +} diff --git a/servers/slapd/back-bdb/filterindex.c b/servers/slapd/back-bdb/filterindex.c index dc76338b19..3e7427834b 100644 --- a/servers/slapd/back-bdb/filterindex.c +++ b/servers/slapd/back-bdb/filterindex.c @@ -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 \ No newline at end of file +#endif diff --git a/servers/slapd/back-bdb/index.c b/servers/slapd/back-bdb/index.c index b19c4be499..3ce26c7e28 100644 --- a/servers/slapd/back-bdb/index.c +++ b/servers/slapd/back-bdb/index.c @@ -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; diff --git a/servers/slapd/back-bdb/key.c b/servers/slapd/back-bdb/key.c new file mode 100644 index 0000000000..95109daa08 --- /dev/null +++ b/servers/slapd/back-bdb/key.c @@ -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 + +#include +#include + +#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 diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 0361295949..06c1922533 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -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 -- 2.39.5