Commit e7a3f6b8 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

some changes related to recovery and the log. close[t:1959]

git-svn-id: file:///svn/toku/tokudb@14328 c7de825b-a66e-492c-adef-691d508d4ae1
parent e018b787
......@@ -747,26 +747,56 @@ static int do_recovery(RECOVER_ENV env, const char *data_dir, const char *log_di
return rr;
}
int tokudb_recover(const char *data_dir, const char *log_dir, brt_compare_func bt_compare, brt_compare_func dup_compare) {
int r;
int lockfd;
{
static int recover_lock(const char *lock_dir, int *lockfd) {
const char fname[] = "/__recoverylock_dont_delete_me";
int namelen=strlen(data_dir);
int namelen=strlen(lock_dir);
char lockfname[namelen+sizeof(fname)];
int l = snprintf(lockfname, sizeof(lockfname), "%s%s", data_dir, fname);
int l = snprintf(lockfname, sizeof(lockfname), "%s%s", lock_dir, fname);
assert(l+1 == (signed)(sizeof(lockfname)));
lockfd = toku_os_lock_file(lockfname);
if (lockfd<0) {
*lockfd = toku_os_lock_file(lockfname);
if (*lockfd < 0) {
int e = errno;
printf("Couldn't run recovery because some other process holds the recovery lock %s\n", lockfname);
return errno; }
return e;
}
return 0;
}
static int recover_unlock(int lockfd) {
int r = toku_os_unlock_file(lockfd);
if (r != 0)
return errno;
return 0;
}
int tokudb_recover_delete_rolltmp_files(const char *UU(data_dir), const char *log_dir) {
int lockfd = -1;
int r = recover_lock(log_dir, &lockfd);
if (r != 0)
return r;
r = toku_delete_rolltmp_files(log_dir);
int rr = recover_unlock(lockfd);
if (r == 0 && rr != 0)
r = rr;
return r;
}
int tokudb_recover(const char *data_dir, const char *log_dir, brt_compare_func bt_compare, brt_compare_func dup_compare) {
int r;
int lockfd = -1;
r = recover_lock(log_dir, &lockfd);
if (r != 0)
return r;
r = toku_delete_rolltmp_files(log_dir);
if (r != 0) {
toku_os_unlock_file(lockfd);
(void) recover_unlock(lockfd);
return r;
}
......@@ -781,8 +811,9 @@ int tokudb_recover(const char *data_dir, const char *log_dir, brt_compare_func b
recover_env_cleanup(&renv);
}
r = toku_os_unlock_file(lockfd);
if (r != 0) return errno;
r = recover_unlock(lockfd);
if (r != 0)
return r;
return rr;
}
......@@ -15,7 +15,7 @@
#include "x1764.h"
// Run tokudb recovery from the log
// Returns: 0 if successfull
// Returns 0 if success
int tokudb_recover(const char *datadir, const char *logdir, brt_compare_func bt_compare, brt_compare_func dup_compare);
// Effect: Check the tokudb logs to determine whether or not we need to run recovery.
......@@ -24,4 +24,8 @@ int tokudb_recover(const char *datadir, const char *logdir, brt_compare_func bt_
// Returns: TRUE if we need recovery, otherwise FALSE.
int tokudb_needs_recovery(const char *logdir, BOOL ignore_empty_log);
// Delete the rolltmp files
// Ruturns 0 if success
int tokudb_recover_delete_rolltmp_files(const char *datadir, const char *logdir);
#endif // TOKURECOVER_H
......@@ -20,7 +20,7 @@ static void do_1381_maybe_lock (int do_table_lock, u_int64_t *raw_count) {
DB_ENV *env;
DB *db;
const int envflags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK|DB_INIT_LOG |DB_THREAD |DB_PRIVATE | DB_RECOVER;
const int envflags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK|DB_THREAD|DB_PRIVATE;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
......@@ -35,7 +35,7 @@ static void do_1381_maybe_lock (int do_table_lock, u_int64_t *raw_count) {
{
DB_ENV *env;
DB *db;
const int envflags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK|DB_INIT_LOG |DB_THREAD |DB_PRIVATE;
const int envflags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK|DB_THREAD |DB_PRIVATE;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
......
// test data directories
#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;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB *dba;
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, "a.db", NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = dba->close(dba, 0); CKERR(r);
DB *dbb;
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->open(dbb, NULL, "bdir/b.db", NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); assert(r != 0);
r = toku_os_mkdir(ENVDIR "/bdir", 0777); assert(r == 0);
r = dbb->open(dbb, NULL, "bdir/b.db", NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = dbb->close(dbb, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
r = toku_os_mkdir(ENVDIR "/cdir", 0777); assert(r == 0);
r = db_env_create(&env, 0); CKERR(r);
r = env->set_data_dir(env, "cdir"); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB *dbc;
r = db_create(&dbc, env, 0); CKERR(r);
r = dbc->open(dbc, NULL, "c.db", NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
r = dbc->close(dbc, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
const char *cmd;
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], "-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);
run_test();
return 0;
}
......@@ -35,6 +35,13 @@ do_1324 (int moreflags)
DB_ENV *env;
int r;
if (moreflags & DB_INIT_LOG) {
// create the log
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);
}
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
......
......@@ -27,6 +27,11 @@ test_txn_recover3 (int nrows) {
const char * const sname = "t.tokudb/status.brt";
int r;
r = db_env_create(&env, 0); assert(r == 0);
env->set_errfile(env, stderr);
r = env->open(env, ENVDIR, DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK|DB_INIT_LOG |DB_THREAD |DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = env->close(env, 0); CKERR(r);
r = db_env_create(&env, 0); assert(r == 0);
env->set_errfile(env, stderr);
r = env->open(env, ENVDIR, DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK|DB_INIT_LOG |DB_THREAD |DB_PRIVATE | DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
......
......@@ -294,6 +294,19 @@ static int toku_c_close(DBC * c);
/* misc */
static char *construct_full_name(const char *dir, const char *fname);
static int delete_rolltmp_files(DB_ENV *env) {
const char *datadir=env->i->dir;
char *logdir;
if (env->i->lg_dir) {
logdir = construct_full_name(env->i->dir, env->i->lg_dir);
} else {
logdir = toku_strdup(env->i->dir);
}
int r = tokudb_recover_delete_rolltmp_files(datadir, logdir);
toku_free(logdir);
return r;
}
static int do_recovery (DB_ENV *env) {
const char *datadir=env->i->dir;
char *logdir;
......@@ -387,13 +400,20 @@ static int toku_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mo
unused_flags &= ~DB_INIT_TXN & ~DB_INIT_LOG;
if (flags&DB_RECOVER) {
if (flags & DB_INIT_TXN) {
r = delete_rolltmp_files(env);
if (r != 0) return r;
}
if (flags & DB_INIT_LOG) {
if (flags & DB_RECOVER) {
r = do_recovery(env);
if (r != 0) return r;
} else {
r = needs_recovery(env);
if (r != 0) return r;
}
}
if (flags & (DB_INIT_TXN | DB_INIT_LOG)) {
char* full_dir = NULL;
......
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