Commit 92481f70 authored by Howard Chu's avatar Howard Chu
Browse files

Modify performance patch from Gertjan van Wingerde <gwingerde@home.nl>

parent ec8fc195
......@@ -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 ) );
......
......@@ -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,
......
......@@ -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;
......
......@@ -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,
......
......@@ -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) {
......
......@@ -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,
......
......@@ -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,
......
......@@ -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 )
......
......@@ -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) {
......
......@@ -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;
}
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment