svn commit: samba r16071 - in branches/SAMBA_4_0/source/lib/ldb/common: .

idra at samba.org idra at samba.org
Wed Jun 7 00:55:49 GMT 2006


Author: idra
Date: 2006-06-07 00:55:48 +0000 (Wed, 07 Jun 2006)
New Revision: 16071

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16071

Log:

tdb has nested transactions
change the code to exploit that in ldb

I still have to reintroduce transactions when you call ldb_request directly,
I have some plans I hop to be able to develop in the next weekend


Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2006-06-07 00:42:19 UTC (rev 16070)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2006-06-07 00:55:48 UTC (rev 16071)
@@ -171,13 +171,11 @@
 /*
   start a transaction
 */
-int ldb_transaction_start(struct ldb_context *ldb)
+static int ldb_transaction_start_internal(struct ldb_context *ldb)
 {
 	struct ldb_module *module;
 	int status;
 	FIRST_OP(ldb, start_transaction);
-	
-	ldb->transaction_active++;
 
 	ldb_reset_err_string(ldb);
 
@@ -195,18 +193,12 @@
 /*
   commit a transaction
 */
-int ldb_transaction_commit(struct ldb_context *ldb)
+static int ldb_transaction_commit_internal(struct ldb_context *ldb)
 {
 	struct ldb_module *module;
 	int status;
 	FIRST_OP(ldb, end_transaction);
 
-	if (ldb->transaction_active > 0) {
-		ldb->transaction_active--;
-	} else {
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-
 	ldb_reset_err_string(ldb);
 
 	status = module->ops->end_transaction(module);
@@ -223,18 +215,12 @@
 /*
   cancel a transaction
 */
-int ldb_transaction_cancel(struct ldb_context *ldb)
+static int ldb_transaction_cancel_internal(struct ldb_context *ldb)
 {
 	struct ldb_module *module;
 	int status;
 	FIRST_OP(ldb, del_transaction);
 
-	if (ldb->transaction_active > 0) {
-		ldb->transaction_active--;
-	} else {
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-
 	status = module->ops->del_transaction(module);
 	if (status != LDB_SUCCESS) {
 		if (ldb->err_string == NULL) {
@@ -246,6 +232,89 @@
 	return status;
 }
 
+int ldb_transaction_start(struct ldb_context *ldb)
+{
+	/* disable autotransactions */
+	ldb->transaction_active++;
+
+	return ldb_transaction_start_internal(ldb);
+}
+
+int ldb_transaction_commit(struct ldb_context *ldb)
+{
+	/* renable autotransactions (when we reach 0) */
+	if (ldb->transaction_active > 0)
+		ldb->transaction_active--;
+
+	return ldb_transaction_commit_internal(ldb);
+}
+
+int ldb_transaction_cancel(struct ldb_context *ldb)
+{
+	/* renable autotransactions (when we reach 0) */
+	if (ldb->transaction_active > 0)
+		ldb->transaction_active--;
+
+	return ldb_transaction_cancel_internal(ldb);
+}
+
+int ldb_autotransaction_start(struct ldb_context *ldb)
+{
+	/* explicit transaction active, ignore autotransaction request */
+	if (ldb->transaction_active)
+		return LDB_SUCCESS;
+
+	return ldb_transaction_start_internal(ldb);
+}
+
+int ldb_autotransaction_commit(struct ldb_context *ldb)
+{
+	/* explicit transaction active, ignore autotransaction request */
+	if (ldb->transaction_active)
+		return LDB_SUCCESS;
+
+	return ldb_transaction_commit_internal(ldb);
+}
+
+int ldb_autotransaction_cancel(struct ldb_context *ldb)
+{
+	/* explicit transaction active, ignore autotransaction request */
+	if (ldb->transaction_active)
+		return LDB_SUCCESS;
+
+	return ldb_transaction_cancel_internal(ldb);
+}
+
+/* autostarts a transacion if none active */
+static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_request *req)
+{
+	int ret;
+
+	ret = ldb_autotransaction_start(ldb);
+	if (ret != LDB_SUCCESS) {
+		return ret;
+	}
+
+	ret = ldb_request(ldb, req);
+	if (ret == LDB_SUCCESS) {
+		ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
+	}
+
+	if (ret == LDB_SUCCESS) {
+		return ldb_autotransaction_commit(ldb);
+	}
+	ldb_autotransaction_cancel(ldb);
+
+	if (ldb->err_string == NULL) {
+		/* no error string was setup by the backend */
+		ldb_set_errstring(ldb, 
+				  talloc_asprintf(ldb, "%s (%d)", 
+						  ldb_strerror(ret), ret));
+	}
+
+	return ret;
+}
+
 int ldb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type)
 {
 	if (!handle) {
@@ -461,43 +530,7 @@
 	return ret;
 }
 
-/* autostarts a transacion if none active */
-static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_request *req)
-{
-	int ret, close_transaction;
 
-	close_transaction = 0;
-	if (!ldb->transaction_active) {
-		ret = ldb_transaction_start(ldb);
-		if (ret != LDB_SUCCESS) {
-			return ret;
-		}
-		close_transaction = 1;
-	}
-
-	ret = ldb_request(ldb, req);
-	if (ret == LDB_SUCCESS) {
-		ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
-	}
-
-	if (close_transaction) {
-		if (ret == LDB_SUCCESS) {
-			return ldb_transaction_commit(ldb);
-		}
-		ldb_transaction_cancel(ldb);
-	}
-
-	if (ldb->err_string == NULL) {
-		/* no error string was setup by the backend */
-		ldb_set_errstring(ldb, 
-				  talloc_asprintf(ldb, "%s (%d)", 
-						  ldb_strerror(ret), ret));
-	}
-
-	return ret;
-}
-
-
 /*
   add a record to the database. Will fail if a record with the given class and key
   already exists



More information about the samba-cvs mailing list