)
{
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
- struct berval ctxcsn_ndn = BER_BVNULL;
EntryInfo *ctxcsn_ei = NULL;
DB_LOCK ctxcsn_lock;
struct berval max_committed_csn;
size_t textlen = sizeof textbuf;
EntryInfo *eip = NULL;
+ assert( !BER_BVISNULL( &op->o_bd->be_context_csn ) );
+
if ( ei ) {
e = ei->bei_e;
}
- build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0],
- (struct berval *)&slap_ldapsync_cn_bv, op->o_tmpmemctx );
-
- rc = bdb_dn2entry( op, tid, &ctxcsn_ndn, &ctxcsn_ei,
+ rc = bdb_dn2entry( op, tid, &op->o_bd->be_context_csn, &ctxcsn_ei,
1, locker, &ctxcsn_lock );
+ switch( rc ) {
+ case 0:
+ case DB_NOTFOUND:
+ break;
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ return BDB_CSN_RETRY;
+ default:
+ return BDB_CSN_ABORT;
+ }
*ctxcsn_e = ctxcsn_ei->bei_e;
- op->o_tmpfree( ctxcsn_ndn.bv_val, op->o_tmpmemctx );
-
slap_get_commit_csn( op, &max_committed_csn );
if ( max_committed_csn.bv_val == NULL ) {
if ( !*ctxcsn_e ) {
rs->sr_err = LDAP_OTHER;
rs->sr_text = "context csn not present";
- ch_free( max_committed_csn.bv_val );
+ op->o_tmpfree( max_committed_csn.bv_val, op->o_tmpmemctx );
return BDB_CSN_ABORT;
} else {
Modifications mod;
modvals[1].bv_len = 0;
mod.sml_op = LDAP_MOD_REPLACE;
- mod.sml_bvalues = modvals;
+ mod.sml_values = modvals;
mod.sml_nvalues = NULL;
mod.sml_desc = slap_schema.si_ad_contextCSN;
mod.sml_type = mod.sml_desc->ad_cname;
dummy = **ctxcsn_e;
ret = bdb_modify_internal( op, tid, &mod, &dummy,
&rs->sr_text, textbuf, textlen );
- ch_free( max_committed_csn.bv_val );
+ op->o_tmpfree( max_committed_csn.bv_val, op->o_tmpmemctx );
if ( ret != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ERR,
}
*ctxcsn_e = slap_create_context_csn_entry( op->o_bd, &max_committed_csn );
- ch_free( max_committed_csn.bv_val );
+ op->o_tmpfree( max_committed_csn.bv_val, op->o_tmpmemctx );
(*ctxcsn_e)->e_id = ctxcsn_id;
*ctxcsn_added = 1;
goto rewind;
case DB_KEYEXIST :
rs->sr_err = LDAP_OTHER;
- rs->sr_text = "context csn exists before contex prefix does";
+ rs->sr_text = "context csn exists before context prefix does";
return BDB_CSN_ABORT;
default :
rs->sr_err = LDAP_OTHER;
)
{
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
- struct berval ctxcsn_ndn = BER_BVNULL;
struct berval csn = BER_BVNULL;
EntryInfo *ctxcsn_ei = NULL;
EntryInfo *suffix_ei = NULL;
int rc;
struct sync_cookie syncCookie = { NULL, -1, NULL};
syncinfo_t *si;
+ u_int32_t ctxcsn_locker = 0;
if ( op->o_sync_mode != SLAP_SYNC_NONE &&
!LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
char substr[67];
+ struct berval ctxcsn_ndn = BER_BVNULL;
struct berval bv;
LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
sprintf( substr, "cn=syncrepl%ld", si->si_rid );
ber_str2bv( substr, 0, 0, &bv );
- build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &bv, NULL );
+ build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &bv, op->o_tmpmemctx );
consumer_ctxcsn_retry :
rs->sr_err = bdb_dn2entry( op, NULL, &ctxcsn_ndn, &ctxcsn_ei,
0, locker, ctxcsn_lock );
switch(rs->sr_err) {
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ goto consumer_ctxcsn_retry;
case 0:
- ch_free( ctxcsn_ndn.bv_val );
+ op->o_tmpfree( ctxcsn_ndn.bv_val, op->o_tmpmemctx );
ctxcsn_ndn.bv_val = NULL;
if ( ctxcsn_ei ) {
ctxcsn_e = ctxcsn_ei->bei_e;
}
break;
- case LDAP_BUSY:
- ch_free( ctxcsn_ndn.bv_val );
- LOCK_ID_FREE (bdb->bi_dbenv, locker );
- return LDAP_BUSY;
- case DB_LOCK_DEADLOCK:
- case DB_LOCK_NOTGRANTED:
- goto consumer_ctxcsn_retry;
case DB_NOTFOUND:
- ch_free( ctxcsn_ndn.bv_val );
- LOCK_ID_FREE( bdb->bi_dbenv, locker );
- return LDAP_OTHER;
default:
- ch_free( ctxcsn_ndn.bv_val );
+ rs->sr_err = LDAP_OTHER;
+ case LDAP_BUSY:
+ op->o_tmpfree( ctxcsn_ndn.bv_val, op->o_tmpmemctx );
ctxcsn_ndn.bv_val = NULL;
- LOCK_ID_FREE (bdb->bi_dbenv, locker );
- return LDAP_OTHER;
+ goto done;
}
if ( ctxcsn_e ) {
}
} else if ( op->o_sync_mode != SLAP_SYNC_NONE &&
LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
- build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0],
- (struct berval *)&slap_ldapsync_cn_bv, NULL );
provider_ctxcsn_retry :
- rs->sr_err = bdb_dn2entry( op, NULL, &ctxcsn_ndn, &ctxcsn_ei,
+ rs->sr_err = bdb_dn2entry( op, NULL, &op->o_bd->be_context_csn, &ctxcsn_ei,
0, locker, ctxcsn_lock );
switch(rs->sr_err) {
case 0:
- ch_free( ctxcsn_ndn.bv_val );
if ( ctxcsn_ei ) {
ctxcsn_e = ctxcsn_ei->bei_e;
}
break;
case LDAP_BUSY:
- ch_free( ctxcsn_ndn.bv_val );
- LOCK_ID_FREE (bdb->bi_dbenv, locker );
- return LDAP_BUSY;
+ goto done;
case DB_LOCK_DEADLOCK:
case DB_LOCK_NOTGRANTED:
goto provider_ctxcsn_retry;
if ( 0 ) {
txn_retry:
rs->sr_err = TXN_ABORT( ltid );
+ ltid = NULL;
if ( rs->sr_err != 0 ) {
rs->sr_err = LDAP_OTHER;
- return rs->sr_err;
+ goto done;
}
ldap_pvt_thread_yield();
bdb_trans_backoff( ++num_retries );
<id, bdb->bi_db_opflags );
if ( rs->sr_err != 0 ) {
rs->sr_err = LDAP_OTHER;
- return rs->sr_err;
+ goto done;
}
+ ctxcsn_locker = TXN_ID ( ltid );
+
rs->sr_err = bdb_csn_commit( op, rs, ltid, NULL, &suffix_ei,
- &ctxcsn_e, &ctxcsn_added, locker );
+ &ctxcsn_e, &ctxcsn_added, ctxcsn_locker );
switch( rs->sr_err ) {
case BDB_CSN_ABORT:
- LOCK_ID_FREE( bdb->bi_dbenv, locker );
- return LDAP_OTHER;
+ rs->sr_err = LDAP_OTHER;
+ goto done;
case BDB_CSN_RETRY:
goto txn_retry;
}
rs->sr_err = TXN_PREPARE( ltid, gid );
if ( rs->sr_err != 0 ) {
rs->sr_err = LDAP_OTHER;
- return rs->sr_err;
+ goto done;
}
bdb_cache_add( bdb, suffix_ei, ctxcsn_e,
- (struct berval *)&slap_ldapsync_cn_bv, locker );
+ (struct berval *)&slap_ldapsync_cn_bv, ctxcsn_locker );
rs->sr_err = TXN_COMMIT( ltid, 0 );
if ( rs->sr_err != 0 ) {
rs->sr_err = LDAP_OTHER;
- return rs->sr_err;
+ goto done;
}
- rs->sr_err = bdb_dn2entry( op, NULL, &ctxcsn_ndn, &ctxcsn_ei,
- 0, locker, ctxcsn_lock );
- ch_free( ctxcsn_ndn.bv_val );
+ rs->sr_err = bdb_dn2entry( op, NULL, &op->o_bd->be_context_csn, &ctxcsn_ei,
+ 0, ctxcsn_locker, ctxcsn_lock );
if ( ctxcsn_ei ) {
ctxcsn_e = ctxcsn_ei->bei_e;
break;
default:
- ch_free( ctxcsn_ndn.bv_val );
- LOCK_ID_FREE (bdb->bi_dbenv, locker );
- return LDAP_OTHER;
+ rs->sr_err = LDAP_OTHER;
+ goto done;
}
if ( ctxcsn_e ) {
}
}
- return LDAP_SUCCESS;
+ ltid = NULL;
+ rs->sr_err = LDAP_SUCCESS;
+
+done:
+ if( ltid != NULL ) {
+ TXN_ABORT( ltid );
+ }
+
+ return rs->sr_err;
}