Commit 1380e291 authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

[t:2499] Loader temp files go in data dir, not env home dir (unless there is no data dir).

git-svn-id: file:///svn/toku/tokudb@20299 c7de825b-a66e-492c-adef-691d508d4ae1
parent 78e2151d
...@@ -127,8 +127,7 @@ static int verify_empty(DB *db, DB_TXN *txn) ...@@ -127,8 +127,7 @@ static int verify_empty(DB *db, DB_TXN *txn)
return r; return r;
} }
//static const char *loader_temp_prefix = "temp"; static const char *loader_temp_prefix = "tokuld"; // #2536
static const char *loader_temp_prefix = "tokuld"; // 2536
static const char *loader_temp_suffix = "XXXXXX"; static const char *loader_temp_suffix = "XXXXXX";
int toku_loader_create_loader(DB_ENV *env, int toku_loader_create_loader(DB_ENV *env,
...@@ -159,7 +158,7 @@ int toku_loader_create_loader(DB_ENV *env, ...@@ -159,7 +158,7 @@ int toku_loader_create_loader(DB_ENV *env,
loader->i->loader_flags = loader_flags; loader->i->loader_flags = loader_flags;
loader->i->temp_file_template = (char *)toku_malloc(MAX_FILE_SIZE); loader->i->temp_file_template = (char *)toku_malloc(MAX_FILE_SIZE);
int n = snprintf(loader->i->temp_file_template, MAX_FILE_SIZE, "%s/%s%s", env->i->dir, loader_temp_prefix, loader_temp_suffix); int n = snprintf(loader->i->temp_file_template, MAX_FILE_SIZE, "%s/%s%s", env->i->real_data_dir, loader_temp_prefix, loader_temp_suffix);
if ( !(n>0 && n<MAX_FILE_SIZE) ) { if ( !(n>0 && n<MAX_FILE_SIZE) ) {
rval = -1; rval = -1;
goto create_exit; goto create_exit;
...@@ -393,7 +392,8 @@ int toku_loader_abort(DB_LOADER *loader) ...@@ -393,7 +392,8 @@ int toku_loader_abort(DB_LOADER *loader)
int toku_loader_cleanup_temp_files(DB_ENV *env) { int toku_loader_cleanup_temp_files(DB_ENV *env) {
int result; int result;
struct dirent *de; struct dirent *de;
DIR *d = opendir(env->i->dir); char * dir = env->i->real_data_dir;
DIR *d = opendir(dir);
if (d==0) { if (d==0) {
result = errno; goto exit; result = errno; goto exit;
} }
...@@ -402,9 +402,9 @@ int toku_loader_cleanup_temp_files(DB_ENV *env) { ...@@ -402,9 +402,9 @@ int toku_loader_cleanup_temp_files(DB_ENV *env) {
while ((de = readdir(d))) { while ((de = readdir(d))) {
int r = memcmp(de->d_name, loader_temp_prefix, strlen(loader_temp_prefix)); int r = memcmp(de->d_name, loader_temp_prefix, strlen(loader_temp_prefix));
if (r == 0 && strlen(de->d_name) == strlen(loader_temp_prefix) + strlen(loader_temp_suffix)) { if (r == 0 && strlen(de->d_name) == strlen(loader_temp_prefix) + strlen(loader_temp_suffix)) {
int fnamelen = strlen(env->i->dir) + 1 + strlen(de->d_name) + 1; // One for the slash and one for the trailing NUL. int fnamelen = strlen(dir) + 1 + strlen(de->d_name) + 1; // One for the slash and one for the trailing NUL.
char fname[fnamelen]; char fname[fnamelen];
int l = snprintf(fname, fnamelen, "%s/%s", env->i->dir, de->d_name); int l = snprintf(fname, fnamelen, "%s/%s", dir, de->d_name);
assert(l+1 == fnamelen); assert(l+1 == fnamelen);
r = unlink(fname); r = unlink(fname);
if (r!=0) { if (r!=0) {
......
...@@ -72,7 +72,7 @@ enum {MAGIC=311}; ...@@ -72,7 +72,7 @@ enum {MAGIC=311};
DBT old_inames[MAX_DBS]; DBT old_inames[MAX_DBS];
DBT new_inames[MAX_DBS]; DBT new_inames[MAX_DBS];
static const char *loader_temp_prefix = "tokuld"; // 2536 static const char *loader_temp_prefix = "tokuld"; // #2536
static int count_temp(char * dirname); static int count_temp(char * dirname);
static void get_inames(DBT* inames, DB** dbs); static void get_inames(DBT* inames, DB** dbs);
static int verify_file(char * dirname, char * filename); static int verify_file(char * dirname, char * filename);
...@@ -174,6 +174,10 @@ count_temp(char * dirname) { ...@@ -174,6 +174,10 @@ count_temp(char * dirname) {
while ((ent=readdir(dir))) { while ((ent=readdir(dir))) {
if (ent->d_type==DT_REG && strncmp(ent->d_name, loader_temp_prefix, 6)==0) { if (ent->d_type==DT_REG && strncmp(ent->d_name, loader_temp_prefix, 6)==0) {
n++; n++;
if (verbose >= 3) {
printf("Temp files\n");
printf(" %s/%s\n", dirname, ent->d_name);
}
} }
} }
closedir(dir); closedir(dir);
...@@ -210,7 +214,7 @@ get_inames(DBT* inames, DB** dbs) { ...@@ -210,7 +214,7 @@ get_inames(DBT* inames, DB** dbs) {
int r = env->get_iname(env, &dname, &inames[i]); int r = env->get_iname(env, &dname, &inames[i]);
CKERR(r); CKERR(r);
char * iname_str = (char*) (inames[i].data); char * iname_str = (char*) (inames[i].data);
if (verbose) printf("dname = %s, iname = %s\n", dname_str, iname_str); if (verbose >= 2) printf("dname = %s, iname = %s\n", dname_str, iname_str);
} }
} }
...@@ -462,7 +466,8 @@ static void test_loader(enum test_type t, DB **dbs) ...@@ -462,7 +466,8 @@ static void test_loader(enum test_type t, DB **dbs)
} }
uint32_t loader_flags = USE_PUTS; // set with -p option uint32_t loader_flags = USE_PUTS; // set with -p option
if (verbose) printf("old inames:\n"); if (verbose >= 2)
printf("old inames:\n");
get_inames(old_inames, dbs); get_inames(old_inames, dbs);
// create and initialize loader // create and initialize loader
...@@ -476,7 +481,8 @@ static void test_loader(enum test_type t, DB **dbs) ...@@ -476,7 +481,8 @@ static void test_loader(enum test_type t, DB **dbs)
CKERR(r); CKERR(r);
printf("USE_PUTS = %d\n", USE_PUTS); printf("USE_PUTS = %d\n", USE_PUTS);
if (verbose) printf("new inames:\n"); if (verbose >= 2)
printf("new inames:\n");
get_inames(new_inames, dbs); get_inames(new_inames, dbs);
// using loader->put, put values into DB // using loader->put, put values into DB
......
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