Blame SOURCES/0056-Ticket-47598-Convert-ldbm_back_seq-code-to-be-transa.patch

cc3dff
From 88315fddb145da4d3d0601d020c61b25aed66366 Mon Sep 17 00:00:00 2001
cc3dff
From: Mark Reynolds <mreynolds@redhat.com>
cc3dff
Date: Tue, 19 Nov 2013 09:45:03 -0500
cc3dff
Subject: [PATCH 56/65] Ticket 47598 - Convert ldbm_back_seq code to be
cc3dff
 transaction aware
cc3dff
cc3dff
Description: Attempt to retrieve the transaction,  and pass it to the db
cc3dff
             functions, and id2entry.  Also did a little code cleanup.
cc3dff
cc3dff
https://fedorahosted.org/389/ticket/47598
cc3dff
cc3dff
Reviewed by: richm(Thanks!)
cc3dff
(cherry picked from commit 50272119bbff52c5d9b6ce5d7302aef763aa96ec)
cc3dff
(cherry picked from commit da9fed74c2a04dc45b4354f436e70020bcbd7cd2)
cc3dff
---
cc3dff
 ldap/servers/slapd/back-ldbm/seq.c | 61 +++++++++++++++++++++-----------------
cc3dff
 1 file changed, 34 insertions(+), 27 deletions(-)
cc3dff
cc3dff
diff --git a/ldap/servers/slapd/back-ldbm/seq.c b/ldap/servers/slapd/back-ldbm/seq.c
cc3dff
index ab473bd..27da2a4 100644
cc3dff
--- a/ldap/servers/slapd/back-ldbm/seq.c
cc3dff
+++ b/ldap/servers/slapd/back-ldbm/seq.c
cc3dff
@@ -68,20 +68,21 @@
cc3dff
 int
cc3dff
 ldbm_back_seq( Slapi_PBlock *pb )
cc3dff
 {
cc3dff
-	backend *be;
cc3dff
-	ldbm_instance *inst;
cc3dff
-	struct ldbminfo		*li;
cc3dff
-	IDList			*idl = NULL;
cc3dff
-	int			err = LDAP_SUCCESS;
cc3dff
-	DB		*db;
cc3dff
-	DBC		*dbc = NULL;
cc3dff
-	int			type;
cc3dff
-	char			*attrname, *val;
cc3dff
-	int			isroot;
cc3dff
+	backend         *be;
cc3dff
+	ldbm_instance   *inst;
cc3dff
+	struct ldbminfo *li;
cc3dff
+	IDList          *idl = NULL;
cc3dff
+	back_txn        txn = {NULL};
cc3dff
 	struct attrinfo	*ai = NULL;
cc3dff
+	DB              *db;
cc3dff
+	DBC             *dbc = NULL;
cc3dff
+	char *attrname, *val;
cc3dff
+	int err = LDAP_SUCCESS;
cc3dff
 	int return_value = -1;
cc3dff
-	int	nentries = 0;
cc3dff
-	int retry_count=0;
cc3dff
+	int nentries = 0;
cc3dff
+	int retry_count = 0;
cc3dff
+	int isroot;
cc3dff
+	int type;
cc3dff
 
cc3dff
 	/* Decode arguments */
cc3dff
 	slapi_pblock_get( pb, SLAPI_BACKEND, &be);
cc3dff
@@ -90,9 +91,15 @@ ldbm_back_seq( Slapi_PBlock *pb )
cc3dff
 	slapi_pblock_get( pb, SLAPI_SEQ_ATTRNAME, &attrname );
cc3dff
 	slapi_pblock_get( pb, SLAPI_SEQ_VAL, &val );
cc3dff
 	slapi_pblock_get( pb, SLAPI_REQUESTOR_ISROOT, &isroot );
cc3dff
+	slapi_pblock_get( pb, SLAPI_TXN, &txn.back_txn_txn );
cc3dff
 
cc3dff
 	inst = (ldbm_instance *) be->be_instance_info;
cc3dff
 
cc3dff
+	if ( !txn.back_txn_txn ) {
cc3dff
+		dblayer_txn_init( li, &txn );
cc3dff
+		slapi_pblock_set( pb, SLAPI_TXN, txn.back_txn_txn );
cc3dff
+	}
cc3dff
+
cc3dff
 	/* Validate arguments */
cc3dff
 	if ( type != SLAPI_SEQ_FIRST &&
cc3dff
 	     type != SLAPI_SEQ_LAST &&
cc3dff
@@ -114,7 +121,7 @@ ldbm_back_seq( Slapi_PBlock *pb )
cc3dff
 		LDAPDebug( LDAP_DEBUG_TRACE,
cc3dff
 		    "seq: caller specified un-indexed attribute %s\n",
cc3dff
 			   attrname ? attrname : "", 0, 0 );
cc3dff
-	    slapi_send_ldap_result( pb, LDAP_UNWILLING_TO_PERFORM, NULL,
cc3dff
+		slapi_send_ldap_result( pb, LDAP_UNWILLING_TO_PERFORM, NULL,
cc3dff
 		    "Unindexed seq access type", 0, NULL );
cc3dff
 		return -1;
cc3dff
 	}
cc3dff
@@ -123,13 +130,13 @@ ldbm_back_seq( Slapi_PBlock *pb )
cc3dff
 		LDAPDebug( LDAP_DEBUG_ANY,
cc3dff
 		    "<= ldbm_back_seq NULL (could not open index file for attribute %s)\n",
cc3dff
 		    attrname, 0, 0 );
cc3dff
-	    slapi_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, NULL, 0, NULL );
cc3dff
+		slapi_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, NULL, 0, NULL );
cc3dff
 		return -1;
cc3dff
 	}
cc3dff
 
cc3dff
 	/* First, get a database cursor */
cc3dff
 
cc3dff
-	return_value = db->cursor(db,NULL,&dbc,0);
cc3dff
+	return_value = db->cursor(db, txn.back_txn_txn, &dbc, 0);
cc3dff
 
cc3dff
 	if (0 == return_value)
cc3dff
 	{
cc3dff
@@ -160,7 +167,7 @@ ldbm_back_seq( Slapi_PBlock *pb )
cc3dff
 				big_buffer = slapi_ch_malloc(key_length);
cc3dff
 				if (NULL == big_buffer) {
cc3dff
 					/* memory allocation failure */
cc3dff
-                                        dblayer_release_index_file( be, ai, db );
cc3dff
+					dblayer_release_index_file( be, ai, db );
cc3dff
 					return -1;
cc3dff
 				}
cc3dff
 				key.data = big_buffer;
cc3dff
@@ -234,24 +241,24 @@ ldbm_back_seq( Slapi_PBlock *pb )
cc3dff
 				/* Retrieve the idlist for this key */
cc3dff
 				key.flags = 0;
cc3dff
 				for (retry_count = 0; retry_count < IDL_FETCH_RETRY_COUNT; retry_count++) {
cc3dff
-				  err = NEW_IDL_DEFAULT;
cc3dff
-				  idl = idl_fetch( be, db, &key, NULL, ai, &err );
cc3dff
-				  if(err == DB_LOCK_DEADLOCK) {
cc3dff
-				    ldbm_nasty("ldbm_back_seq deadlock retry", 1600, err);
cc3dff
+					err = NEW_IDL_DEFAULT;
cc3dff
+					idl = idl_fetch( be, db, &key, txn.back_txn_txn, ai, &err );
cc3dff
+					if(err == DB_LOCK_DEADLOCK) {
cc3dff
+						ldbm_nasty("ldbm_back_seq deadlock retry", 1600, err);
cc3dff
 #ifdef FIX_TXN_DEADLOCKS
cc3dff
 #error if txn != NULL, have to retry the entire transaction
cc3dff
 #endif
cc3dff
-				    continue;
cc3dff
-				  } else {
cc3dff
-				    break;
cc3dff
-				  }
cc3dff
+						continue;
cc3dff
+					} else {
cc3dff
+						break;
cc3dff
+					}
cc3dff
 				}
cc3dff
 			}
cc3dff
 		}
cc3dff
 		if(retry_count == IDL_FETCH_RETRY_COUNT) {
cc3dff
-		  ldbm_nasty("ldbm_back_seq retry count exceeded",1645,err);
cc3dff
+			ldbm_nasty("ldbm_back_seq retry count exceeded",1645,err);
cc3dff
 		} else if ( err != 0 && err != DB_NOTFOUND ) {
cc3dff
-		  ldbm_nasty("ldbm_back_seq database error", 1650, err);
cc3dff
+			ldbm_nasty("ldbm_back_seq database error", 1650, err);
cc3dff
 		}
cc3dff
 		slapi_ch_free( &(data.data) );
cc3dff
 		if ( key.data != little_buffer && key.data != &keystring ) {
cc3dff
@@ -272,7 +279,7 @@ ldbm_back_seq( Slapi_PBlock *pb )
cc3dff
 		for ( id = idl_firstid( idl ); id != NOID;
cc3dff
 			id = idl_nextid( idl, id ))
cc3dff
 		{
cc3dff
-		    if (( e = id2entry( be, id, NULL, &err )) == NULL )
cc3dff
+		    if (( e = id2entry( be, id, &txn, &err )) == NULL )
cc3dff
 		    {
cc3dff
 				if ( err != LDAP_SUCCESS )
cc3dff
 				{
cc3dff
-- 
cc3dff
1.8.1.4
cc3dff