From 67a64c293513ab6f4541e84d2b5a55ae1e1385f1 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 10 Dec 2001 18:09:07 +0000 Subject: [PATCH] Fixed suffix DN_SUBTREE again. Index was still being written even though it was not being read. --- servers/slapd/back-bdb/dn2id.c | 38 +++------ servers/slapd/back-ldbm/dn2id.c | 137 ++++++++++++++++---------------- 2 files changed, 77 insertions(+), 98 deletions(-) diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index 2b1d3d6032..ca360779d5 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -77,24 +77,12 @@ bdb_dn2id_add( pdn, rc, 0 ); goto done; } - - pdn[-1] = DN_SUBTREE_PREFIX; - rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id ); - - if( rc != 0 ) { - Debug( LDAP_DEBUG_ANY, - "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n", - pdn, rc, 0 ); - goto done; - } - ptr = pdn; - pdn = dn_parent( be, pdn ); } while( pdn != NULL ) { + if ( be_issuffix( be, pdn )) + break; pdn[-1] = DN_SUBTREE_PREFIX; - key.size -= pdn - ptr; - key.data = pdn - 1; rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id ); @@ -106,6 +94,8 @@ bdb_dn2id_add( } ptr = pdn; pdn = dn_parent( be, pdn ); + key.size -= pdn - ptr; + key.data = pdn - 1; } done: @@ -173,25 +163,13 @@ bdb_dn2id_delete( pdn, rc, 0 ); goto done; } - - pdn[-1] = DN_SUBTREE_PREFIX; - - rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id ); - - if( rc != 0 ) { - Debug( LDAP_DEBUG_ANY, - "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n", - pdn, rc, 0 ); - goto done; - } - ptr = pdn; - pdn = dn_parent( be, pdn ); } while( pdn != NULL ) { + if ( be_issuffix( be, pdn )) + break; + pdn[-1] = DN_SUBTREE_PREFIX; - key.size -= pdn - ptr; - key.data = pdn - 1; rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id ); if( rc != 0 ) { @@ -202,6 +180,8 @@ bdb_dn2id_delete( } ptr = pdn; pdn = dn_parent( be, pdn ); + key.size -= pdn - ptr; + key.data = pdn - 1; } done: diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 9743094340..2092b46f39 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -26,6 +26,7 @@ dn2id_add( int rc, flags; DBCache *db; Datum key, data; + char *buf, *ptr, *pdn; #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, @@ -51,8 +52,11 @@ dn2id_add( ldbm_datum_init( key ); key.dsize = strlen( dn ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); + buf = ch_malloc( key.dsize ); + key.dptr = buf; + buf[0] = DN_BASE_PREFIX; + ptr = buf + 1; + strcpy( ptr, dn ); ldbm_datum_init( data ); data.dptr = (char *) &id; @@ -61,46 +65,44 @@ dn2id_add( flags = LDBM_INSERT; rc = ldbm_cache_store( db, key, data, flags ); - free( key.dptr ); + if ( rc != -1 && !be_issuffix( be, ptr )) { + buf[0] = DN_SUBTREE_PREFIX; + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); + rc = idl_insert_key( be, db, key, id ); + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); + } if ( rc != -1 ) { - char *pdn = dn_parent( be, dn ); + pdn = dn_parent( be, ptr ); if( pdn != NULL ) { - ldbm_datum_init( key ); - key.dsize = strlen( pdn ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn ); + pdn[-1] = DN_ONE_PREFIX; + key.dsize -= pdn - ptr; + key.dptr = pdn - 1; ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); rc = idl_insert_key( be, db, key, id ); ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); - free( key.dptr ); } } - if ( rc != -1 ) { - char **subtree = dn_subtree( be, dn ); - - if( subtree != NULL ) { - int i; - for( i=0; subtree[i] != NULL; i++ ) { - ldbm_datum_init( key ); - key.dsize = strlen( subtree[i] ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", - DN_SUBTREE_PREFIX, subtree[i] ); - ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); - rc = idl_insert_key( be, db, key, id ); - ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); - free( key.dptr ); - - if(rc == -1) break; - } - - charray_free( subtree ); - } + while ( rc != -1 && pdn != NULL ) { + if ( be_issuffix( be, pdn )) + break; + + pdn[-1] = DN_SUBTREE_PREFIX; + + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); + rc = idl_insert_key( be, db, key, id ); + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); + + if( rc != 0 ) break; + ptr = pdn; + pdn = dn_parent( be, pdn ); + key.dsize -= pdn - ptr; + key.dptr = pdn - 1; } + free( buf ); ldbm_cache_close( be, db ); #ifdef NEW_LOGGING @@ -269,6 +271,7 @@ dn2id_delete( DBCache *db; Datum key; int rc; + char *buf, *ptr, *pdn; #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, @@ -294,56 +297,52 @@ dn2id_delete( return( -1 ); } + ldbm_datum_init( key ); + key.dsize = strlen( dn ) + 2; + buf = ch_malloc( key.dsize ); + key.dptr = buf; + buf[0] = DN_BASE_PREFIX; + ptr = buf + 1; + strcpy( ptr, dn ); - { - char *pdn = dn_parent( be, dn ); + rc = ldbm_cache_delete( db, key ); + + if( !be_issuffix( be, ptr )) { + buf[0] = DN_SUBTREE_PREFIX; + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); + (void) idl_delete_key( be, db, key, id ); + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); + } - if( pdn != NULL ) { - ldbm_datum_init( key ); - key.dsize = strlen( pdn ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn ); + pdn = dn_parent( be, ptr ); - ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); - (void) idl_delete_key( be, db, key, id ); - ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); + if( pdn != NULL ) { + pdn[-1] = DN_ONE_PREFIX; + key.dsize -= pdn - ptr; + key.dptr = pdn - 1; - free( key.dptr ); - } + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); + (void) idl_delete_key( be, db, key, id ); + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); } - { - char **subtree = dn_subtree( be, dn ); - - if( subtree != NULL ) { - int i; - for( i=0; subtree[i] != NULL; i++ ) { - ldbm_datum_init( key ); - key.dsize = strlen( subtree[i] ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", - DN_SUBTREE_PREFIX, subtree[i] ); + while ( pdn != NULL ) { + if ( be_issuffix( be, pdn )) + break; - ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); - (void) idl_delete_key( be, db, key, id ); - ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); + pdn[-1] = DN_SUBTREE_PREFIX; - free( key.dptr ); - } + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); + (void) idl_delete_key( be, db, key, id ); + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); - charray_free( subtree ); - } + ptr = pdn; + pdn = dn_parent( be, pdn ); + key.dsize -= pdn - ptr; + key.dptr = pdn - 1; } - ldbm_datum_init( key ); - - key.dsize = strlen( dn ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); - - rc = ldbm_cache_delete( db, key ); - - free( key.dptr ); + free( buf ); ldbm_cache_close( be, db ); -- 2.39.5