Minor rearrangement, give pdn to dn2id_add to avoid getting it twice.

This commit is contained in:
Howard Chu 2001-12-06 03:26:37 +00:00
parent 575c9469d9
commit 6e0861b671
7 changed files with 61 additions and 60 deletions

View file

@ -100,7 +100,6 @@ retry: rc = txn_abort( ltid );
/* get parent */
rc = bdb_dn2entry( be, ltid, pdn, &p, &matched, 0 );
ch_free( pdn );
switch( rc ) {
case 0:
@ -188,10 +187,6 @@ retry: rc = txn_abort( ltid );
p = NULL;
} else {
if( pdn != NULL ) {
free(pdn);
}
/*
* no parent!
* must be adding entry to at suffix
@ -227,7 +222,7 @@ retry: rc = txn_abort( ltid );
}
/* dn2id index */
rc = bdb_dn2id_add( be, ltid, e->e_ndn, e->e_id );
rc = bdb_dn2id_add( be, ltid, pdn, e );
if ( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb_add: dn2id_add failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
@ -309,6 +304,10 @@ return_results:
}
done:
if( pdn != NULL ) {
free(pdn);
}
if (p != NULL) {
/* free parent and writer lock */
bdb_entry_return( be, p );

View file

@ -122,8 +122,6 @@ retry: /* transaction retry */
/* get parent */
rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
ch_free( pdn );
switch( rc ) {
case 0:
case DB_NOTFOUND:
@ -162,8 +160,6 @@ retry: /* transaction retry */
}
} else {
ch_free( pdn );
/* no parent, must be root to delete */
if( ! be_isroot( be, op->o_ndn ) ) {
if ( be_issuffix( be, "" ) || be_isupdate( be, op->o_ndn ) ) {
@ -235,7 +231,7 @@ retry: /* transaction retry */
}
/* delete from dn2id */
rc = bdb_dn2id_delete( be, ltid, e->e_ndn, e->e_id );
rc = bdb_dn2id_delete( be, ltid, pdn, e->e_ndn, e->e_id );
if ( rc != 0 ) {
switch( rc ) {
case DB_LOCK_DEADLOCK:
@ -284,6 +280,15 @@ retry: /* transaction retry */
goto return_results;
}
#if 0 /* Do we want to reclaim deleted IDs? */
ldap_pvt_thread_mutex_lock( &bdb->bi_lastid_mutex );
if ( e->e_id == bdb->bi_lastid ) {
bdb_last_id( be, ltid );
}
ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex );
#endif
if( bdb->bi_txn ) {
rc = txn_commit( ltid, 0 );
}
@ -316,6 +321,10 @@ return_results:
}
done:
if( pdn != NULL ) {
free( pdn );
}
/* free entry */
if( e != NULL ) {
bdb_entry_return( be, e );

View file

@ -17,8 +17,8 @@ int
bdb_dn2id_add(
BackendDB *be,
DB_TXN *txn,
const char *dn,
ID id )
const char *pdn,
Entry *e )
{
int rc;
DBT key, data;
@ -26,18 +26,18 @@ bdb_dn2id_add(
DB *db = bdb->bi_dn2id->bdi_db;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n",
dn, (long) id, 0 );
assert( id != NOID );
e->e_ndn, (long) e->e_id, 0 );
assert( e->e_id != NOID );
DBTzero( &key );
key.size = strlen( dn ) + 2;
key.size = strlen( e->e_ndn ) + 2;
key.data = ch_malloc( key.size );
((char *)key.data)[0] = DN_BASE_PREFIX;
AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
AC_MEMCPY( &((char *)key.data)[1], e->e_ndn, key.size - 1 );
DBTzero( &data );
data.data = (char *) &id;
data.size = sizeof( id );
data.data = (char *) &e->e_id;
data.size = sizeof( e->e_id );
/* store it -- don't override */
rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
@ -48,7 +48,6 @@ bdb_dn2id_add(
}
{
char *pdn = dn_parent( NULL, dn );
((char *)(key.data))[0] = DN_ONE_PREFIX;
if( pdn != NULL ) {
@ -56,21 +55,19 @@ bdb_dn2id_add(
AC_MEMCPY( &((char*)key.data)[1],
pdn, key.size - 1 );
rc = bdb_idl_insert_key( be, db, txn, &key, id );
rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
pdn, rc, 0 );
free( pdn );
goto done;
}
free( pdn );
}
}
{
char **subtree = dn_subtree( be, dn );
char **subtree = dn_subtree( be, e->e_ndn );
if( subtree != NULL ) {
int i;
@ -80,7 +77,8 @@ bdb_dn2id_add(
AC_MEMCPY( &((char *)key.data)[1],
subtree[i], key.size - 1 );
rc = bdb_idl_insert_key( be, db, txn, &key, id );
rc = bdb_idl_insert_key( be, db, txn, &key,
e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
@ -104,6 +102,7 @@ int
bdb_dn2id_delete(
BackendDB *be,
DB_TXN *txn,
const char *pdn,
const char *dn,
ID id )
{
@ -121,7 +120,7 @@ bdb_dn2id_delete(
((char *)key.data)[0] = DN_BASE_PREFIX;
AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
/* store it -- don't override */
/* delete it */
rc = db->del( db, txn, &key, 0 );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: delete failed: %s %d\n",
@ -130,7 +129,6 @@ bdb_dn2id_delete(
}
{
char *pdn = dn_parent( NULL, dn );
((char *)(key.data))[0] = DN_ONE_PREFIX;
if( pdn != NULL ) {
@ -144,10 +142,8 @@ bdb_dn2id_delete(
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
pdn, rc, 0 );
free( pdn );
goto done;
}
free( pdn );
}
}

View file

@ -12,10 +12,11 @@
#include "back-bdb.h"
int bdb_id2entry_add(
int bdb_id2entry_put(
BackendDB *be,
DB_TXN *tid,
Entry *e )
Entry *e,
int flag )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_id2entry->bdi_db;
@ -35,39 +36,26 @@ int bdb_id2entry_add(
DBTzero( &data );
bv2DBT( &bv, &data );
rc = db->put( db, tid, &key, &data, DB_NOOVERWRITE );
rc = db->put( db, tid, &key, &data, flag );
free( bv.bv_val );
return rc;
}
int bdb_id2entry_add(
BackendDB *be,
DB_TXN *tid,
Entry *e )
{
return bdb_id2entry_put( be, tid, e, DB_NOOVERWRITE );
}
int bdb_id2entry_update(
BackendDB *be,
DB_TXN *tid,
Entry *e )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_id2entry->bdi_db;
DBT key, data;
struct berval bv;
int rc;
DBTzero( &key );
key.data = (char *) &e->e_id;
key.size = sizeof(ID);
rc = entry_encode( e, &bv );
if( rc != LDAP_SUCCESS ) {
return -1;
}
DBTzero( &data );
bv2DBT( &bv, &data );
rc = db->put( db, tid, &key, &data, 0 );
free( bv.bv_val );
return rc;
return bdb_id2entry_put( be, tid, e, 0 );
}
int bdb_id2entry(

View file

@ -161,6 +161,7 @@ retry: /* transaction retry */
}
p_ndn = dn_parent( be, e->e_ndn );
np_ndn = p_ndn;
if ( p_ndn != NULL && p_ndn[ 0 ] != '\0' ) {
/* Make sure parent entry exist and we can write its
* children.
@ -550,7 +551,7 @@ retry: /* transaction retry */
}
/* delete old one */
rc = bdb_dn2id_delete( be, ltid, e->e_ndn, e->e_id );
rc = bdb_dn2id_delete( be, ltid, p_ndn, e->e_ndn, e->e_id );
if ( rc != 0 ) {
switch( rc ) {
case DB_LOCK_DEADLOCK:
@ -570,7 +571,7 @@ retry: /* transaction retry */
e->e_ndn = new_ndn;
/* add new one */
rc = bdb_dn2id_add( be, ltid, e->e_ndn, e->e_id );
rc = bdb_dn2id_add( be, ltid, np_ndn, e );
if ( rc != 0 ) {
switch( rc ) {
case DB_LOCK_DEADLOCK:
@ -642,6 +643,7 @@ done:
if( new_dn != NULL ) free( new_dn );
if( new_ndn != NULL ) free( new_ndn );
if( np_ndn == p_ndn ) np_ndn = NULL;
if( p_dn != NULL ) free( p_dn );
if( p_ndn != NULL ) free( p_ndn );

View file

@ -82,12 +82,13 @@ int bdb_dn2id_matched(
int bdb_dn2id_add(
BackendDB *be,
DB_TXN *tid,
const char *dn,
ID id );
const char *pdn,
Entry *e );
int bdb_dn2id_delete(
BackendDB *be,
DB_TXN *tid,
const char *pdn,
const char *dn,
ID id );

View file

@ -113,6 +113,7 @@ ID bdb_tool_entry_put(
int rc;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB_TXN *tid = NULL;
char *pdn;
assert( be != NULL );
assert( slapMode & SLAP_TOOL_MODE );
@ -140,7 +141,9 @@ ID bdb_tool_entry_put(
}
/* add dn2id indices */
pdn = dn_parent( be, e->e_ndn );
rc = bdb_dn2id_add( be, tid, e->e_ndn, e->e_id );
if( pdn ) free( pdn );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_tool_entry_put: dn2id_add failed: %s (%d)\n",
@ -196,6 +199,7 @@ int bdb_tool_entry_reindex(
int rc;
Entry *e;
DB_TXN *tid = NULL;
char *pdn;
Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n",
(long) id, 0, 0 );
@ -230,8 +234,10 @@ int bdb_tool_entry_reindex(
(long) id, e->e_dn, 0 );
/* add dn2id indices */
rc = bdb_dn2id_add( be, tid, e->e_ndn, e->e_id );
if( rc != 0 ) {
pdn = dn_parent( be, e->e_ndn );
rc = bdb_dn2id_add( be, tid, pdn, e );
if( pdn ) free( pdn );
if( rc != 0 && rc != DB_KEYEXIST ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_tool_entry_reindex: dn2id_add failed: %s (%d)\n",
db_strerror(rc), rc, 0 );