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

Remove rolltmp files during recovery. Fixes #1324.

git-svn-id: file:///svn/toku/tokudb@9090 c7de825b-a66e-492c-adef-691d508d4ae1
parent 80599b87
...@@ -68,7 +68,6 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp) { ...@@ -68,7 +68,6 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp) {
} }
int dirnamelen = strlen(directory); int dirnamelen = strlen(directory);
while ((de=readdir(d))) { while ((de=readdir(d))) {
if (de==0) return errno;
long long thisl; long long thisl;
int r = sscanf(de->d_name, "log%lld.tokulog", &thisl); int r = sscanf(de->d_name, "log%lld.tokulog", &thisl);
if (r!=1) continue; // Skip over non-log files. if (r!=1) continue; // Skip over non-log files.
......
...@@ -698,7 +698,36 @@ static int toku_recover_xbegin (LSN UU(lsn), TXNID UU(parent)) { ...@@ -698,7 +698,36 @@ static int toku_recover_xbegin (LSN UU(lsn), TXNID UU(parent)) {
return 0; return 0;
} }
static int toku_delete_rolltmp_files (const char *log_dir) {
struct dirent *de;
DIR *d = opendir(log_dir);
if (d==0) {
return errno;
}
int result = 0;
while ((de=readdir(d))) {
char rolltmp_prefix[] = "__rolltmp.";
int r = memcmp(de->d_name, rolltmp_prefix, sizeof(rolltmp_prefix) - 1);
if (r==0) {
int fnamelen = strlen(log_dir) + strlen(de->d_name) + 2; // One for the slash and one for the trailing NUL.
char fname[fnamelen];
snprintf(fname, fnamelen, "%s/%s", log_dir, de->d_name);
r = unlink(fname);
if (r!=0) {
result = errno;
perror("Trying to delete a rolltmp file");
}
}
}
{
int r = closedir(d);
if (r==-1) return errno;
}
return result;
}
int tokudb_recover(const char *data_dir, const char *log_dir) { int tokudb_recover(const char *data_dir, const char *log_dir) {
int failresult = 0;
int r; int r;
int entrycount=0; int entrycount=0;
char **logfiles; char **logfiles;
...@@ -718,8 +747,11 @@ int tokudb_recover(const char *data_dir, const char *log_dir) { ...@@ -718,8 +747,11 @@ int tokudb_recover(const char *data_dir, const char *log_dir) {
} }
} }
r = toku_delete_rolltmp_files(log_dir);
if (r!=0) { failresult=r; goto fail; }
r = toku_logger_find_logfiles(log_dir, &logfiles); r = toku_logger_find_logfiles(log_dir, &logfiles);
if (r!=0) return r; if (r!=0) { failresult=r; goto fail; }
int i; int i;
toku_recover_init(); toku_recover_init();
char org_wd[1000]; char org_wd[1000];
...@@ -778,4 +810,8 @@ int tokudb_recover(const char *data_dir, const char *log_dir) { ...@@ -778,4 +810,8 @@ int tokudb_recover(const char *data_dir, const char *log_dir) {
//printf("%s:%d recovery successful! ls -l says\n", __FILE__, __LINE__); //printf("%s:%d recovery successful! ls -l says\n", __FILE__, __LINE__);
//system("ls -l"); //system("ls -l");
return 0; return 0;
fail:
toku_os_unlock_file(lockfd);
chdir(org_wd);
return failresult;
} }
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include "test.h"
/* Test for #1324. Make sure rolltmp files are removed. */
#include <db.h>
#include <fcntl.h>
void mkfile (const char *fname) {
int fd = creat(fname, O_WRONLY);
if (fd<0) perror("opening");
assert(fd>=0);
int r = write(fd, "hello\n", 6); assert(r==6);
r = close(fd); assert(r==0);
}
void
do_1324 (int moreflags)
{
const char fname[] = ENVDIR "/__rolltmp.12345";
const char fnamekeep[] = ENVDIR "/keepme";
system("rm -rf " ENVDIR);
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
mkfile(fname);
mkfile(fnamekeep);
const int envflags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK |DB_THREAD |DB_PRIVATE | DB_RECOVER | moreflags;
{
DB_ENV *env;
int r;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
{
struct stat sbuf;
r = stat(fname, &sbuf);
if (r==0) {
fprintf(stderr, "The rolltmp file %s should have been deleted, but was not.\n", fname);
}
assert(r!=0);
}
{
struct stat sbuf;
r = stat(fnamekeep, &sbuf);
if (r!=0) {
fprintf(stderr, "The keepme file %s should NOT have been deleted, but was not.\n", fnamekeep);
}
assert(r==0);
}
r = env->close(env, 0); CKERR(r);
}
system("ls -l " ENVDIR);
// make sure we can open the env again.
{
DB_ENV *env;
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 = env->close(env, 0); CKERR(r);
}
}
int
test_main (int argc, const char *argv[])
{
parse_args(argc, argv);
do_1324(DB_INIT_LOG);
do_1324(0);
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