Commit 99f483bd authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

close[t:4435]. Merge the changes in for #4435 (no more {{{chdir()}}} allowed...

close[t:4435].  Merge the changes in for #4435 (no more {{{chdir()}}} allowed during recovery) to main.  {{{svn merge -r 39184:39201 ../tokudb.4435}}}.  Closes #4435.


git-svn-id: file:///svn/toku/tokudb@39209 c7de825b-a66e-492c-adef-691d508d4ae1
parent ddcd118c
...@@ -186,15 +186,18 @@ struct recover_env { ...@@ -186,15 +186,18 @@ struct recover_env {
}; };
typedef struct recover_env *RECOVER_ENV; typedef struct recover_env *RECOVER_ENV;
static int recover_env_init (RECOVER_ENV renv, brt_compare_func bt_compare, static int recover_env_init (RECOVER_ENV renv,
const char *env_dir,
brt_compare_func bt_compare,
brt_update_func update_function, brt_update_func update_function,
generate_row_for_put_func generate_row_for_put, generate_row_for_put_func generate_row_for_put,
generate_row_for_del_func generate_row_for_del, generate_row_for_del_func generate_row_for_del,
size_t cachetable_size) { size_t cachetable_size) {
int r; int r;
r = toku_create_cachetable(&renv->ct, cachetable_size ? cachetable_size : 1<<25, (LSN){0}, 0); r = toku_brt_create_cachetable(&renv->ct, cachetable_size ? cachetable_size : 1<<25, (LSN){0}, 0);
assert(r == 0); assert(r == 0);
toku_cachetable_set_env_dir(renv->ct, env_dir);
r = toku_logger_create(&renv->logger); r = toku_logger_create(&renv->logger);
assert(r == 0); assert(r == 0);
toku_logger_write_log_files(renv->logger, FALSE); toku_logger_write_log_files(renv->logger, FALSE);
...@@ -642,13 +645,15 @@ static int toku_recover_fcreate (struct logtype_fcreate *l, RECOVER_ENV renv) { ...@@ -642,13 +645,15 @@ static int toku_recover_fcreate (struct logtype_fcreate *l, RECOVER_ENV renv) {
//unlink if it exists (recreate from scratch). //unlink if it exists (recreate from scratch).
char *iname = fixup_fname(&l->iname); char *iname = fixup_fname(&l->iname);
r = unlink(iname); char *iname_in_cwd = toku_cachetable_get_fname_in_cwd(renv->ct, iname);
r = unlink(iname_in_cwd);
if (r != 0 && errno != ENOENT) { if (r != 0 && errno != ENOENT) {
fprintf(stderr, "Tokudb recovery %s:%d unlink %s %d\n", __FUNCTION__, __LINE__, iname, errno); fprintf(stderr, "Tokudb recovery %s:%d unlink %s %d\n", __FUNCTION__, __LINE__, iname, errno);
toku_free(iname); toku_free(iname);
return r; return r;
} }
assert(strcmp(iname, ROLLBACK_CACHEFILE_NAME)); //Creation of rollback cachefile never gets logged. assert(strcmp(iname, ROLLBACK_CACHEFILE_NAME)); //Creation of rollback cachefile never gets logged.
toku_free(iname_in_cwd);
toku_free(iname); toku_free(iname);
BOOL must_create = TRUE; BOOL must_create = TRUE;
...@@ -1179,7 +1184,7 @@ static int do_recovery(RECOVER_ENV renv, const char *env_dir, const char *log_di ...@@ -1179,7 +1184,7 @@ static int do_recovery(RECOVER_ENV renv, const char *env_dir, const char *log_di
struct log_entry *le = NULL; struct log_entry *le = NULL;
time_t tnow = time(NULL); time_t tnow = time(NULL);
fprintf(stderr, "%.24s Tokudb recovery starting\n", ctime(&tnow)); fprintf(stderr, "%.24s Tokudb recovery starting in env %s\n", ctime(&tnow), env_dir);
char org_wd[1000]; char org_wd[1000];
{ {
...@@ -1211,11 +1216,12 @@ static int do_recovery(RECOVER_ENV renv, const char *env_dir, const char *log_di ...@@ -1211,11 +1216,12 @@ static int do_recovery(RECOVER_ENV renv, const char *env_dir, const char *log_di
r = toku_logcursor_create(&logcursor, log_dir); r = toku_logcursor_create(&logcursor, log_dir);
assert(r == 0); assert(r == 0);
r = chdir(env_dir); {
if (r != 0) { toku_struct_stat buf;
// no data directory error if (toku_stat(env_dir, &buf)!=0) {
rr = errno; goto errorexit; rr = errno; goto errorexit;
} }
}
// scan backwards // scan backwards
scan_state_init(&renv->ss); scan_state_init(&renv->ss);
...@@ -1352,9 +1358,6 @@ static int do_recovery(RECOVER_ENV renv, const char *env_dir, const char *log_di ...@@ -1352,9 +1358,6 @@ static int do_recovery(RECOVER_ENV renv, const char *env_dir, const char *log_di
tnow = time(NULL); tnow = time(NULL);
fprintf(stderr, "%.24s Tokudb recovery done\n", ctime(&tnow)); fprintf(stderr, "%.24s Tokudb recovery done\n", ctime(&tnow));
r = chdir(org_wd);
assert(r == 0);
return 0; return 0;
errorexit: errorexit:
...@@ -1366,9 +1369,6 @@ static int do_recovery(RECOVER_ENV renv, const char *env_dir, const char *log_di ...@@ -1366,9 +1369,6 @@ static int do_recovery(RECOVER_ENV renv, const char *env_dir, const char *log_di
assert(r == 0); assert(r == 0);
} }
r = chdir(org_wd);
assert(r == 0);
return rr; return rr;
} }
...@@ -1416,7 +1416,9 @@ int tokudb_recover(const char *env_dir, const char *log_dir, ...@@ -1416,7 +1416,9 @@ int tokudb_recover(const char *env_dir, const char *log_dir,
int rr = 0; int rr = 0;
if (tokudb_needs_recovery(log_dir, FALSE)) { if (tokudb_needs_recovery(log_dir, FALSE)) {
struct recover_env renv; struct recover_env renv;
r = recover_env_init(&renv, bt_compare, r = recover_env_init(&renv,
env_dir,
bt_compare,
update_function, update_function,
generate_row_for_put, generate_row_for_put,
generate_row_for_del, generate_row_for_del,
......
...@@ -10,7 +10,7 @@ static void recover_callback_at_turnaround(void *UU(arg)) { ...@@ -10,7 +10,7 @@ static void recover_callback_at_turnaround(void *UU(arg)) {
// change the LSN in the first log entry of log 2. this will cause an LSN error during the forward scan. // change the LSN in the first log entry of log 2. this will cause an LSN error during the forward scan.
int r; int r;
char logname[PATH_MAX]; char logname[PATH_MAX];
sprintf(logname, "log000000000002.tokulog%d", TOKU_LOG_VERSION); sprintf(logname, "%s/log000000000002.tokulog%d", TESTDIR, TOKU_LOG_VERSION);
FILE *f = fopen(logname, "r+b"); assert(f); FILE *f = fopen(logname, "r+b"); assert(f);
r = fseek(f, 025, SEEK_SET); assert(r == 0); r = fseek(f, 025, SEEK_SET); assert(r == 0);
char c = 100; char c = 100;
......
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