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

cleanup old loader temp files when the env is opened closes[t:2550]

git-svn-id: file:///svn/toku/tokudb@19941 c7de825b-a66e-492c-adef-691d508d4ae1
parent dec35a62
......@@ -119,6 +119,9 @@ static int verify_empty(DB *db, DB_TXN *txn)
return r;
}
static const char *loader_temp_prefix = "temp";
static const char *loader_temp_suffix = "XXXXXX";
int toku_loader_create_loader(DB_ENV *env,
DB_TXN *txn,
DB_LOADER **blp,
......@@ -145,7 +148,7 @@ int toku_loader_create_loader(DB_ENV *env,
loader->i->loader_flags = loader_flags;
loader->i->temp_file_template = (char *)toku_malloc(MAX_FILE_SIZE);
int n = snprintf(loader->i->temp_file_template, MAX_FILE_SIZE, "%s/tempXXXXXX", env->i->dir);
int n = snprintf(loader->i->temp_file_template, MAX_FILE_SIZE, "%s/%s%s", env->i->dir, loader_temp_prefix, loader_temp_suffix);
if ( !(n>0 && n<MAX_FILE_SIZE) ) {
free_loader(loader);
return -1;
......@@ -349,3 +352,37 @@ int toku_loader_abort(DB_LOADER *loader)
free_loader(loader);
return r;
}
// find all of the files in the environments home directory that match the loader temp name and remove them
int toku_loader_cleanup_temp_files(DB_ENV *env) {
int result;
struct dirent *de;
DIR *d = opendir(env->i->dir);
if (d==0) {
result = errno; goto exit;
}
result = 0;
while ((de = readdir(d))) {
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)) {
int fnamelen = strlen(env->i->dir) + 1 + strlen(de->d_name) + 1; // One for the slash and one for the trailing NUL.
char fname[fnamelen];
int l = snprintf(fname, fnamelen, "%s/%s", env->i->dir, de->d_name);
assert(l+1 == fnamelen);
r = unlink(fname);
if (r!=0) {
result = errno;
perror("Trying to delete a rolltmp file");
}
}
}
{
int r = closedir(d);
if (r == -1)
result = errno;
}
exit:
return result;
}
#ifndef TOKULOADER_H
#define TOKULOADER_H
#ifndef TOKU_LOADER_H
#define TOKU_LOADER_H
/* Copyright (c) 2007, 2008, 2009 Tokutek Inc. All rights reserved.
#if defined(__cplusplus)
extern "C" {
#endif
/* Copyright (c) 2007-2010 Tokutek Inc. All rights reserved.
*
* The technology is licensed by the Massachusetts Institute of Technology,
* Rutgers State University of New Jersey, and the Research Foundation of
......@@ -10,10 +14,22 @@
*/
int toku_loader_create_loader(DB_ENV *env, DB_TXN *txn, DB_LOADER **blp, DB *src_db, int N, DB *dbs[N], uint32_t db_flags[N], uint32_t dbt_flags[N], uint32_t loader_flags);
int toku_loader_set_error_callback(DB_LOADER *loader, void (*error_cb)(DB *db, int i, int err, DBT *key, DBT *val, void *error_extra), void *error_extra);
int toku_loader_set_poll_function(DB_LOADER *loader, int (*poll_func)(void *poll_extra, float progress), void *poll_extra);
int toku_loader_put(DB_LOADER *loader, DBT *key, DBT *val);
int toku_loader_close(DB_LOADER *loader);
int toku_loader_abort(DB_LOADER *loader);
// Remove any loader temp files that may have been left from a crashed system
int toku_loader_cleanup_temp_files(DB_ENV *env);
#if defined(__cplusplus)
}
#endif
#endif
......@@ -782,6 +782,8 @@ toku_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mode) {
}
}
}
toku_loader_cleanup_temp_files(env);
if (flags & (DB_INIT_TXN | DB_INIT_LOG)) {
assert(env->i->logger);
......
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