From: Howard Chu Date: Thu, 19 Sep 2002 06:08:12 +0000 (+0000) Subject: Updated BDB_HIER for current API X-Git-Tag: NO_SLAP_OP_BLOCKS~958 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ff9e580d335da9089339b0483a6867af711b9f9d;p=openldap Updated BDB_HIER for current API --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 5533206dc6..70e40712d8 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -104,7 +104,6 @@ struct bdb_info { Avlnode *bi_tree; ldap_pvt_thread_rdwr_t bi_tree_rdwr; void *bi_troot; - int bi_nrdns; #endif int bi_txn_cp; diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index 96eedca61b..70bca2b43e 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -12,6 +12,7 @@ #include "back-bdb.h" #include "idl.h" +#include "lutil.h" #ifndef BDB_HIER int @@ -621,11 +622,11 @@ node_find_cmp( static int node_frdn_cmp( - char *nrdn, + struct berval *nrdn, idNode *n ) { - return strcmp(nrdn, n->i_rdn->nrdn.bv_val); + return ber_bvcmp(nrdn, &n->i_rdn->nrdn); } static int @@ -643,9 +644,6 @@ node_rdn_cmp( idNode *b ) { -#if 0 - return strcmp(a->i_rdn->nrdn.bv_val, b->i_rdn->nrdn.bv_val); -#endif /* should be slightly better without ordering drawbacks */ return ber_bvcmp(&a->i_rdn->nrdn, &b->i_rdn->nrdn); } @@ -659,7 +657,7 @@ idNode * bdb_find_id_node( } idNode * bdb_find_rdn_node( - char *nrdn, + struct berval *nrdn, Avlnode *tree ) { @@ -716,12 +714,11 @@ int bdb_build_tree( ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; - int i, rc; + int rc; DBC *cursor; DBT key, data; ID id; idNode *node; - char **rdns; bdb->bi_tree = NULL; @@ -732,20 +729,6 @@ int bdb_build_tree( return NOID; } - /* When be_suffix is turned into struct berval or LDAPDN - * life will get a lot easier... Since no DNs live on disk, we - * need to operate on the be_suffix to fully qualify our DNs. - * We need to know how many components are in the suffix DN, - * so we can tell where the suffix ends and our nodes begin. - * - * Note that this code always uses be_suffix[0], so defining - * multiple suffixes for a single backend won't work! - */ - rdns = ldap_explode_dn(be->be_nsuffix[0].bv_val, 0); - for (i=0; rdns[i]; i++); - bdb->bi_nrdns = i; - ldap_charray_free(rdns); - DBTzero( &key ); DBTzero( &data ); key.data = (char *)&id; @@ -840,7 +823,7 @@ bdb_dn2id_add( d->nrdn.bv_val -= (long)d; if (pdn->bv_len) { - bdb_dn2id(be, txn, pdn, &d->parent); + bdb_dn2id(be, txn, pdn, &d->parent, 0); } else { d->parent = 0; } @@ -897,7 +880,7 @@ bdb_dn2id_delete( if (n) { if (n->i_parent) { ldap_pvt_thread_rdwr_wlock(&n->i_parent->i_kids_rdwr); - avl_delete(&n->i_parent->i_kids, n->i_rdn->nrdn.bv_val, + avl_delete(&n->i_parent->i_kids, &n->i_rdn->nrdn, (AVL_CMP)node_frdn_cmp); ldap_pvt_thread_rdwr_wunlock(&n->i_parent->i_kids_rdwr); } @@ -918,11 +901,12 @@ bdb_dn2id_matched( DB_TXN *txn, struct berval *in, ID *id, - ID *id2 ) + ID *id2, + int flags ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; - int i; - char **rdns; + struct berval rdn; + char *p1, *p2; idNode *n, *p; if (!bdb->bi_troot) @@ -934,24 +918,23 @@ bdb_dn2id_matched( return 0; } - rdns = ldap_explode_dn(in->bv_val, 0); - for (i=0; rdns[i]; i++); - i -= bdb->bi_nrdns; - if (i < 0) { - ldap_charray_free(rdns); - return -1; - } + p1 = in->bv_val + in->bv_len - be->be_nsuffix[0].bv_len - 1; + n = p; ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr); - for (--i; i>=0; i--) { + for (;;) { + for (p2 = p1-1; (p2 >= in->bv_val) && !DN_SEPARATOR(*p2); p2--); + rdn.bv_val = p2+1; + rdn.bv_len = p1-rdn.bv_val; + p1 = p2; + ldap_pvt_thread_rdwr_rlock(&p->i_kids_rdwr); - n = bdb_find_rdn_node(rdns[i], p->i_kids); + n = bdb_find_rdn_node(&rdn, p->i_kids); ldap_pvt_thread_rdwr_runlock(&p->i_kids_rdwr); - if (!n) break; + if (!n || p2 < in->bv_val) break; p = n; } ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr); - ldap_charray_free(rdns); if (n) { *id = n->i_id; @@ -966,23 +949,25 @@ bdb_dn2id( BackendDB *be, DB_TXN *txn, struct berval *dn, - ID *id ) + ID *id, + int flags ) { - return bdb_dn2id_matched(be, txn, dn, id, NULL); + return bdb_dn2id_matched(be, txn, dn, id, NULL, flags); } int bdb_dn2id_children( BackendDB *be, DB_TXN *txn, - struct berval *dn ) + struct berval *dn, + int flags ) { int rc; struct bdb_info *bdb = (struct bdb_info *) be->be_private; ID id; idNode *n; - rc = bdb_dn2id(be, txn, dn, &id); + rc = bdb_dn2id(be, txn, dn, &id, flags); if (rc != 0) return rc; @@ -1043,7 +1028,7 @@ bdb_dn2idl( return 0; } - rc = bdb_dn2id(be, NULL, dn, &id); + rc = bdb_dn2id(be, NULL, dn, &id, 0); if (rc) return rc; ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr); diff --git a/servers/slapd/back-bdb/id2entry.c b/servers/slapd/back-bdb/id2entry.c index ef377fd5bd..9c8c9657e4 100644 --- a/servers/slapd/back-bdb/id2entry.c +++ b/servers/slapd/back-bdb/id2entry.c @@ -124,6 +124,9 @@ int bdb_id2entry_rw( } if ( rc == 0 ) { +#ifdef BDB_HIER + bdb_fix_dn(be, id, *e); +#endif ret = bdb_cache_add_entry_rw( bdb->bi_dbenv, &bdb->bi_cache, *e, rw, locker, lock); while ( ret == 1 || ret == -1 ) { @@ -155,10 +158,6 @@ int bdb_id2entry_rw( rc = ret; } -#ifdef BDB_HIER - bdb_fix_dn(be, id, *e); -#endif - if (rc == 0) { bdb_cache_entry_commit(*e); }