From 92481f7057f64adae2b58bb0761d5e1a95dcbca5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 13 Jan 2002 23:23:23 +0000 Subject: [PATCH] Modify performance patch from Gertjan van Wingerde --- servers/slapd/attr.c | 2 + servers/slapd/back-bdb/index.c | 18 +++++++ servers/slapd/back-bdb/modify.c | 59 +++++++++++++++++------ servers/slapd/back-bdb/proto-bdb.h | 5 ++ servers/slapd/back-ldap/search.c | 1 + servers/slapd/back-ldbm/index.c | 18 +++++++ servers/slapd/back-ldbm/proto-back-ldbm.h | 5 ++ servers/slapd/back-meta/search.c | 1 + servers/slapd/entry.c | 1 + servers/slapd/operational.c | 2 + servers/slapd/slap.h | 3 ++ 11 files changed, 99 insertions(+), 16 deletions(-) diff --git a/servers/slapd/attr.c b/servers/slapd/attr.c index 462fead661..a4ef93f7b3 100644 --- a/servers/slapd/attr.c +++ b/servers/slapd/attr.c @@ -74,6 +74,7 @@ Attribute *attr_dup( Attribute *a ) tmp->a_desc = a->a_desc; tmp->a_next = NULL; + tmp->a_flags = 0; return tmp; } @@ -125,6 +126,7 @@ attr_merge( (*a)->a_desc = desc; (*a)->a_vals = NULL; (*a)->a_next = NULL; + (*a)->a_flags = 0; } return( value_add( &(*a)->a_vals, vals ) ); diff --git a/servers/slapd/back-bdb/index.c b/servers/slapd/back-bdb/index.c index b22c3f6598..c62e09d63f 100644 --- a/servers/slapd/back-bdb/index.c +++ b/servers/slapd/back-bdb/index.c @@ -75,6 +75,24 @@ static slap_mask_t index_mask( return 0; } +int bdb_index_is_indexed( + Backend *be, + AttributeDescription *desc ) +{ + int rc; + slap_mask_t mask; + char *dbname; + struct berval prefix; + + mask = index_mask( be, desc, &dbname, &prefix ); + + if( mask == 0 ) { + return LDAP_INAPPROPRIATE_MATCHING; + } + + return LDAP_SUCCESS; +} + int bdb_index_param( Backend *be, AttributeDescription *desc, diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 435ae651b8..6d9cc6c4be 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -33,6 +33,7 @@ int bdb_modify_internal( Modification *mod; Modifications *ml; Attribute *save_attrs; + Attribute *ap; Debug( LDAP_DEBUG_TRACE, "bdb_modify_internal: 0x%08lx: %s\n", e->e_id, e->e_dn, 0); @@ -115,6 +116,16 @@ int bdb_modify_internal( /* unlock entry, delete from cache */ return err; } + + /* check if modified attribute was indexed */ + err = bdb_index_is_indexed( be, mod->sm_desc ); + if ( err == LDAP_SUCCESS ) { + ap = attr_find( save_attrs, mod->sm_desc ); + if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL; + + ap = attr_find( e->e_attrs, mod->sm_desc ); + if ( ap ) ap->a_flags |= SLAP_ATTR_IXADD; + } } /* check that the entry still obeys the schema */ @@ -127,24 +138,40 @@ int bdb_modify_internal( return rc; } - /* delete indices for old attributes */ - rc = bdb_index_entry_del( be, tid, e, save_attrs); - if ( rc != LDAP_SUCCESS ) { - attrs_free( e->e_attrs ); - e->e_attrs = save_attrs; - Debug( LDAP_DEBUG_ANY, "entry index delete failed!\n", - 0, 0, 0 ); - return rc; + /* update the indices of the modified attributes */ + + /* start with deleting the old index entries */ + for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) { + if ( ap->a_flags & SLAP_ATTR_IXDEL ) { + rc = bdb_index_values( be, tid, ap->a_desc, ap->a_vals, + e->e_id, SLAP_INDEX_DELETE_OP ); + if ( rc != LDAP_SUCCESS ) { + attrs_free( e->e_attrs ); + e->e_attrs = save_attrs; + Debug( LDAP_DEBUG_ANY, + "Attribute index delete failure", + 0, 0, 0 ); + return rc; + } + ap->a_flags &= ~SLAP_ATTR_IXDEL; + } } - /* add indices for new attributes */ - rc = bdb_index_entry_add( be, tid, e, e->e_attrs); - if ( rc != LDAP_SUCCESS ) { - attrs_free( e->e_attrs ); - e->e_attrs = save_attrs; - Debug( LDAP_DEBUG_ANY, "entry index add failed!\n", - 0, 0, 0 ); - return rc; + /* add the new index entries */ + for ( ap = e->e_attrs; ap != NULL; ap = ap->a_next ) { + if (ap->a_flags & SLAP_ATTR_IXADD) { + rc = bdb_index_values( be, tid, ap->a_desc, ap->a_vals, + e->e_id, SLAP_INDEX_ADD_OP ); + if ( rc != LDAP_SUCCESS ) { + attrs_free( e->e_attrs ); + e->e_attrs = save_attrs; + Debug( LDAP_DEBUG_ANY, + "Attribute index add failure", + 0, 0, 0 ); + return rc; + } + ap->a_flags &= ~SLAP_ATTR_IXADD; + } } return rc; diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index b54e6de4c2..903700600f 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -207,6 +207,11 @@ ID bdb_idl_next( ID *ids, ID *cursor ); * index.c */ extern int +bdb_index_is_indexed LDAP_P(( + Backend *be, + AttributeDescription *desc )); + +extern int bdb_index_param LDAP_P(( Backend *be, AttributeDescription *desc, diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 8a8f4327de..bba93b59be 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -426,6 +426,7 @@ ldap_send_entry( attr = (Attribute *)ch_malloc( sizeof(Attribute) ); if (attr == NULL) continue; + attr->a_flags = 0; attr->a_next = 0; attr->a_desc = NULL; if (slap_bv2ad(&mapped, &attr->a_desc, &text) != LDAP_SUCCESS) { diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index cd1c685fec..924f16ee57 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -71,6 +71,24 @@ static slap_mask_t index_mask( return 0; } +int index_is_indexed( + Backend *be, + AttributeDescription *desc ) +{ + int rc; + slap_mask_t mask; + char *dbname; + struct berval prefix; + + mask = index_mask( be, desc, &dbname, &prefix ); + + if( mask == 0 ) { + return LDAP_INAPPROPRIATE_MATCHING; + } + + return LDAP_SUCCESS; +} + int index_param( Backend *be, AttributeDescription *desc, diff --git a/servers/slapd/back-ldbm/proto-back-ldbm.h b/servers/slapd/back-ldbm/proto-back-ldbm.h index a449f6aff2..20ef3dfee9 100644 --- a/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -139,6 +139,11 @@ ID idl_nextid LDAP_P(( ID_BLOCK *idl, ID *cursor )); * index.c */ extern int +index_is_indexed LDAP_P(( + Backend *be, + AttributeDescription *desc )); + +extern int index_param LDAP_P(( Backend *be, AttributeDescription *desc, diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index e475548757..259f55cab9 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -646,6 +646,7 @@ meta_send_entry( if ( attr == NULL ) { continue; } + attr->a_flags = 0; attr->a_next = 0; attr->a_desc = NULL; if ( slap_bv2ad( &mapped, &attr->a_desc, &text ) diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index 9af12512dc..6b17ccf018 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -625,6 +625,7 @@ int entry_decode(struct berval *bv, Entry **e) a->a_desc = ad; bptr = (BVarray)(a+1); a->a_vals = bptr; + a->a_flags = 0; j = entry_getlen(&ptr); while (j) { diff --git a/servers/slapd/operational.c b/servers/slapd/operational.c index 1c37cec543..8accbee425 100644 --- a/servers/slapd/operational.c +++ b/servers/slapd/operational.c @@ -27,6 +27,7 @@ slap_operational_subschemaSubentry( void ) a->a_vals[1].bv_val = NULL; a->a_next = NULL; + a->a_flags = 0; return a; } @@ -47,6 +48,7 @@ slap_operational_hasSubordinate( int hs ) a->a_vals[1].bv_val = NULL; a->a_next = NULL; + a->a_flags = 0; return a; } diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index e4c5abce42..26c0141b22 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -716,6 +716,9 @@ typedef struct slap_attr { AttributeDescription *a_desc; BVarray a_vals; struct slap_attr *a_next; + unsigned a_flags; +#define SLAP_ATTR_IXADD 0x1U +#define SLAP_ATTR_IXDEL 0x2U } Attribute; -- 2.39.5