mirror of
https://github.com/samba-team/samba.git
synced 2025-01-26 10:04:02 +03:00
tdb2: unify tdb1_transaction_start etc. into tdb_transaction_start.
Switch on the TDB_VERSION1 flag. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit 6bc8ea012391198bc3898ae2937558b60dd55906)
This commit is contained in:
parent
014ca657e6
commit
5d9dd8d541
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user