Commit 1dc5b58d authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

add Makefile rules for running recoveyr tests [t:1864]

git-svn-id: file:///svn/toku/tokudb@14460 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9c46cc4e
......@@ -29,7 +29,7 @@ $(notdir $(TLIBTDB)): $(TLIBTDB)
cp $< $@
SRCS = $(sort $(wildcard *.c))
RECOVERY_SRCS = $(wildcard recover-*.c)
#Tests that are irrelevant in windows.
WINDOWS_DONTRUN_TESTS = \
......@@ -57,7 +57,7 @@ WINDOWS_BDB_DONTRUN_TESTS += \
ifeq ($(OS_CHOICE),windows)
TDB_TESTS = $(patsubst %.c,%.tdb$(BINSUF),$(filter-out $(patsubst %,%.c,$(WINDOWS_DONTRUN_TESTS)),$(SRCS)))
else
TDB_TESTS = $(patsubst %.c,%.tdb$(BINSUF),$(SRCS))
TDB_TESTS = $(patsubst %.c,%.tdb$(BINSUF),$(filter-out $(RECOVERY_SRCS),$(SRCS)))
endif
# For diskfull.bdb: db-4.6 seems OK, but db-4.3 segfaults
......@@ -190,7 +190,10 @@ EXTRA_TDB_TESTS = \
# test_db_assoc3.tdbrun_wasbad \# Obsolete right now.
#\ ends prev line
RUN_TDB_TESTS = $(patsubst %.tdb$(BINSUF),%.tdbrun,$(TDB_TESTS)) $(EXTRA_TDB_TESTS)
RECOVER_TDBS = $(patsubst %.c,%.tdb$(BINSUF),$(RECOVERY_SRCS))
RECOVERY_TESTS = $(patsubst %.c,%.abortrecover,$(RECOVERY_SRCS))
RUN_TDB_TESTS = $(patsubst %.tdb$(BINSUF),%.tdbrun,$(TDB_TESTS)) $(EXTRA_TDB_TESTS) $(RECOVERY_TESTS)
RUN_BDB_TESTS = $(patsubst %.bdb$(BINSUF),%.bdbrun,$(BDB_TESTS))
RUN_ALL_TESTS = $(RUN_BDB_TESTS) $(RUN_TDB_TESTS)
......@@ -213,6 +216,10 @@ check.bdb: $(RUN_BDB_TESTS) ;
tests.tdb: $(TDB_TESTS) ;
check.tdb: $(notdir $(LIBTDB)) $(PTHREAD_LOCAL) $(RUN_TDB_TESTS) ;
tests.abortrecover: $(RECOVERY_TDBS) ;
check.abortrecover: $(RECOVERY_TESTS) ;
foo:
echo RUN_TDB_TESTS: $(RUN_TDB_TESTS)
echo ALL_TESTS: $(ALL_TESTS)
......@@ -294,6 +301,31 @@ endif
%.recoverwc: %.tdb$(BINSUF) $(PTHREAD_LOCAL)
(cd dir.$*.c.tdb;pwd;cat log*| ../../../newbrt/tdb_logprint |wc -c)
%.abortrecover: %.tdb$(BINSUF) $(PTHREAD_LOCAL)
ifeq ($(VGRIND),)
./$< --test >$<.check.output 2>&1; \
if [ $$? -ne 134 ] ; then \
test 0 = 1; \
else \
./$< --recover >>$<.check.output 2>&1; \
fi \
$(MAYBEINVERTER) $(SUMMARIZE_CMD)
else
./$< --test >$<.check.output 2>&1; \
if [ $$? -ne 134 ] ; then \
test 0 = 1; \
else \
valgrind --quiet --error-exitcode=1 --leak-check=full --log-file=$<.check.valgrind ./$< --recover >>$<.check.output 2>&1; \
if [ $$? -ne 0 ] ; then \
test 0 = 1; \
else \
lines=`cat $<.check.valgrind | wc -l`; \
if [ $$lines -ne 0 ] ; then test 0 = 1; fi; \
fi \
fi \
$(MAYBEINVERTER) $(SUMMARIZE_CMD)
endif
.PHONY: %.recover
all.recover: $(patsubst %,test_log%.recover,$(TLRECOVER)) $(PTHREAD_LOCAL) ;
......@@ -330,7 +362,7 @@ endif
clean:
rm -f $(ALL_TESTS)
rm -rf dir.*.tdb dir.*.bdb dir.*.tdb.recover
rm -rf dir.*.tdb dir.*.bdb dir.*.tdb.recover *.tdb$(BINSUF) *.check.output *.check.valgrind
rm -f dump.bdb.1426 dump.tdb.1426 test1426.bdb
ifeq ($(VGRIND),)
......
......@@ -144,13 +144,13 @@ static void test_parse_args (int argc, char *argv[]) {
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "--commit")==0) {
do_commit=TRUE;
} else if (strcmp(argv[0], "--abort")==0) {
} else if (strcmp(argv[0], "--abort")==0 || strcmp(argv[0], "--test") == 0) {
do_abort=TRUE;
} else if (strcmp(argv[0], "--explicit-abort")==0) {
do_explicit_abort=TRUE;
} else if (strcmp(argv[0], "--recover-committed")==0) {
do_recover_committed=TRUE;
} else if (strcmp(argv[0], "--recover-aborted")==0) {
} else if (strcmp(argv[0], "--recover-aborted")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_aborted=TRUE;
} else if (strcmp(argv[0], "--recover-only") == 0) {
do_recover_only=TRUE;
......
// this test verifies that db creation after a checkpoint works for nodup and dupsort dictionaries
#include <sys/stat.h>
#include "test.h"
const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN;
char *namea="a.db";
char *nameb="b.db";
static void run_test (BOOL do_commit, BOOL do_abort) {
int r;
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
DB_ENV *env;
DB *dba, *dbb;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
{
DBT a={.data="a", .size=2};
DBT b={.data="b", .size=2};
r = dba->put(dba, txn, &a, &b, DB_YESOVERWRITE); CKERR(r);
r = dbb->put(dbb, txn, &b, &a, DB_YESOVERWRITE); CKERR(r);
}
//printf("opened\n");
if (do_commit) {
r = txn->commit(txn, 0); CKERR(r);
} else if (do_abort) {
r = txn->abort(txn); CKERR(r);
// force an fsync of the log
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
}
//printf("shutdown\n");
abort();
}
static void run_recover (BOOL did_commit) {
DB_ENV *env;
DB *dba, *dbb;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
u_int32_t dbflags;
dbflags = 0;
r = dba->get_flags(dba, &dbflags); CKERR(r);
assert(dbflags == 0);
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
dbflags = 0;
r = dbb->get_flags(dbb, &dbflags); CKERR(r);
assert(dbflags == 0);
DBT aa={.size=0}, ab={.size=0};
DBT ba={.size=0}, bb={.size=0};
DB_TXN *txn;
DBC *ca,*cb;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = dba->cursor(dba, txn, &ca, 0); CKERR(r);
r = dbb->cursor(dbb, txn, &cb, 0); CKERR(r);
int ra = ca->c_get(ca, &aa, &ab, DB_FIRST); CKERR(r);
int rb = cb->c_get(cb, &ba, &bb, DB_FIRST); CKERR(r);
if (did_commit) {
assert(ra==0);
assert(rb==0);
// verify key-value pairs
assert(aa.size==2);
assert(ab.size==2);
assert(ba.size==2);
assert(bb.size==2);
const char a[2] = "a";
const char b[2] = "b";
assert(memcmp(aa.data, &a, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(bb.data, &a, 2)==0);
// make sure no other entries in DB
assert(ca->c_get(ca, &aa, &ab, DB_NEXT) == DB_NOTFOUND);
assert(cb->c_get(cb, &ba, &bb, DB_NEXT) == DB_NOTFOUND);
fprintf(stderr, "Both verified. Yay!\n");
} else {
// It wasn't committed (it also wasn't aborted), but a checkpoint happened.
assert(ra==DB_NOTFOUND);
assert(rb==DB_NOTFOUND);
fprintf(stderr, "Neither present. Yay!\n");
}
r = ca->c_close(ca); CKERR(r);
r = cb->c_close(cb); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
r = dba->close(dba, 0); CKERR(r);
r = dbb->close(dbb, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
static void run_recover_only (void) {
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
static void run_no_recover (void) {
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags & ~DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == DB_RUNRECOVERY);
r = env->close(env, 0); CKERR(r);
}
const char *cmd;
BOOL do_commit=FALSE, do_abort=FALSE, do_explicit_abort=FALSE, do_recover_committed=FALSE, do_recover_aborted=FALSE, do_recover_only=FALSE, do_no_recover = FALSE;
static void test_parse_args (int argc, char *argv[]) {
int resultcode;
cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-v") == 0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "--commit")==0 || strcmp(argv[0], "--test") == 0) {
do_commit=TRUE;
} else if (strcmp(argv[0], "--abort")==0) {
do_abort=TRUE;
} else if (strcmp(argv[0], "--explicit-abort")==0) {
do_explicit_abort=TRUE;
} else if (strcmp(argv[0], "--recover-committed")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_committed=TRUE;
} else if (strcmp(argv[0], "--recover-aborted")==0) {
do_recover_aborted=TRUE;
} else if (strcmp(argv[0], "--recover-only") == 0) {
do_recover_only=TRUE;
} else if (strcmp(argv[0], "--no-recover") == 0) {
do_no_recover=TRUE;
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--commit | --abort | --explicit-abort | --recover-committed | --recover-aborted } \n", cmd);
exit(resultcode);
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
{
int n_specified=0;
if (do_commit) n_specified++;
if (do_abort) n_specified++;
if (do_explicit_abort) n_specified++;
if (do_recover_committed) n_specified++;
if (do_recover_aborted) n_specified++;
if (do_recover_only) n_specified++;
if (do_no_recover) n_specified++;
if (n_specified>1) {
printf("Specify only one of --commit or --abort or --recover-committed or --recover-aborted\n");
resultcode=1;
goto do_usage;
}
}
}
int test_main (int argc, char *argv[]) {
test_parse_args(argc, argv);
if (do_commit) {
run_test(TRUE, FALSE);
} else if (do_abort) {
run_test(FALSE, TRUE);
} else if (do_recover_committed) {
run_recover(TRUE);
} else if (do_recover_aborted) {
run_recover(FALSE);
} else if (do_recover_only) {
run_recover_only();
} else if (do_no_recover) {
run_no_recover();
}
return 0;
}
......@@ -146,13 +146,13 @@ static void test_parse_args (int argc, char *argv[]) {
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "--commit")==0) {
do_commit=TRUE;
} else if (strcmp(argv[0], "--abort")==0) {
} else if (strcmp(argv[0], "--abort")==0 || strcmp(argv[0], "--test") == 0) {
do_abort=TRUE;
} else if (strcmp(argv[0], "--explicit-abort")==0) {
do_explicit_abort=TRUE;
} else if (strcmp(argv[0], "--recover-committed")==0) {
do_recover_committed=TRUE;
} else if (strcmp(argv[0], "--recover-aborted")==0) {
} else if (strcmp(argv[0], "--recover-aborted")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_aborted=TRUE;
} else if (strcmp(argv[0], "--recover-only") == 0) {
do_recover_only=TRUE;
......
// this test verifies that db creation after a checkpoint works for nodup and dupsort dictionaries
#include <sys/stat.h>
#include "test.h"
const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN;
char *namea="a.db";
char *nameb="b.db";
static void run_test (BOOL do_commit, BOOL do_abort) {
int r;
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
DB_ENV *env;
DB *dba, *dbb;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
// r = dba->set_flags(dba, DB_DUPSORT); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->set_flags(dbb, DB_DUPSORT); CKERR(r);
r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
{
DBT a={.data="a", .size=2};
DBT b={.data="b", .size=2};
r = dba->put(dba, txn, &a, &b, DB_YESOVERWRITE); CKERR(r);
r = dbb->put(dbb, txn, &b, &a, DB_YESOVERWRITE); CKERR(r);
}
//printf("opened\n");
if (do_commit) {
r = txn->commit(txn, 0); CKERR(r);
} else if (do_abort) {
r = txn->abort(txn); CKERR(r);
// force an fsync of the log
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
}
//printf("shutdown\n");
abort();
}
static void run_recover (BOOL did_commit) {
DB_ENV *env;
DB *dba, *dbb;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
u_int32_t dbflags;
dbflags = 0;
r = dba->get_flags(dba, &dbflags); CKERR(r);
assert(dbflags == 0);
r = db_create(&dbb, env, 0); CKERR(r);
r = dba->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
dbflags = 0;
r = dbb->get_flags(dbb, &dbflags); CKERR(r);
assert(dbflags == DB_DUPSORT);
DBT aa={.size=0}, ab={.size=0};
DBT ba={.size=0}, bb={.size=0};
DB_TXN *txn;
DBC *ca,*cb;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = dba->cursor(dba, txn, &ca, 0); CKERR(r);
r = dbb->cursor(dbb, txn, &cb, 0); CKERR(r);
int ra = ca->c_get(ca, &aa, &ab, DB_FIRST); CKERR(r);
int rb = cb->c_get(cb, &ba, &bb, DB_FIRST); CKERR(r);
if (did_commit) {
assert(ra==0);
assert(rb==0);
// verify key-value pairs
assert(aa.size==2);
assert(ab.size==2);
assert(ba.size==2);
assert(bb.size==2);
const char a[2] = "a";
const char b[2] = "b";
assert(memcmp(aa.data, &a, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(bb.data, &a, 2)==0);
// make sure no other entries in DB
assert(ca->c_get(ca, &aa, &ab, DB_NEXT) == DB_NOTFOUND);
assert(cb->c_get(cb, &ba, &bb, DB_NEXT) == DB_NOTFOUND);
fprintf(stderr, "Both verified. Yay!\n");
} else {
// It wasn't committed (it also wasn't aborted), but a checkpoint happened.
assert(ra==DB_NOTFOUND);
assert(rb==DB_NOTFOUND);
fprintf(stderr, "Neither present. Yay!\n");
}
r = ca->c_close(ca); CKERR(r);
r = cb->c_close(cb); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
r = dba->close(dba, 0); CKERR(r);
r = dbb->close(dbb, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
static void run_recover_only (void) {
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
static void run_no_recover (void) {
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags & ~DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == DB_RUNRECOVERY);
r = env->close(env, 0); CKERR(r);
}
const char *cmd;
BOOL do_commit=FALSE, do_abort=FALSE, do_explicit_abort=FALSE, do_recover_committed=FALSE, do_recover_aborted=FALSE, do_recover_only=FALSE, do_no_recover = FALSE;
static void test_parse_args (int argc, char *argv[]) {
int resultcode;
cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-v") == 0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "--commit")==0 || strcmp(argv[0], "--test") == 0) {
do_commit=TRUE;
} else if (strcmp(argv[0], "--abort")==0) {
do_abort=TRUE;
} else if (strcmp(argv[0], "--explicit-abort")==0) {
do_explicit_abort=TRUE;
} else if (strcmp(argv[0], "--recover-committed")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_committed=TRUE;
} else if (strcmp(argv[0], "--recover-aborted")==0) {
do_recover_aborted=TRUE;
} else if (strcmp(argv[0], "--recover-only") == 0) {
do_recover_only=TRUE;
} else if (strcmp(argv[0], "--no-recover") == 0) {
do_no_recover=TRUE;
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--commit | --abort | --explicit-abort | --recover-committed | --recover-aborted } \n", cmd);
exit(resultcode);
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
{
int n_specified=0;
if (do_commit) n_specified++;
if (do_abort) n_specified++;
if (do_explicit_abort) n_specified++;
if (do_recover_committed) n_specified++;
if (do_recover_aborted) n_specified++;
if (do_recover_only) n_specified++;
if (do_no_recover) n_specified++;
if (n_specified>1) {
printf("Specify only one of --commit or --abort or --recover-committed or --recover-aborted\n");
resultcode=1;
goto do_usage;
}
}
}
int test_main (int argc, char *argv[]) {
test_parse_args(argc, argv);
if (do_commit) {
run_test(TRUE, FALSE);
} else if (do_abort) {
run_test(FALSE, TRUE);
} else if (do_recover_committed) {
run_recover(TRUE);
} else if (do_recover_aborted) {
run_recover(FALSE);
} else if (do_recover_only) {
run_recover_only();
} else if (do_no_recover) {
run_no_recover();
}
return 0;
}
......@@ -189,13 +189,13 @@ x1_parse_args (int argc, char *argv[]) {
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "--commit")==0) {
do_commit=TRUE;
} else if (strcmp(argv[0], "--abort")==0) {
} else if (strcmp(argv[0], "--abort")==0 || strcmp(argv[0], "--test") == 0) {
do_abort=TRUE;
} else if (strcmp(argv[0], "--explicit-abort")==0) {
do_explicit_abort=TRUE;
} else if (strcmp(argv[0], "--recover-committed")==0) {
do_recover_committed=TRUE;
} else if (strcmp(argv[0], "--recover-aborted")==0) {
} else if (strcmp(argv[0], "--recover-aborted")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_aborted=TRUE;
} else if (strcmp(argv[0], "--recover-only") == 0) {
do_recover_only=TRUE;
......
/* Transaction consistency:
* fork a process:
* Open two tables, T1 and T2
* begin transaction
* store A in T1
* checkpoint
* store B in T2
* commit (or abort)
* signal to end the process abruptly
* wait for the process to finish
* open the environment doing recovery
* check to see if both A and B are present (or absent)
*/
#include <sys/stat.h>
#include <sys/wait.h>
#include "test.h"
const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN;
char *namea="a.db";
char *nameb="b.db";
static void
do_x1_shutdown (BOOL do_commit, BOOL do_abort) {
int r;
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
DB_ENV *env;
DB *dba, *dbb;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
{
DBT a={.data="a", .size=2};
DBT b={.data="b", .size=2};
r = dba->put(dba, txn, &a, &b, 0); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
r = dbb->put(dbb, txn, &b, &a, 0); CKERR(r);
}
//printf("opened\n");
if (do_commit) {
r = txn->commit(txn, 0); CKERR(r);
} else if (do_abort) {
r = txn->abort(txn); CKERR(r);
// force an fsync of the log
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
}
//printf("shutdown\n");
abort();
}
static void
do_x1_recover (BOOL did_commit) {
DB_ENV *env;
DB *dba, *dbb;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dba->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DBT aa={.size=0}, ab={.size=0};
DBT ba={.size=0}, bb={.size=0};
DB_TXN *txn;
DBC *ca,*cb;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = dba->cursor(dba, txn, &ca, 0); CKERR(r);
r = dbb->cursor(dbb, txn, &cb, 0); CKERR(r);
int ra = ca->c_get(ca, &aa, &ab, DB_FIRST); CKERR(r);
int rb = cb->c_get(cb, &ba, &bb, DB_FIRST); CKERR(r);
if (did_commit) {
assert(ra==0);
assert(rb==0);
// verify key-value pairs
assert(aa.size==2);
assert(ab.size==2);
assert(ba.size==2);
assert(bb.size==2);
const char a[2] = "a";
const char b[2] = "b";
assert(memcmp(aa.data, &a, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(bb.data, &a, 2)==0);
// make sure no other entries in DB
assert(ca->c_get(ca, &aa, &ab, DB_NEXT) == DB_NOTFOUND);
assert(cb->c_get(cb, &ba, &bb, DB_NEXT) == DB_NOTFOUND);
fprintf(stderr, "Both verified. Yay!\n");
} else {
// It wasn't committed (it also wasn't aborted), but a checkpoint happened.
assert(ra==DB_NOTFOUND);
assert(rb==DB_NOTFOUND);
fprintf(stderr, "Neither present. Yay!\n");
}
r = ca->c_close(ca); CKERR(r);
r = cb->c_close(cb); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
r = dba->close(dba, 0); CKERR(r);
r = dbb->close(dbb, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
exit(0);
}
static void
do_x1_recover_only (void) {
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r);
exit(0);
}
static void
do_x1_no_recover (void) {
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags & ~DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == DB_RUNRECOVERY);
r = env->close(env, 0); CKERR(r);
exit(0);
}
const char *cmd;
static void
do_test_internal (BOOL commit)
{
pid_t pid;
if (0 == (pid=fork())) {
int r=execl(cmd, verbose ? "-v" : "-q", commit ? "--commit" : "--abort", NULL);
assert(r==-1);
printf("execl failed: %d (%s)\n", errno, strerror(errno));
assert(0);
}
{
int r;
int status;
r = waitpid(pid, &status, 0);
//printf("signaled=%d sig=%d\n", WIFSIGNALED(status), WTERMSIG(status));
assert(WIFSIGNALED(status) && WTERMSIG(status)==SIGABRT);
}
// Now find out what happend
if (0 == (pid = fork())) {
int r=execl(cmd, verbose ? "-v" : "-q", commit ? "--recover-committed" : "--recover-aborted", NULL);
assert(r==-1);
printf("execl failed: %d (%s)\n", errno, strerror(errno));
assert(0);
}
{
int r;
int status;
r = waitpid(pid, &status, 0);
//printf("recovery exited=%d\n", WIFEXITED(status));
assert(WIFEXITED(status) && WEXITSTATUS(status)==0);
}
}
static void
do_test (void) {
do_test_internal(TRUE);
do_test_internal(FALSE);
}
BOOL do_commit=FALSE, do_abort=FALSE, do_explicit_abort=FALSE, do_recover_committed=FALSE, do_recover_aborted=FALSE, do_recover_only=FALSE, do_no_recover = FALSE;
static void
x1_parse_args (int argc, char *argv[]) {
int resultcode;
cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-v") == 0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "--commit")==0 || strcmp(argv[0], "--test") == 0) {
do_commit=TRUE;
} else if (strcmp(argv[0], "--abort")==0) {
do_abort=TRUE;
} else if (strcmp(argv[0], "--explicit-abort")==0) {
do_explicit_abort=TRUE;
} else if (strcmp(argv[0], "--recover-committed")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_committed=TRUE;
} else if (strcmp(argv[0], "--recover-aborted")==0) {
do_recover_aborted=TRUE;
} else if (strcmp(argv[0], "--recover-only") == 0) {
do_recover_only=TRUE;
} else if (strcmp(argv[0], "--no-recover") == 0) {
do_no_recover=TRUE;
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--commit | --abort | --explicit-abort | --recover-committed | --recover-aborted } \n", cmd);
exit(resultcode);
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
{
int n_specified=0;
if (do_commit) n_specified++;
if (do_abort) n_specified++;
if (do_explicit_abort) n_specified++;
if (do_recover_committed) n_specified++;
if (do_recover_aborted) n_specified++;
if (do_recover_only) n_specified++;
if (do_no_recover) n_specified++;
if (n_specified>1) {
printf("Specify only one of --commit or --abort or --recover-committed or --recover-aborted\n");
resultcode=1;
goto do_usage;
}
}
}
int
test_main (int argc, char *argv[])
{
x1_parse_args(argc, argv);
if (do_commit) {
do_x1_shutdown (TRUE, FALSE);
} else if (do_abort) {
do_x1_shutdown (FALSE, FALSE);
} else if (do_explicit_abort) {
do_x1_shutdown(FALSE, TRUE);
} else if (do_recover_committed) {
do_x1_recover(TRUE);
} else if (do_recover_aborted) {
do_x1_recover(FALSE);
} else if (do_recover_only) {
do_x1_recover_only();
} else if (do_no_recover) {
do_x1_no_recover();
} else {
do_test();
}
return 0;
}
......@@ -179,13 +179,13 @@ x1_parse_args (int argc, char *argv[]) {
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "--commit")==0) {
do_commit=1;
} else if (strcmp(argv[0], "--abort")==0) {
} else if (strcmp(argv[0], "--abort")==0 || strcmp(argv[0], "--test") == 0) {
do_abort=1;
} else if (strcmp(argv[0], "--explicit-abort")==0) {
do_explicit_abort=1;
} else if (strcmp(argv[0], "--recover-committed")==0) {
do_recover_committed=1;
} else if (strcmp(argv[0], "--recover-aborted")==0) {
} else if (strcmp(argv[0], "--recover-aborted")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_aborted=1;
} else if (strcmp(argv[0], "--recover-only") == 0) {
do_recover_only=1;
......
/* Transaction consistency:
* fork a process:
* Open two tables, T1 and T2
* begin transaction
* store A in T1
* checkpoint
* store B in T2
* commit (or abort)
* signal to end the process abruptly
* wait for the process to finish
* open the environment doing recovery
* check to see if both A and B are present (or absent)
*/
#include <sys/stat.h>
#include <sys/wait.h>
#include "test.h"
const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN;
char *namea="a.db";
char *nameb="b.db";
static void
do_x1_shutdown (BOOL do_commit, BOOL do_abort) {
int r;
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
DB_ENV *env;
DB *dba, *dbb;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DB_TXN *txn0;
r = env->txn_begin(env, NULL, &txn0, 0); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, txn0, &txn, 0); CKERR(r);
{
DBT a={.data="a", .size=2};
DBT b={.data="b", .size=2};
r = dba->put(dba, txn, &a, &b, 0); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
r = dbb->put(dbb, txn, &b, &a, 0); CKERR(r);
}
//printf("opened\n");
r = txn->commit(txn, 0); CKERR(r);
if (do_commit) {
r = txn->commit(txn0, 0); CKERR(r);
} else if (do_abort) {
r = txn->abort(txn0); CKERR(r);
// force an fsync of the log
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
}
//printf("shutdown\n");
abort();
}
static void
do_x1_recover (BOOL did_commit) {
DB_ENV *env;
DB *dba, *dbb;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dba->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DBT aa={.size=0}, ab={.size=0};
DBT ba={.size=0}, bb={.size=0};
DB_TXN *txn;
DBC *ca,*cb;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = dba->cursor(dba, txn, &ca, 0); CKERR(r);
r = dbb->cursor(dbb, txn, &cb, 0); CKERR(r);
int ra = ca->c_get(ca, &aa, &ab, DB_FIRST); CKERR(r);
int rb = cb->c_get(cb, &ba, &bb, DB_FIRST); CKERR(r);
if (did_commit) {
assert(ra==0);
assert(rb==0);
// verify key-value pairs
assert(aa.size==2);
assert(ab.size==2);
assert(ba.size==2);
assert(bb.size==2);
const char a[2] = "a";
const char b[2] = "b";
assert(memcmp(aa.data, &a, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(bb.data, &a, 2)==0);
// make sure no other entries in DB
assert(ca->c_get(ca, &aa, &ab, DB_NEXT) == DB_NOTFOUND);
assert(cb->c_get(cb, &ba, &bb, DB_NEXT) == DB_NOTFOUND);
fprintf(stderr, "Both verified. Yay!\n");
} else {
// It wasn't committed (it also wasn't aborted), but a checkpoint happened.
assert(ra==DB_NOTFOUND);
assert(rb==DB_NOTFOUND);
fprintf(stderr, "Neither present. Yay!\n");
}
r = ca->c_close(ca); CKERR(r);
r = cb->c_close(cb); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
r = dba->close(dba, 0); CKERR(r);
r = dbb->close(dbb, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
exit(0);
}
static void
do_x1_recover_only (void) {
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r);
exit(0);
}
const char *cmd;
static void
do_test_internal (BOOL commit) {
pid_t pid;
if (0 == (pid=fork())) {
int r=execl(cmd, verbose ? "-v" : "-q", commit ? "--commit" : "--abort", NULL);
assert(r==-1);
printf("execl failed: %d (%s)\n", errno, strerror(errno));
assert(0);
}
{
int r;
int status;
r = waitpid(pid, &status, 0);
//printf("signaled=%d sig=%d\n", WIFSIGNALED(status), WTERMSIG(status));
assert(WIFSIGNALED(status) && WTERMSIG(status)==SIGABRT);
}
// Now find out what happend
if (0 == (pid = fork())) {
int r=execl(cmd, verbose ? "-v" : "-q", commit ? "--recover-committed" : "--recover-aborted", NULL);
assert(r==-1);
printf("execl failed: %d (%s)\n", errno, strerror(errno));
assert(0);
}
{
int r;
int status;
r = waitpid(pid, &status, 0);
//printf("recovery exited=%d\n", WIFEXITED(status));
assert(WIFEXITED(status) && WEXITSTATUS(status)==0);
}
}
static void
do_test (void) {
do_test_internal(TRUE);
do_test_internal(FALSE);
}
BOOL do_commit=FALSE, do_abort=FALSE, do_explicit_abort=FALSE, do_recover_committed=FALSE, do_recover_aborted=FALSE, do_recover_only=FALSE;
static void
x1_parse_args (int argc, char *argv[]) {
int resultcode;
cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-v") == 0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "--commit")==0 || strcmp(argv[0], "--test") == 0) {
do_commit=1;
} else if (strcmp(argv[0], "--abort")==0) {
do_abort=1;
} else if (strcmp(argv[0], "--explicit-abort")==0) {
do_explicit_abort=1;
} else if (strcmp(argv[0], "--recover-committed")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_committed=1;
} else if (strcmp(argv[0], "--recover-aborted")==0) {
do_recover_aborted=1;
} else if (strcmp(argv[0], "--recover-only") == 0) {
do_recover_only=1;
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--commit | --abort | --explicit-abort | --recover-committed | --recover-aborted } \n", cmd);
exit(resultcode);
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
{
int n_specified=0;
if (do_commit) n_specified++;
if (do_abort) n_specified++;
if (do_explicit_abort) n_specified++;
if (do_recover_committed) n_specified++;
if (do_recover_aborted) n_specified++;
if (do_recover_only) n_specified++;
if (n_specified>1) {
printf("Specify only one of --commit or --abort or --recover-committed or --recover-aborted\n");
resultcode=1;
goto do_usage;
}
}
}
int
test_main (int argc, char *argv[]) {
x1_parse_args(argc, argv);
if (do_commit) {
do_x1_shutdown (TRUE, FALSE);
} else if (do_abort) {
do_x1_shutdown (FALSE, FALSE);
} else if (do_explicit_abort) {
do_x1_shutdown(FALSE, TRUE);
} else if (do_recover_committed) {
do_x1_recover(TRUE);
} else if (do_recover_aborted) {
do_x1_recover(FALSE);
} else if (do_recover_only) {
do_x1_recover_only();
} else {
do_test();
}
return 0;
}
......@@ -166,13 +166,13 @@ x2_parse_args (int argc, char *argv[]) {
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0],"--abort")==0) {
} else if (strcmp(argv[0],"--abort")==0 || strcmp(argv[0], "--test") == 0) {
do_abort=1;
} else if (strcmp(argv[0],"--commit")==0) {
do_commit=1;
} else if (strcmp(argv[0],"--recover-committed")==0) {
do_recover_committed=1;
} else if (strcmp(argv[0],"--recover-aborted")==0) {
} else if (strcmp(argv[0],"--recover-aborted")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_aborted=1;
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
......
/* Transaction consistency:
* fork a process:
* Open two tables, A and B
* begin transaction U
* begin transaction V
* store U.A into A using U
* store V.B into B using V
* checkpoint
* store U.C into A using U
* store V.D into B using V
* commit U
* maybe commit V
* abort the process abruptly
* wait for the process to finish
* open the environment doing recovery
* check to see if both rows are present in A and maybe present in B
*/
#include <sys/stat.h>
#include <sys/wait.h>
#include "test.h"
const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN;
char *namea="a.db";
char *nameb="b.db";
static void
put (DB_TXN *txn, DB *db, char *key, char *data) {
DBT k = {.data = key, .size=1+strlen(key) };
DBT d = {.data = data, .size=1+strlen(data)};
int r = db->put(db, txn, &k, &d, 0);
CKERR(r);
}
static void
do_x2_shutdown (BOOL do_commit) {
int r;
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
DB_ENV *env;
DB *dba, *dbb; // Use two DBs so that BDB doesn't get a lock conflict
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dba->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DB_TXN *txnU, *txnV;
r = env->txn_begin(env, NULL, &txnU, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txnV, 0); CKERR(r);
put(txnU, dba, "u.a", "u.a.data");
put(txnV, dbb, "v.b", "v.b.data");
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
put(txnU, dba, "u.c", "u.c.data");
put(txnV, dbb, "v.d", "v.d.data");
r = txnU->commit(txnU, 0); CKERR(r);
if (do_commit) {
r = txnV->commit(txnV, 0); CKERR(r);
}
abort();
}
static void
checkcurs (DBC *curs, int cursflags, char *key, char *val, BOOL expect_it) {
DBT k={.size=0}, v={.size=0};
int r = curs->c_get(curs, &k, &v, cursflags);
if (expect_it) {
assert(r==0);
printf("Got %s expected %s\n", (char*)k.data, key);
assert(strcmp(k.data, key)==0);
assert(strcmp(v.data, val)==0);
} else {
printf("Expected nothing, got r=%d\n", r);
assert(r!=0);
}
}
static void
do_x2_recover (BOOL did_commit) {
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags|DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
{
DB *dba;
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DBC *c;
r = dba->cursor(dba, txn, &c, 0); CKERR(r);
checkcurs(c, DB_FIRST, "u.a", "u.a.data", TRUE);
checkcurs(c, DB_NEXT, "u.c", "u.c.data", TRUE);
checkcurs(c, DB_NEXT, NULL, NULL, FALSE);
r = c->c_close(c); CKERR(r);
r = dba->close(dba, 0); CKERR(r);
}
{
DB *dbb;
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DBC *c;
r = dbb->cursor(dbb, txn, &c, 0); CKERR(r);
checkcurs(c, DB_FIRST, "v.b", "v.b.data", did_commit);
checkcurs(c, DB_NEXT, "v.d", "v.d.data", did_commit);
checkcurs(c, DB_NEXT, NULL, NULL, FALSE);
r = c->c_close(c); CKERR(r);
r = dbb->close(dbb, 0); CKERR(r);
}
r = txn->commit(txn, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
exit(0);
}
const char *cmd;
static void
do_test_internal (BOOL commit) {
pid_t pid;
if (0 == (pid=fork())) {
int r=execl(cmd, verbose ? "-v" : "-q", commit ? "--commit" : "--abort", NULL);
assert(r==-1);
printf("execl failed: %d (%s)\n", errno, strerror(errno));
assert(0);
}
{
int r;
int status;
r = waitpid(pid, &status, 0);
//printf("signaled=%d sig=%d\n", WIFSIGNALED(status), WTERMSIG(status));
assert(WIFSIGNALED(status) && WTERMSIG(status)==SIGABRT);
}
// Now find out what happend
if (0 == (pid = fork())) {
int r=execl(cmd, verbose ? "-v" : "-q", commit ? "--recover-committed" : "--recover-aborted", NULL);
assert(r==-1);
printf("execl failed: %d (%s)\n", errno, strerror(errno));
assert(0);
}
{
int r;
int status;
r = waitpid(pid, &status, 0);
//printf("recovery exited=%d\n", WIFEXITED(status));
assert(WIFEXITED(status) && WEXITSTATUS(status)==0);
}
}
static void
do_test (void) {
do_test_internal(TRUE);
do_test_internal(FALSE);
}
BOOL do_commit=FALSE, do_abort=FALSE, do_recover_committed=FALSE, do_recover_aborted=FALSE;
static void
x2_parse_args (int argc, char *argv[]) {
int resultcode;
cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-v") == 0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0],"--abort")==0) {
do_abort=1;
} else if (strcmp(argv[0],"--commit")==0 || strcmp(argv[0], "--test") == 0) {
do_commit=1;
} else if (strcmp(argv[0],"--recover-committed")==0 || strcmp(argv[0], "--recover") == 0) {
do_recover_committed=1;
} else if (strcmp(argv[0],"--recover-aborted")==0) {
do_recover_aborted=1;
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--abort | --commit | --recover-committed | --recover-aborted } \n", cmd);
exit(resultcode);
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
{
int n_specified=0;
if (do_commit) n_specified++;
if (do_abort) n_specified++;
if (do_recover_committed) n_specified++;
if (do_recover_aborted) n_specified++;
if (n_specified>1) {
printf("Specify only one of --commit or --abort or --recover-committed or --recover-aborted\n");
resultcode=1;
goto do_usage;
}
}
}
int
test_main (int argc, char *argv[]) {
x2_parse_args(argc, argv);
if (do_commit) {
do_x2_shutdown (TRUE);
} else if (do_abort) {
do_x2_shutdown (FALSE);
} else if (do_recover_committed) {
do_x2_recover(TRUE);
} else if (do_recover_aborted) {
do_x2_recover(FALSE);
} else {
do_test();
}
return 0;
}
/*
* Test recovery when a crash occurs before all tables are closed (xclose --commit)
* Open two tables, A and B
* checkpoint
* insert a in A and commit
* insert b in B and commit
* close A
* abort the process
*
* Verify the recovery (xclose --recover)
*/
#include <sys/stat.h>
#include <sys/wait.h>
#include "test.h"
const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN |DB_RECOVER;
char *namea="a.db";
char *nameb="b.db";
static void
do_xclose (void) {
int r;
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
DB_ENV *env;
DB *dba, *dbb;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
{
DBT a={.data="a", .size=2};
DBT b={.data="b", .size=2};
r = dba->put(dba, txn, &a, &b, 0); CKERR(r);
r = dbb->put(dbb, txn, &b, &a, 0); CKERR(r);
}
//printf("opened\n");
r = txn->commit(txn, 0); CKERR(r);
r = dba->close(dba, 0); CKERR(r);
//printf("shutdown\n");
abort();
}
static void
do_xclose_recover (BOOL did_commit) {
DB_ENV *env;
DB *dba, *dbb;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = db_create(&dbb, env, 0); CKERR(r);
r = dba->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DBT aa={.size=0}, ab={.size=0};
DBT ba={.size=0}, bb={.size=0};
DB_TXN *txn;
DBC *ca,*cb;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = dba->cursor(dba, txn, &ca, 0); CKERR(r);
r = dbb->cursor(dbb, txn, &cb, 0); CKERR(r);
int ra = ca->c_get(ca, &aa, &ab, DB_FIRST); CKERR(r);
int rb = cb->c_get(cb, &ba, &bb, DB_FIRST); CKERR(r);
if (did_commit) {
assert(ra==0);
assert(rb==0);
// verify key-value pairs
assert(aa.size==2);
assert(ab.size==2);
assert(ba.size==2);
assert(bb.size==2);
const char a[2] = "a";
const char b[2] = "b";
assert(memcmp(aa.data, &a, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(ab.data, &b, 2)==0);
assert(memcmp(bb.data, &a, 2)==0);
// make sure no other entries in DB
assert(ca->c_get(ca, &aa, &ab, DB_NEXT) == DB_NOTFOUND);
assert(cb->c_get(cb, &ba, &bb, DB_NEXT) == DB_NOTFOUND);
fprintf(stderr, "Both verified. Yay!\n");
} else {
// It wasn't committed (it also wasn't aborted), but a checkpoint happened.
assert(ra==DB_NOTFOUND);
assert(rb==DB_NOTFOUND);
fprintf(stderr, "Neither present. Yay!\n");
}
r = ca->c_close(ca); CKERR(r);
r = cb->c_close(cb); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
r = dba->close(dba, 0); CKERR(r);
r = dbb->close(dbb, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
exit(0);
}
BOOL do_commit=FALSE, do_recover=FALSE;
char *cmd;
static void
xclose_parse_args (int argc, char *argv[]) {
int resultcode;
cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-v") == 0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0],"--commit")==0) {
do_commit=1;
} else if (strcmp(argv[0],"--recover")==0) {
do_recover=1;
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--commit | --abort | --explicit-abort | --recover-committed | --recover-aborted } \n", cmd);
exit(resultcode);
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
{
int n_specified=0;
if (do_commit) n_specified++;
if (do_recover) n_specified++;
if (n_specified>1) {
printf("Specify only one of --commit or --recover\n");
resultcode=1;
goto do_usage;
}
}
}
int
test_main (int argc, char *argv[])
{
xclose_parse_args(argc, argv);
if (do_commit) {
do_xclose ();
} else if (do_recover) {
do_xclose_recover(TRUE);
}
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment