tdb2: unify tdb1_transaction_start etc. into tdb_transaction_start.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)
Switch on the TDB_VERSION1 flag.

ccan/tdb2/private.h
ccan/tdb2/tdb1.h
ccan/tdb2/test/run-tdb1-3G-file.c
ccan/tdb2/test/run-tdb1-die-during-transaction.c
ccan/tdb2/test/run-tdb1-nested-transactions.c
ccan/tdb2/test/run-tdb1-open-during-transaction.c
ccan/tdb2/test/run-tdb1-readonly-check.c
ccan/tdb2/test/run-tdb1-traverse-in-transaction.c
ccan/tdb2/test/tdb1-external-agent.c
ccan/tdb2/transaction.c

index 59badc622375d1ace7c45de3e028ae992cae79e4..96f23e92c364bb2cb91a699290d48fcf406ffe2e 100644 (file)
@@ -671,6 +671,11 @@ enum TDB_ERROR tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key,
                                                          void *private_data),
                                 void *private_data);
 
+/* tdb1_transaction.c: */
+int tdb1_transaction_start(struct tdb_context *tdb);
+int tdb1_transaction_prepare_commit(struct tdb_context *tdb);
+int tdb1_transaction_commit(struct tdb_context *tdb);
+
 /* tdb.c: */
 enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
                               enum TDB_ERROR ecode,
index f0536f986d1dd51ff9e5b385ebe1b1869dcec891..b565b1140889231fa5619f1547e4fc6afe1e3f02 100644 (file)
@@ -42,12 +42,6 @@ TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
 
 TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
 
-int tdb1_transaction_start(struct tdb_context *tdb);
-
-int tdb1_transaction_prepare_commit(struct tdb_context *tdb);
-
-int tdb1_transaction_commit(struct tdb_context *tdb);
-
 int tdb1_get_seqnum(struct tdb_context *tdb);
 
 void tdb1_increment_seqnum_nonblock(struct tdb_context *tdb);
index 074901857faf3d25d03d0dfb8fbe6ef1ff436981..f3403dd1b8f7d63e0d81cb780c769f388a884fc5 100644 (file)
@@ -109,14 +109,14 @@ int main(int argc, char *argv[])
        ok1(tdb_traverse(tdb, test_traverse, NULL) == 0);
 
        /* Transactions should work. */
-       ok1(tdb1_transaction_start(tdb) == 0);
+       ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
        ok1(tdb_store(tdb, key, orig_data, TDB_INSERT) == TDB_SUCCESS);
 
        ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
        ok1(data.dsize == strlen("world"));
        ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
        free(data.dptr);
-       ok1(tdb1_transaction_commit(tdb) == 0);
+       ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS);
 
        ok1(tdb_traverse(tdb, test_traverse, &orig_data) == 1);
        tdb_close(tdb);
index f42513953a5adbb79995c9a132340e4676604d4c..f45fcedc7abf746136200291c13bce1ddb232894 100644 (file)
@@ -170,13 +170,13 @@ reset:
                errx(1, "Agent failed find key: %s", agent_return_name1(ret));
 
        in_transaction = true;
-       if (tdb1_transaction_start(tdb) != 0)
+       if (tdb_transaction_start(tdb) != TDB_SUCCESS)
                return false;
 
        if (tdb_store(tdb, key, key, TDB_INSERT) != TDB_SUCCESS)
                return false;
 
-       if (tdb1_transaction_commit(tdb) != 0)
+       if (tdb_transaction_commit(tdb) != TDB_SUCCESS)
                return false;
 
        in_transaction = false;
index 408987b58e827527931ca586849c9dc6ebe1432a..a6a815363cf1d6b86d54c628b00f2ec86f53aa96 100644 (file)
@@ -15,7 +15,7 @@ int main(int argc, char *argv[])
        hsize.base.next = &tap_log_attr;
        hsize.tdb1_hashsize.hsize = 1024;
 
-       plan_tests(30);
+       plan_tests(29);
        key.dsize = strlen("hi");
        key.dptr = (void *)"hi";
 
@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
        ok1(tdb);
 
        /* No nesting by default. */
-       ok1(tdb1_transaction_start(tdb) == 0);
+       ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
        data.dptr = (void *)"world";
        data.dsize = strlen("world");
        ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
@@ -32,14 +32,13 @@ int main(int argc, char *argv[])
        ok1(data.dsize == strlen("world"));
        ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
        free(data.dptr);
-       ok1(tdb1_transaction_start(tdb) != 0);
-       ok1(tdb_error(tdb) == TDB_ERR_EINVAL);
+       ok1(tdb_transaction_start(tdb) == TDB_ERR_EINVAL);
 
        ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
        ok1(data.dsize == strlen("world"));
        ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
        free(data.dptr);
-       ok1(tdb1_transaction_commit(tdb) == 0);
+       ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS);
        ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
        ok1(data.dsize == strlen("world"));
        ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
@@ -50,21 +49,22 @@ int main(int argc, char *argv[])
                       TDB_ALLOW_NESTING, O_RDWR, 0, &tap_log_attr);
        ok1(tdb);
 
-       ok1(tdb1_transaction_start(tdb) == 0);
-       ok1(tdb1_transaction_start(tdb) == 0);
+       ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
+       ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
        ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
-       ok1(tdb1_transaction_commit(tdb) == 0);
+       ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS);
        ok1(!tdb_exists(tdb, key));
-       ok1(tdb1_transaction_cancel(tdb) == 0);
+       tdb_transaction_cancel(tdb);
+       ok1(tap_log_messages == 0);
        /* Surprise! Kills inner "committed" transaction. */
        ok1(tdb_exists(tdb, key));
 
-       ok1(tdb1_transaction_start(tdb) == 0);
-       ok1(tdb1_transaction_start(tdb) == 0);
+       ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
+       ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
        ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
-       ok1(tdb1_transaction_commit(tdb) == 0);
+       ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS);
        ok1(!tdb_exists(tdb, key));
-       ok1(tdb1_transaction_commit(tdb) == 0);
+       ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS);
        ok1(!tdb_exists(tdb, key));
        tdb_close(tdb);
 
index 879d79064716a1f8c442af01fb9c141707996510..d03f7d95a09ee53dd70b10515b468fe0ea3f3ce1 100644 (file)
@@ -156,14 +156,14 @@ int main(int argc, char *argv[])
                ok1(tdb);
 
                opened = true;
-               ok1(tdb1_transaction_start(tdb) == 0);
+               ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
                key.dsize = strlen("hi");
                key.dptr = (void *)"hi";
                data.dptr = (void *)"world";
                data.dsize = strlen("world");
 
                ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
-               ok1(tdb1_transaction_commit(tdb) == 0);
+               ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS);
                ok(!errors, "We had %u open errors", errors);
 
                opened = false;
index 6e1b57323c7f05db1c62f73b2a02289b759f1d3a..471f813da24159052969a64cd88aa68e3606b6c2 100644 (file)
@@ -31,7 +31,7 @@ int main(int argc, char *argv[])
        ok1(tdb1_check(tdb, NULL, NULL) == 0);
 
        /* We are also allowed to do a check inside a transaction. */
-       ok1(tdb1_transaction_start(tdb) == 0);
+       ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
        ok1(tdb1_check(tdb, NULL, NULL) == 0);
        ok1(tdb_close(tdb) == 0);
 
index c4fd89dfe4b79b44996063d5dfb6b7d7ec794fcc..691aaf944472a3839e11688e37cb43e900291c9b 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
 
        ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS);
 
-       ok1(tdb1_transaction_start(tdb) == 0);
+       ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
        ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == WOULD_HAVE_BLOCKED);
        tdb_traverse(tdb, traverse, NULL);
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
        /* That should *not* release the transaction lock! */
        ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == WOULD_HAVE_BLOCKED);
-       ok1(tdb1_transaction_commit(tdb) == 0);
+       ok1(tdb_transaction_commit(tdb) == TDB_SUCCESS);
        /* Now we should be fine. */
        ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == SUCCESS);
index 6f80b1933c15de9e399db94274c07d403df8f248..6b6f87dea5ea64bce3f1e4d83b7dc75365d5a873 100644 (file)
@@ -48,7 +48,7 @@ static enum agent_return do_operation(enum operation op, const char *name)
                        ret = SUCCESS;
                break;
        case TRANSACTION_START:
-               ret = tdb1_transaction_start(tdb) == 0 ? SUCCESS : OTHER_FAILURE;
+               ret = tdb_transaction_start(tdb) == TDB_SUCCESS ? SUCCESS : OTHER_FAILURE;
                break;
        case FETCH:
                if (tdb_fetch(tdb, k, &data) != TDB_SUCCESS) {
@@ -71,7 +71,7 @@ static enum agent_return do_operation(enum operation op, const char *name)
                        ret = OTHER_FAILURE;
                break;
        case TRANSACTION_COMMIT:
-               ret = tdb1_transaction_commit(tdb)==0 ? SUCCESS : OTHER_FAILURE;
+               ret = tdb_transaction_commit(tdb) == TDB_SUCCESS ? SUCCESS : OTHER_FAILURE;
                break;
        case CHECK:
                ret = tdb1_check(tdb, NULL, NULL) == 0 ? SUCCESS : OTHER_FAILURE;
index a5f3c543e8194592f70e368d1f624b8833799a83..eab00e0937778b51ce79d7b48de26daf94c93c78 100644 (file)
@@ -521,6 +521,12 @@ enum TDB_ERROR tdb_transaction_start(struct tdb_context *tdb)
 {
        enum TDB_ERROR ecode;
 
+       if (tdb->flags & TDB_VERSION1) {
+               if (tdb1_transaction_start(tdb) == -1)
+                       return tdb->last_error;
+               return TDB_SUCCESS;
+       }
+
        tdb->stats.transactions++;
        /* some sanity checks */
        if (tdb->flags & TDB_INTERNAL) {
@@ -617,6 +623,10 @@ fail_allrecord_lock:
 */
 void tdb_transaction_cancel(struct tdb_context *tdb)
 {
+       if (tdb->flags & TDB_VERSION1) {
+               tdb1_transaction_cancel(tdb);
+               return;
+       }
        tdb->stats.transaction_cancel++;
        _tdb_transaction_cancel(tdb);
 }
@@ -1052,6 +1062,11 @@ static enum TDB_ERROR _tdb_transaction_prepare_commit(struct tdb_context *tdb)
 */
 enum TDB_ERROR tdb_transaction_prepare_commit(struct tdb_context *tdb)
 {
+       if (tdb->flags & TDB_VERSION1) {
+               if (tdb1_transaction_prepare_commit(tdb) == -1)
+                       return tdb->last_error;
+               return TDB_SUCCESS;
+       }
        return _tdb_transaction_prepare_commit(tdb);
 }
 
@@ -1064,6 +1079,12 @@ enum TDB_ERROR tdb_transaction_commit(struct tdb_context *tdb)
        int i;
        enum TDB_ERROR ecode;
 
+       if (tdb->flags & TDB_VERSION1) {
+               if (tdb1_transaction_commit(tdb) == -1)
+                       return tdb->last_error;
+               return TDB_SUCCESS;
+       }
+
        if (tdb->tdb2.transaction == NULL) {
                return tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
                                                    TDB_LOG_USE_ERROR,