/* get parent */
rc = bdb_dn2entry( be, ltid, pdn, &p, &matched, 0 );
- ch_free( pdn );
switch( rc ) {
case 0:
p = NULL;
} else {
- if( pdn != NULL ) {
- free(pdn);
- }
-
/*
* no parent!
* must be adding entry to at suffix
}
/* 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 );
}
done:
+ if( pdn != NULL ) {
+ free(pdn);
+ }
+
if (p != NULL) {
/* free parent and writer lock */
bdb_entry_return( be, p );
/* get parent */
rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
- ch_free( pdn );
-
switch( rc ) {
case 0:
case DB_NOTFOUND:
}
} 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 ) ) {
}
/* 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:
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 );
}
}
done:
+ if( pdn != NULL ) {
+ free( pdn );
+ }
+
/* free entry */
if( e != NULL ) {
bdb_entry_return( be, e );
bdb_dn2id_add(
BackendDB *be,
DB_TXN *txn,
- const char *dn,
- ID id )
+ const char *pdn,
+ Entry *e )
{
int rc;
DBT key, data;
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 );
}
{
- char *pdn = dn_parent( NULL, dn );
((char *)(key.data))[0] = DN_ONE_PREFIX;
if( pdn != NULL ) {
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;
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,
bdb_dn2id_delete(
BackendDB *be,
DB_TXN *txn,
+ const char *pdn,
const char *dn,
ID id )
{
((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",
}
{
- char *pdn = dn_parent( NULL, dn );
((char *)(key.data))[0] = DN_ONE_PREFIX;
if( pdn != NULL ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
pdn, rc, 0 );
- free( pdn );
goto done;
}
- free( pdn );
}
}
#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;
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_update(
+int bdb_id2entry_add(
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 );
+ return bdb_id2entry_put( be, tid, e, DB_NOOVERWRITE );
+}
- free( bv.bv_val );
- return rc;
+int bdb_id2entry_update(
+ BackendDB *be,
+ DB_TXN *tid,
+ Entry *e )
+{
+ return bdb_id2entry_put( be, tid, e, 0 );
}
int bdb_id2entry(
}
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.
}
/* 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:
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:
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 );
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 );
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 );
}
/* 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",
int rc;
Entry *e;
DB_TXN *tid = NULL;
+ char *pdn;
Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n",
(long) id, 0, 0 );
(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 );