- /* add the entry to the entry cache */
- /* we should add to cache only upon free of txn-abort */
- if (bdb_cache_add_entry_rw(&bdb->bi_cache, e, CACHE_WRITE_LOCK) != 0) {
- text = "cache add failed";
- goto return_results;
- }
-
- Debug( LDAP_DEBUG_TRACE,
- "bdb_add: added id=%08lx dn=\"%s\"\n",
- e->e_id, e->e_dn, 0 );
- rc = LDAP_SUCCESS;
- text = NULL;
+ char gid[DB_XIDDATASIZE];
+
+ snprintf( gid, sizeof( gid ), "%s-%08lx-%08lx",
+ bdb_uuid.bv_val, (long) op->o_connid, (long) op->o_opid );
+
+ if (( rc=TXN_PREPARE( ltid, gid )) != 0 ) {
+ text = "txn_prepare failed";
+
+ } else {
+ int ret = bdb_cache_add_entry_rw(bdb->bi_dbenv,
+ &bdb->bi_cache, e, CACHE_WRITE_LOCK,
+ locker, &lock);
+#if 0
+ if ( bdb_cache_add_entry_rw(&bdb->bi_cache,
+ e, CACHE_WRITE_LOCK) != 0 )
+#endif
+ switch ( ret ) {
+ case 0:
+ break;
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ goto retry;
+ default:
+ ret = LDAP_OTHER;
+ }
+
+ if ( ret ) {
+ if(( rc=TXN_ABORT( ltid )) != 0 ) {
+ text = "cache add & txn_abort failed";
+ } else {
+ rc = LDAP_OTHER;
+ text = "cache add failed";
+ }
+ } else {
+ if(( rc=TXN_COMMIT( ltid, 0 )) != 0 ) {
+ text = "txn_commit failed";
+ } else {
+ rc = LDAP_SUCCESS;
+ }
+ }
+ }