add TDB_NO_NESTING. When this flag is set tdb will not allow any nested transactions...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Sat, 25 Apr 2009 22:38:37 +0000 (08:38 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Sat, 25 Apr 2009 22:38:37 +0000 (08:38 +1000)
lib/tdb/common/transaction.c
lib/tdb/include/tdb.h

index 4e2127be64484cbcb5faee1a6e5682c08425f26a..6a34c4526993d73d25a13778474739a3afa0b971 100644 (file)
     still available, but no transaction recovery area is used and no
     fsync/msync calls are made.
 
+  - if TDB_NO_NESTING is passed to flags in tdb open then transaction
+    nesting is disabled. tdb_transaction_start() will then implicitely
+    cancel any pending transactions and always start a new transaction
+    context instead of nesting.
+
 */
 
 
@@ -409,10 +414,15 @@ int tdb_transaction_start(struct tdb_context *tdb)
 
        /* cope with nested tdb_transaction_start() calls */
        if (tdb->transaction != NULL) {
-               tdb->transaction->nesting++;
-               TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_start: nesting %d\n", 
-                        tdb->transaction->nesting));
-               return 0;
+               if (!tdb->flags & TDB_NO_NESTING) {
+                       tdb->transaction->nesting++;
+                       TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_start: nesting %d\n", 
+                                tdb->transaction->nesting));
+                       return 0;
+               } else {
+                       tdb_transaction_cancel(tdb);
+                       TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_start: cancelling previous transaction\n"));
+               }
        }
 
        if (tdb->num_locks != 0 || tdb->global_lock.count) {
index 0008085de540b525bb02fc1ff178d06bc898a02d..628118172e807ed10762f631bae0b8168fe37f38 100644 (file)
@@ -47,6 +47,7 @@ extern "C" {
 #define TDB_NOSYNC   64 /* don't use synchronous transactions */
 #define TDB_SEQNUM   128 /* maintain a sequence number */
 #define TDB_VOLATILE   256 /* Activate the per-hashchain freelist, default 5 */
+#define TDB_NO_NESTING 512 /* Dont allow transaction nesting */
 
 #define TDB_ERRCODE(code, ret) ((tdb->ecode = (code)), ret)