summaryrefslogtreecommitdiff
path: root/lib/tdb/tools
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2009-10-22 00:10:54 +1030
committerRusty Russell <rusty@rustcorp.com.au>2009-10-22 00:10:54 +1030
commit0fc6800005ffb532a5e5699c97f13f1de138d51f (patch)
tree44d457578b7c89dde569bad73da7ff75da439baf /lib/tdb/tools
parentb77f41d58b05101e02d8ac0e54cb0e30807d89c2 (diff)
downloadsamba-0fc6800005ffb532a5e5699c97f13f1de138d51f.tar.gz
samba-0fc6800005ffb532a5e5699c97f13f1de138d51f.tar.bz2
samba-0fc6800005ffb532a5e5699c97f13f1de138d51f.zip
lib/tdb: add -t (always use transactions) option to tdbtorture
This means you can kill it at any time and expect no corruption. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb/tools')
-rw-r--r--lib/tdb/tools/tdbtorture.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/lib/tdb/tools/tdbtorture.c b/lib/tdb/tools/tdbtorture.c
index bd5fb201b7..b0221a2503 100644
--- a/lib/tdb/tools/tdbtorture.c
+++ b/lib/tdb/tools/tdbtorture.c
@@ -29,6 +29,7 @@
static struct tdb_context *db;
static int in_transaction;
static int error_count;
+static int always_transaction = 0;
#ifdef PRINTF_ATTRIBUTE
static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4);
@@ -104,8 +105,16 @@ static void addrec_db(void)
data.dptr = (unsigned char *)d;
data.dsize = dlen+1;
+#if REOPEN_PROB
+ if (in_transaction == 0 && random() % REOPEN_PROB == 0) {
+ tdb_reopen_all(0);
+ goto next;
+ }
+#endif
+
#if TRANSACTION_PROB
- if (in_transaction == 0 && random() % TRANSACTION_PROB == 0) {
+ if (in_transaction == 0 &&
+ (always_transaction || random() % TRANSACTION_PROB == 0)) {
if (tdb_transaction_start(db) != 0) {
fatal("tdb_transaction_start failed");
}
@@ -133,13 +142,6 @@ static void addrec_db(void)
}
#endif
-#if REOPEN_PROB
- if (in_transaction == 0 && random() % REOPEN_PROB == 0) {
- tdb_reopen_all(0);
- goto next;
- }
-#endif
-
#if DELETE_PROB
if (random() % DELETE_PROB == 0) {
tdb_delete(db, key);
@@ -209,7 +211,7 @@ static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf,
static void usage(void)
{
- printf("Usage: tdbtorture [-n NUM_PROCS] [-l NUM_LOOPS] [-s SEED] [-H HASH_SIZE]\n");
+ printf("Usage: tdbtorture [-t] [-n NUM_PROCS] [-l NUM_LOOPS] [-s SEED] [-H HASH_SIZE]\n");
exit(0);
}
@@ -226,7 +228,7 @@ static void usage(void)
struct tdb_logging_context log_ctx;
log_ctx.log_fn = tdb_log;
- while ((c = getopt(argc, argv, "n:l:s:H:h")) != -1) {
+ while ((c = getopt(argc, argv, "n:l:s:H:th")) != -1) {
switch (c) {
case 'n':
num_procs = strtol(optarg, NULL, 0);
@@ -240,6 +242,9 @@ static void usage(void)
case 's':
seed = strtol(optarg, NULL, 0);
break;
+ case 't':
+ always_transaction = 1;
+ break;
default:
usage();
}
@@ -265,8 +270,8 @@ static void usage(void)
}
if (i == 0) {
- printf("testing with %d processes, %d loops, %d hash_size, seed=%d\n",
- num_procs, num_loops, hash_size, seed);
+ printf("testing with %d processes, %d loops, %d hash_size, seed=%d%s\n",
+ num_procs, num_loops, hash_size, seed, always_transaction ? " (all within transactions)" : "");
}
srand(seed + i);
@@ -278,8 +283,20 @@ static void usage(void)
if (error_count == 0) {
tdb_traverse_read(db, NULL, NULL);
+ if (always_transaction) {
+ while (in_transaction) {
+ tdb_transaction_cancel(db);
+ in_transaction--;
+ }
+ if (tdb_transaction_start(db) != 0)
+ fatal("tdb_transaction_start failed");
+ }
tdb_traverse(db, traverse_fn, NULL);
tdb_traverse(db, traverse_fn, NULL);
+ if (always_transaction) {
+ if (tdb_transaction_commit(db) != 0)
+ fatal("tdb_transaction_commit failed");
+ }
}
tdb_close(db);