mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-23 16:19:35 -05:00
Another round. BDB_INDEX almost ready for functional testing.
This commit is contained in:
parent
83d50bd696
commit
9f1fc48659
7 changed files with 142 additions and 34 deletions
|
|
@ -19,6 +19,7 @@ LDAP_BEGIN_DECL
|
||||||
/* #define BDB_REINDEX 1 */
|
/* #define BDB_REINDEX 1 */
|
||||||
/* #define BDB_FILTER_INDICES 1 */
|
/* #define BDB_FILTER_INDICES 1 */
|
||||||
#define BDB_CONFIG_INDICES 1
|
#define BDB_CONFIG_INDICES 1
|
||||||
|
/* #define SLAPD_USE_AD 1 */
|
||||||
|
|
||||||
#define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
|
#define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
|
||||||
#define DN_ONE_PREFIX '%'
|
#define DN_ONE_PREFIX '%'
|
||||||
|
|
@ -46,9 +47,12 @@ LDAP_BEGIN_DECL
|
||||||
#define BDB_NEXTID 0
|
#define BDB_NEXTID 0
|
||||||
#define BDB_DN2ID 1
|
#define BDB_DN2ID 1
|
||||||
#define BDB_ID2ENTRY 2
|
#define BDB_ID2ENTRY 2
|
||||||
#define BDB_INDICES 3
|
#define BDB_NDB 3
|
||||||
|
|
||||||
|
#define BDB_INDICES 128
|
||||||
|
|
||||||
struct bdb_db_info {
|
struct bdb_db_info {
|
||||||
|
char *bdi_name;
|
||||||
DB *bdi_db;
|
DB *bdi_db;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,59 @@ int
|
||||||
bdb_db_cache(
|
bdb_db_cache(
|
||||||
Backend *be,
|
Backend *be,
|
||||||
const char *name,
|
const char *name,
|
||||||
DB *db )
|
DB **dbout )
|
||||||
{
|
{
|
||||||
return -1;
|
int i;
|
||||||
|
int rc;
|
||||||
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
||||||
|
struct bdb_db_info *db;
|
||||||
|
char *file;
|
||||||
|
|
||||||
|
*dbout = NULL;
|
||||||
|
|
||||||
|
for( i=BDB_NDB; bdb->bi_databases[i]->bdi_name; i++ ) {
|
||||||
|
if( !strcmp( bdb->bi_databases[i]->bdi_name, name) ) {
|
||||||
|
*dbout = bdb->bi_databases[i]->bdi_db;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( i >= BDB_INDICES ) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
|
||||||
|
|
||||||
|
db->bdi_name = ch_strdup( name );
|
||||||
|
|
||||||
|
rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
|
||||||
|
if( rc != 0 ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"bdb_db_cache: db_create(%s) failed: %s (%d)\n",
|
||||||
|
bdb->bi_dbenv_home, db_strerror(rc), rc );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = ch_malloc( strlen( name ) + sizeof(BDB_SUFFIX) );
|
||||||
|
sprintf( file, "%s" BDB_SUFFIX, name );
|
||||||
|
|
||||||
|
rc = db->bdi_db->open( db->bdi_db,
|
||||||
|
file, name,
|
||||||
|
DB_BTREE, DB_CREATE|DB_THREAD,
|
||||||
|
bdb->bi_dbenv_mode );
|
||||||
|
|
||||||
|
ch_free( file );
|
||||||
|
|
||||||
|
if( rc != 0 ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"bdb_db_cache: db_open(%s) failed: %s (%d)\n",
|
||||||
|
name, db_strerror(rc), rc );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
bdb->bi_databases[i] = db;
|
||||||
|
|
||||||
|
*dbout = db->bdi_db;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,13 +149,6 @@ static int indexer(
|
||||||
|
|
||||||
assert( mask );
|
assert( mask );
|
||||||
|
|
||||||
rc = slap_str2ad( atname, &ad, &text );
|
|
||||||
|
|
||||||
if( rc != LDAP_SUCCESS ) return rc;
|
|
||||||
|
|
||||||
prefix.bv_val = atname;
|
|
||||||
prefix.bv_len = strlen( atname );
|
|
||||||
|
|
||||||
rc = bdb_db_cache( be, dbname, &db );
|
rc = bdb_db_cache( be, dbname, &db );
|
||||||
|
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
|
|
@ -167,13 +160,20 @@ static int indexer(
|
||||||
"<= bdb_index_read NULL (could not open %s)\n",
|
"<= bdb_index_read NULL (could not open %s)\n",
|
||||||
dbname, 0, 0 );
|
dbname, 0, 0 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ad_free( ad, 1 );
|
|
||||||
return LDAP_OTHER;
|
return LDAP_OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = slap_str2ad( atname, &ad, &text );
|
||||||
|
if( rc != LDAP_SUCCESS ) return rc;
|
||||||
|
|
||||||
|
prefix.bv_val = atname;
|
||||||
|
prefix.bv_len = strlen( atname );
|
||||||
|
|
||||||
if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
|
if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
|
||||||
rc = bdb_key_change( be, db, txn, &prefix, id, op );
|
rc = bdb_key_change( be, db, txn, &prefix, id, op );
|
||||||
|
if( rc ) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) ) {
|
if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) ) {
|
||||||
|
|
@ -187,9 +187,14 @@ static int indexer(
|
||||||
if( rc == LDAP_SUCCESS && keys != NULL ) {
|
if( rc == LDAP_SUCCESS && keys != NULL ) {
|
||||||
for( i=0; keys[i] != NULL; i++ ) {
|
for( i=0; keys[i] != NULL; i++ ) {
|
||||||
rc = bdb_key_change( be, db, txn, keys[i], id, op );
|
rc = bdb_key_change( be, db, txn, keys[i], id, op );
|
||||||
|
if( rc ) {
|
||||||
|
ber_bvecfree( keys );
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ber_bvecfree( keys );
|
ber_bvecfree( keys );
|
||||||
}
|
}
|
||||||
|
rc = LDAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) {
|
if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) {
|
||||||
|
|
@ -203,9 +208,15 @@ static int indexer(
|
||||||
if( rc == LDAP_SUCCESS && keys != NULL ) {
|
if( rc == LDAP_SUCCESS && keys != NULL ) {
|
||||||
for( i=0; keys[i] != NULL; i++ ) {
|
for( i=0; keys[i] != NULL; i++ ) {
|
||||||
rc = bdb_key_change( be, db, txn, keys[i], id, op );
|
rc = bdb_key_change( be, db, txn, keys[i], id, op );
|
||||||
|
if( rc ) {
|
||||||
|
ber_bvecfree( keys );
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ber_bvecfree( keys );
|
ber_bvecfree( keys );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = LDAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) ) {
|
if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) ) {
|
||||||
|
|
@ -219,13 +230,20 @@ static int indexer(
|
||||||
if( rc == LDAP_SUCCESS && keys != NULL ) {
|
if( rc == LDAP_SUCCESS && keys != NULL ) {
|
||||||
for( i=0; keys[i] != NULL; i++ ) {
|
for( i=0; keys[i] != NULL; i++ ) {
|
||||||
bdb_key_change( be, db, txn, keys[i], id, op );
|
bdb_key_change( be, db, txn, keys[i], id, op );
|
||||||
|
if( rc ) {
|
||||||
|
ber_bvecfree( keys );
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ber_bvecfree( keys );
|
ber_bvecfree( keys );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = LDAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
ad_free( ad, 1 );
|
ad_free( ad, 1 );
|
||||||
return LDAP_SUCCESS;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int index_at_values(
|
static int index_at_values(
|
||||||
|
|
@ -250,6 +268,8 @@ static int index_at_values(
|
||||||
type->sat_sup, lang,
|
type->sat_sup, lang,
|
||||||
vals, id, op,
|
vals, id, op,
|
||||||
dbnamep, &tmpmask );
|
dbnamep, &tmpmask );
|
||||||
|
|
||||||
|
if( rc ) return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bdb_attr_mask( be->be_private, type->sat_cname, &mask );
|
bdb_attr_mask( be->be_private, type->sat_cname, &mask );
|
||||||
|
|
@ -265,6 +285,8 @@ static int index_at_values(
|
||||||
type->sat_cname,
|
type->sat_cname,
|
||||||
vals, id, op,
|
vals, id, op,
|
||||||
mask );
|
mask );
|
||||||
|
|
||||||
|
if( rc ) return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( lang ) {
|
if( lang ) {
|
||||||
|
|
@ -288,6 +310,11 @@ static int index_at_values(
|
||||||
rc = indexer( be, txn, dbname, lname,
|
rc = indexer( be, txn, dbname, lname,
|
||||||
vals, id, op,
|
vals, id, op,
|
||||||
tmpmask );
|
tmpmask );
|
||||||
|
|
||||||
|
if( rc ) {
|
||||||
|
ch_free( lname );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ch_free( lname );
|
ch_free( lname );
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,11 @@ static struct bdbi_database {
|
||||||
char *name;
|
char *name;
|
||||||
int type;
|
int type;
|
||||||
int flags;
|
int flags;
|
||||||
} bdbi_databases[BDB_INDICES] = {
|
} bdbi_databases[] = {
|
||||||
{ "nextid" BDB_SUFFIX, "nextid", DB_BTREE, 0 },
|
{ "nextid" BDB_SUFFIX, "nextid", DB_BTREE, 0 },
|
||||||
{ "dn2entry" BDB_SUFFIX, "dn2entry", DB_BTREE, 0 },
|
{ "dn2entry" BDB_SUFFIX, "dn2entry", DB_BTREE, 0 },
|
||||||
{ "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 },
|
{ "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 },
|
||||||
|
{ NULL, NULL, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
@ -181,7 +182,7 @@ bdb_db_open( BackendDB *be )
|
||||||
BDB_INDICES * sizeof(struct bdb_db_info *) );
|
BDB_INDICES * sizeof(struct bdb_db_info *) );
|
||||||
|
|
||||||
/* open (and create) main database */
|
/* open (and create) main database */
|
||||||
for( i = 0; i < BDB_INDICES; i++ ) {
|
for( i = 0; bdbi_databases[i].name; i++ ) {
|
||||||
struct bdb_db_info *db;
|
struct bdb_db_info *db;
|
||||||
|
|
||||||
db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
|
db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
|
||||||
|
|
@ -208,9 +209,13 @@ bdb_db_open( BackendDB *be )
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db->bdi_name = bdbi_databases[i].name;
|
||||||
bdb->bi_databases[i] = db;
|
bdb->bi_databases[i] = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bdb->bi_databases[i] = NULL;
|
||||||
|
bdb->bi_ndatabases = i;
|
||||||
|
|
||||||
/* get nextid */
|
/* get nextid */
|
||||||
rc = bdb_last_id( be, NULL );
|
rc = bdb_last_id( be, NULL );
|
||||||
if( rc != 0 ) {
|
if( rc != 0 ) {
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,7 @@ bdb_key_read(
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DBzero( &key );
|
DBzero( &key );
|
||||||
key.data = k->bv_val;
|
bv2DBT(k,&key);
|
||||||
key.size = k->bv_len;
|
|
||||||
|
|
||||||
rc = bdb_idl_fetch_key( be, db, txn, key, ids );
|
rc = bdb_idl_fetch_key( be, db, txn, key, ids );
|
||||||
|
|
||||||
|
|
@ -90,8 +89,7 @@ bdb_key_change(
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DBTzero( &key );
|
DBTzero( &key );
|
||||||
key.data = k->bv_val;
|
bv2DBT(k,&key);
|
||||||
key.size = k->bv_len;
|
|
||||||
|
|
||||||
if (op == SLAP_INDEX_ADD_OP) {
|
if (op == SLAP_INDEX_ADD_OP) {
|
||||||
/* Add values */
|
/* Add values */
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,13 @@ Entry *bdb_deref_internal_r LDAP_P((
|
||||||
* attr.c
|
* attr.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void bdb_attr_mask LDAP_P(( struct bdb_info *bdb,
|
void bdb_attr_mask( struct bdb_info *bdb,
|
||||||
const char *desc,
|
#ifdef SLAPD_USE_AD
|
||||||
slap_mask_t *indexmask ));
|
AttributeDescription *desc,
|
||||||
|
#else
|
||||||
|
const char *desc,
|
||||||
|
#endif
|
||||||
|
slap_mask_t *indexmask );
|
||||||
|
|
||||||
int bdb_attr_index_config LDAP_P(( struct bdb_info *bdb,
|
int bdb_attr_index_config LDAP_P(( struct bdb_info *bdb,
|
||||||
const char *fname, int lineno,
|
const char *fname, int lineno,
|
||||||
|
|
@ -46,7 +50,7 @@ int
|
||||||
bdb_db_cache(
|
bdb_db_cache(
|
||||||
Backend *be,
|
Backend *be,
|
||||||
const char *name,
|
const char *name,
|
||||||
DB *db );
|
DB **db );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dn2entry.c
|
* dn2entry.c
|
||||||
|
|
|
||||||
|
|
@ -177,10 +177,10 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Debug( LDAP_DEBUG_ANY,
|
|
||||||
"=> bdb_tool_entry_put: txn_aborted!\n",
|
|
||||||
0, 0, 0 );
|
|
||||||
txn_abort( tid );
|
txn_abort( tid );
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"=> bdb_tool_entry_put: txn_aborted! %s (%d)\n",
|
||||||
|
db_strerror(rc), rc, 0 );
|
||||||
e->e_id = NOID;
|
e->e_id = NOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,22 +200,23 @@ int bdb_tool_entry_reindex(
|
||||||
Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n",
|
Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n",
|
||||||
(long) id, 0, 0 );
|
(long) id, 0, 0 );
|
||||||
|
|
||||||
#if 0
|
|
||||||
rc = txn_begin( bi->bi_dbenv, NULL, &tid, 0 );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
e = bdb_tool_entry_get( be, id );
|
e = bdb_tool_entry_get( be, id );
|
||||||
|
|
||||||
if( e == NULL ) {
|
if( e == NULL ) {
|
||||||
Debug( LDAP_DEBUG_ANY,
|
Debug( LDAP_DEBUG_ANY,
|
||||||
"bdb_tool_entry_reindex:: could not locate id=%ld\n",
|
"bdb_tool_entry_reindex:: could not locate id=%ld\n",
|
||||||
(long) id, 0, 0 );
|
(long) id, 0, 0 );
|
||||||
#if 0
|
|
||||||
txn_abort( tid );
|
|
||||||
#endif
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = txn_begin( bi->bi_dbenv, NULL, &tid, 0 );
|
||||||
|
if( rc != 0 ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"=> bdb_tool_entry_reindex: txn_begin failed: %s (%d)\n",
|
||||||
|
db_strerror(rc), rc, 0 );
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* just (re)add them for now
|
* just (re)add them for now
|
||||||
* assume that some other routine (not yet implemented)
|
* assume that some other routine (not yet implemented)
|
||||||
|
|
@ -228,8 +229,25 @@ int bdb_tool_entry_reindex(
|
||||||
|
|
||||||
rc = bdb_index_entry_add( be, tid, e, e->e_attrs );
|
rc = bdb_index_entry_add( be, tid, e, e->e_attrs );
|
||||||
|
|
||||||
entry_free( e );
|
if( rc == 0 ) {
|
||||||
|
rc = txn_commit( tid, 0 );
|
||||||
|
if( rc != 0 ) {
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"=> bdb_tool_entry_reindex: txn_commit failed: %s (%d)\n",
|
||||||
|
db_strerror(rc), rc, 0 );
|
||||||
|
e->e_id = NOID;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
txn_abort( tid );
|
||||||
|
Debug( LDAP_DEBUG_ANY,
|
||||||
|
"=> bdb_tool_entry_reindex: txn_aborted! %s (%d)\n",
|
||||||
|
db_strerror(rc), rc, 0 );
|
||||||
|
e->e_id = NOID;
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
entry_free( e );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue