allow nested ctdb transactions in the same manner that they are
authorAndrew Tridgell <tridge@samba.org>
Fri, 8 Aug 2008 06:44:24 +0000 (16:44 +1000)
committerMichael Adam <obnox@samba.org>
Wed, 13 Aug 2008 09:54:11 +0000 (11:54 +0200)
allowed for tdb. This is needed for the registry db backend.
(This used to be commit 4b04ec29c76df837a7909725bbbf4c79d5abdb4d)

source3/lib/dbwrap_ctdb.c

index 541b2789707e5a905d27c8a5e7370d194c12393d..7c1ef8fed86d2aeaf7db3ef4ccaf4c579ab2055e 100644 (file)
@@ -31,6 +31,8 @@ struct db_ctdb_transaction_handle {
        */
        struct ctdb_marshall_buffer *m_all;
        struct ctdb_marshall_buffer *m_write;
+       uint32_t nesting;
+       bool nested_cancel;
 };
 
 struct db_ctdb_ctx {
@@ -279,8 +281,8 @@ static int db_ctdb_transaction_start(struct db_context *db)
        }
 
        if (ctx->transaction) {
-               DEBUG(0,("Nested transactions not supported on db 0x%08x\n", ctx->db_id));
-               return -1;
+               ctx->transaction->nesting++;
+               return 0;
        }
 
        h = talloc_zero(db, struct db_ctdb_transaction_handle);
@@ -616,6 +618,17 @@ static int db_ctdb_transaction_commit(struct db_context *db)
                return -1;
        }
 
+       if (h->nested_cancel) {
+               db->transaction_cancel(db);
+               DEBUG(5,(__location__ " Failed transaction commit after nested cancel\n"));
+               return -1;
+       }
+
+       if (h->nesting != 0) {
+               h->nesting--;
+               return 0;
+       }
+
        DEBUG(5,(__location__ " Commit transaction on db 0x%08x\n", ctx->db_id));
 
        talloc_set_destructor(h, NULL);
@@ -734,6 +747,12 @@ static int db_ctdb_transaction_cancel(struct db_context *db)
                return -1;
        }
 
+       if (h->nesting != 0) {
+               h->nesting--;
+               h->nested_cancel = true;
+               return 0;
+       }
+
        DEBUG(5,(__location__ " Cancel transaction on db 0x%08x\n", ctx->db_id));
 
        ctx->transaction = NULL;