From aa54899993d7c9e558fead305c4c942464c9870b Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 16 Apr 2005 21:00:08 +0000 Subject: [PATCH] ITS#3666 cleanup --- servers/slapd/back-bdb/ctxcsn.c | 61 ++++++--------------------------- 1 file changed, 10 insertions(+), 51 deletions(-) diff --git a/servers/slapd/back-bdb/ctxcsn.c b/servers/slapd/back-bdb/ctxcsn.c index 88ed6e9856..26537e6870 100644 --- a/servers/slapd/back-bdb/ctxcsn.c +++ b/servers/slapd/back-bdb/ctxcsn.c @@ -70,6 +70,7 @@ bdb_csn_commit( } *ctxcsn_e = ctxcsn_ei->bei_e; + *ctxcsn_added = 0; slap_get_commit_csn( op, &max_committed_csn ); @@ -77,8 +78,6 @@ bdb_csn_commit( return BDB_CSN_COMMIT; } - *ctxcsn_added = 0; - switch( rc ) { case 0: if ( !*ctxcsn_e ) { @@ -87,29 +86,25 @@ bdb_csn_commit( op->o_tmpfree( max_committed_csn.bv_val, op->o_tmpmemctx ); return BDB_CSN_ABORT; } else { - Modifications mod; struct berval modvals[2]; - Entry dummy; modvals[0] = max_committed_csn; modvals[1].bv_val = NULL; modvals[1].bv_len = 0; - mod.sml_op = LDAP_MOD_REPLACE; - mod.sml_values = modvals; - mod.sml_nvalues = NULL; - mod.sml_desc = slap_schema.si_ad_contextCSN; - mod.sml_type = mod.sml_desc->ad_cname; - mod.sml_next = NULL; + attr_delete( &(*ctxcsn_e)->e_attrs, slap_schema.si_ad_contextCSN ); + ret = attr_merge( *ctxcsn_e, slap_schema.si_ad_contextCSN, + modvals, NULL ); - dummy = **ctxcsn_e; - ret = bdb_modify_internal( op, tid, &mod, &dummy, - &rs->sr_text, textbuf, textlen ); op->o_tmpfree( max_committed_csn.bv_val, op->o_tmpmemctx ); if ( ret != LDAP_SUCCESS ) { + /* destroy the cached copy since it is now corrupted */ + ctxcsn_ei->bei_e = NULL; + (*ctxcsn_e)->e_private = NULL; + entry_free( *ctxcsn_e ); + *ctxcsn_e = NULL; Debug( LDAP_DEBUG_TRACE, "bdb_csn_commit: modify failed (%d)\n", rs->sr_err, 0, 0 ); - if ( dummy.e_attrs != e->e_attrs ) attrs_free( dummy.e_attrs ); switch( ret ) { case DB_LOCK_DEADLOCK: case DB_LOCK_NOTGRANTED: @@ -119,29 +114,18 @@ bdb_csn_commit( } } - ret = bdb_id2entry_update( op->o_bd, tid, &dummy ); + ret = bdb_id2entry_update( op->o_bd, tid, *ctxcsn_e ); switch ( ret ) { case 0 : break; case DB_LOCK_DEADLOCK : case DB_LOCK_NOTGRANTED : - if ( dummy.e_attrs != e->e_attrs ) attrs_free( dummy.e_attrs ); goto rewind; default : - if ( dummy.e_attrs != e->e_attrs ) attrs_free( dummy.e_attrs ); rs->sr_err = ret; rs->sr_text = "context csn update failed"; return BDB_CSN_ABORT; } - ret = bdb_cache_modify( *ctxcsn_e, dummy.e_attrs, bdb->bi_dbenv, locker, &ctxcsn_lock ); - if ( ret != LDAP_SUCCESS ) { - if ( dummy.e_attrs != e->e_attrs ) attrs_free( dummy.e_attrs ); - switch( ret ) { - case DB_LOCK_DEADLOCK: - case DB_LOCK_NOTGRANTED: - goto rewind; - } - } } break; case DB_NOTFOUND: @@ -203,32 +187,7 @@ bdb_csn_commit( rs->sr_text = "context csn store failed"; return BDB_CSN_ABORT; } - ret = bdb_index_entry_add( op, tid, *ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn indexing failed"; - return BDB_CSN_ABORT; - } break; - case DB_LOCK_DEADLOCK: - case DB_LOCK_NOTGRANTED: - Debug( LDAP_DEBUG_TRACE, - "bdb_csn_commit : bdb_dn2entry retry\n", 0, 0, 0 ); - goto rewind; - case LDAP_BUSY: - rs->sr_err = rc; - rs->sr_text = "ldap server busy"; - return BDB_CSN_ABORT; - default: - rs->sr_err = LDAP_OTHER; - rs->sr_text = "internal error"; - return BDB_CSN_ABORT; } return BDB_CSN_COMMIT; -- 2.47.2