Commit 94a5f224 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

test missing log entries [t:1959]

git-svn-id: file:///svn/toku/tokudb@14313 c7de825b-a66e-492c-adef-691d508d4ae1
parent 17b53318
......@@ -20,7 +20,7 @@ struct toku_logcursor {
enum lc_direction last_direction;
};
#define LC_LSN_ERROR (-1)
#define LC_LSN_ERROR (DB_RUNRECOVERY)
static void lc_print_logcursor (TOKULOGCURSOR lc) __attribute__((unused));
static void lc_print_logcursor (TOKULOGCURSOR lc) {
......@@ -70,7 +70,9 @@ static int lc_check_lsn(TOKULOGCURSOR lc, int dir) {
LSN lsn = toku_log_entry_get_lsn(&(lc->entry));
if (((dir == LC_FORWARD) && ( lsn.lsn != lc->cur_lsn.lsn + 1 )) ||
((dir == LC_BACKWARD) && ( lsn.lsn != lc->cur_lsn.lsn - 1 ))) {
fprintf(stderr, "Bad LSN : direction = %d, lsn.lsn = %"PRIu64", cur_lsn.lsn=%"PRIu64"\n", dir, lsn.lsn, lc->cur_lsn.lsn);
int index = lc->cur_logfiles_index;
fprintf(stderr, "Bad LSN: %d %s direction = %d, lsn.lsn = %"PRIu64", cur_lsn.lsn=%"PRIu64"\n",
index, lc->logfiles[index], dir, lsn.lsn, lc->cur_lsn.lsn);
return LC_LSN_ERROR;
}
lc->cur_lsn.lsn = lsn.lsn;
......
......@@ -624,6 +624,8 @@ static void abort_live_txn(void *v, void *UU(extra)) {
static int do_recovery(RECOVER_ENV env, const char *data_dir, const char *log_dir) {
int r;
int rr = 0;
TOKULOGCURSOR logcursor = NULL;
char org_wd[1000];
{
......@@ -637,12 +639,14 @@ static int do_recovery(RECOVER_ENV env, const char *data_dir, const char *log_di
LSN lastlsn = toku_logger_last_lsn(env->logger);
TOKULOGCURSOR logcursor;
r = toku_logcursor_create(&logcursor, log_dir);
assert(r == 0);
r = chdir(data_dir);
assert(r == 0);
if (r != 0) {
// no data directory error
rr = errno; goto errorexit;
}
struct log_entry *le;
......@@ -653,8 +657,12 @@ static int do_recovery(RECOVER_ENV env, const char *data_dir, const char *log_di
r = toku_logcursor_prev(logcursor, &le);
if (toku_recover_trace)
printf("%s:%d r=%d cmd=%c\n", __FUNCTION__, __LINE__, r, le ? le->cmd : '?');
if (r != 0)
if (r != 0) {
if (r == DB_RUNRECOVERY) {
rr = DB_RUNRECOVERY; goto errorexit;
}
break;
}
logtype_dispatch_assign(le, toku_recover_backward_, r, env);
if (r != 0) {
if (toku_recover_trace)
......@@ -670,8 +678,12 @@ static int do_recovery(RECOVER_ENV env, const char *data_dir, const char *log_di
r = toku_logcursor_next(logcursor, &le);
if (toku_recover_trace)
printf("%s:%d r=%d cmd=%c\n", __FUNCTION__, __LINE__, r, le ? le->cmd : '?');
if (r != 0)
if (r != 0) {
if (r == DB_RUNRECOVERY) {
rr = DB_RUNRECOVERY; goto errorexit;
}
break;
}
logtype_dispatch_args(le, toku_recover_, env);
}
......@@ -710,6 +722,17 @@ static int do_recovery(RECOVER_ENV env, const char *data_dir, const char *log_di
assert(r == 0);
return 0;
errorexit:
if (logcursor) {
r = toku_logcursor_destroy(&logcursor);
assert(r == 0);
}
r = chdir(org_wd);
assert(r == 0);
return rr;
}
int tokudb_recover(const char *data_dir, const char *log_dir, brt_compare_func bt_compare, brt_compare_func dup_compare) {
......@@ -749,7 +772,5 @@ int tokudb_recover(const char *data_dir, const char *log_dir, brt_compare_func b
r = toku_os_unlock_file(lockfd);
if (r != 0) return errno;
//printf("%s:%d recovery successful! ls -l says\n", __FILE__, __LINE__);
return rr;
}
// verify that DB_RUNRECOVERY is returned when there is a missing logfile
#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 run_test (void) {
int r;
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
DB_ENV *env;
DB *dba, *dbb;
// create logfile 0
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r);
// create logfile 1
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r);
// create logfile 2
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);
dbb = NULL;
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 = txn->commit(txn, 0); CKERR(r);
abort();
}
static void run_recover (void) {
DB_ENV *env;
int r;
r = rename(ENVDIR "/log000000000001.tokulog", ENVDIR "/save000000000001");
assert(r == 0);
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 = rename(ENVDIR "/save000000000001", ENVDIR "/log000000000001.tokulog");
assert(r == 0);
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 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); CKERR(r);
r = env->close(env, 0); CKERR(r);
exit(0);
}
const char *cmd;
BOOL do_test=FALSE, do_recover=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], "--test")==0) {
do_test=TRUE;
} else if (strcmp(argv[0], "--recover") == 0) {
do_recover=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] {--test | --recover } \n", cmd);
exit(resultcode);
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
}
int test_main (int argc, char *argv[]) {
test_parse_args(argc, argv);
if (do_test) {
run_test();
} else if (do_recover) {
run_recover();
} else if (do_recover_only) {
run_recover();
} else if (do_no_recover) {
run_no_recover();
}
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