summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/tdb2/private.h5
-rw-r--r--lib/tdb2/tdb1.h6
-rw-r--r--lib/tdb2/test/run-tdb1-3G-file.c4
-rw-r--r--lib/tdb2/test/run-tdb1-die-during-transaction.c4
-rw-r--r--lib/tdb2/test/run-tdb1-nested-transactions.c26
-rw-r--r--lib/tdb2/test/run-tdb1-open-during-transaction.c4
-rw-r--r--lib/tdb2/test/run-tdb1-readonly-check.c2
-rw-r--r--lib/tdb2/test/run-tdb1-traverse-in-transaction.c4
-rw-r--r--lib/tdb2/test/tdb1-external-agent.c4
-rw-r--r--lib/tdb2/transaction.c21
10 files changed, 50 insertions, 30 deletions
diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h
index 2bb144646a..67bc97dad1 100644
--- a/lib/tdb2/private.h
+++ b/lib/tdb2/private.h
@@ -683,6 +683,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,
diff --git a/lib/tdb2/tdb1.h b/lib/tdb2/tdb1.h
index f0536f986d..b565b11408 100644
--- a/lib/tdb2/tdb1.h
+++ b/lib/tdb2/tdb1.h
@@ -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);
diff --git a/lib/tdb2/test/run-tdb1-3G-file.c b/lib/tdb2/test/run-tdb1-3G-file.c
index 074901857f..f3403dd1b8 100644
--- a/lib/tdb2/test/run-tdb1-3G-file.c
+++ b/lib/tdb2/test/run-tdb1-3G-file.c
@@ -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);
diff --git a/lib/tdb2/test/run-tdb1-die-during-transaction.c b/lib/tdb2/test/run-tdb1-die-during-transaction.c
index f42513953a..f45fcedc7a 100644
--- a/lib/tdb2/test/run-tdb1-die-during-transaction.c
+++ b/lib/tdb2/test/run-tdb1-die-during-transaction.c
@@ -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;
diff --git a/lib/tdb2/test/run-tdb1-nested-transactions.c b/lib/tdb2/test/run-tdb1-nested-transactions.c
index 408987b58e..a6a815363c 100644
--- a/lib/tdb2/test/run-tdb1-nested-transactions.c
+++ b/lib/tdb2/test/run-tdb1-nested-transactions.c
@@ -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);
diff --git a/lib/tdb2/test/run-tdb1-open-during-transaction.c b/lib/tdb2/test/run-tdb1-open-during-transaction.c
index 879d790647..d03f7d95a0 100644
--- a/lib/tdb2/test/run-tdb1-open-during-transaction.c
+++ b/lib/tdb2/test/run-tdb1-open-during-transaction.c
@@ -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;
diff --git a/lib/tdb2/test/run-tdb1-readonly-check.c b/lib/tdb2/test/run-tdb1-readonly-check.c
index 6e1b57323c..471f813da2 100644
--- a/lib/tdb2/test/run-tdb1-readonly-check.c
+++ b/lib/tdb2/test/run-tdb1-readonly-check.c
@@ -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);
diff --git a/lib/tdb2/test/run-tdb1-traverse-in-transaction.c b/lib/tdb2/test/run-tdb1-traverse-in-transaction.c
index c4fd89dfe4..691aaf9444 100644
--- a/lib/tdb2/test/run-tdb1-traverse-in-transaction.c
+++ b/lib/tdb2/test/run-tdb1-traverse-in-transaction.c
@@ -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);
diff --git a/lib/tdb2/test/tdb1-external-agent.c b/lib/tdb2/test/tdb1-external-agent.c
index 6f80b1933c..6b6f87dea5 100644
--- a/lib/tdb2/test/tdb1-external-agent.c
+++ b/lib/tdb2/test/tdb1-external-agent.c
@@ -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;
diff --git a/lib/tdb2/transaction.c b/lib/tdb2/transaction.c
index a5f3c543e8..eab00e0937 100644
--- a/lib/tdb2/transaction.c
+++ b/lib/tdb2/transaction.c
@@ -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,