Commit a7f62478 authored by Dave Wells's avatar Dave Wells Committed by Yoni Fogel

address and close #2521 [t:2521]

git-svn-id: file:///svn/toku/tokudb@19894 c7de825b-a66e-492c-adef-691d508d4ae1
parent c37f8a21
...@@ -13,28 +13,17 @@ static int delete_logfile(TOKULOGGER logger, long long index); ...@@ -13,28 +13,17 @@ static int delete_logfile(TOKULOGGER logger, long long index);
static void grab_output(TOKULOGGER logger, LSN *fsynced_lsn); static void grab_output(TOKULOGGER logger, LSN *fsynced_lsn);
static void release_output(TOKULOGGER logger, LSN fsynced_lsn); static void release_output(TOKULOGGER logger, LSN fsynced_lsn);
// added for #2424 // added for #2424, improved for #2521
static BOOL is_a_logfile(char *name) { static BOOL is_a_logfile (const char *name, long long *number_result) {
int r=0; unsigned long long result;
long long num = 0; int n;
int len = strlen(name); int r = sscanf(name, "log%llu.tokulog%n", &result, &n);
char num_str[128]; if (r!=1 || name[n]!=0) return FALSE;
if ( len < 11 ) goto not_logfile; *number_result = result;
// check 'log'
r = strncmp(&name[0], "log", 3);
if (r!=0) goto not_logfile;
// check number
r = snprintf(&num_str[0], len-11, "%s", &name[3]);
r = sscanf(num_str, "%lld", &num);
if (r!=1) goto not_logfile;
// check '.tokulog'
r = strncmp(&name[len-8], ".tokulog", 8);
if (r!=0) goto not_logfile;
return TRUE; return TRUE;
not_logfile:
return FALSE;
} }
int toku_logger_create (TOKULOGGER *resultp) { int toku_logger_create (TOKULOGGER *resultp) {
int r; int r;
TAGMALLOC(TOKULOGGER, result); TAGMALLOC(TOKULOGGER, result);
...@@ -526,12 +515,10 @@ int toku_logger_find_next_unused_log_file(const char *directory, long long *resu ...@@ -526,12 +515,10 @@ int toku_logger_find_next_unused_log_file(const char *directory, long long *resu
if (d==0) return errno; if (d==0) return errno;
while ((de=readdir(d))) { while ((de=readdir(d))) {
if (de==0) return errno; if (de==0) return errno;
long long thisl; long long thisl;
int r = 0; if ( is_a_logfile(de->d_name, &thisl) ) {
if ( is_a_logfile(de->d_name) ) { // #2424 if ((long long)thisl > maxf) maxf = thisl;
r = sscanf(de->d_name, "log%lld.tokulog", &thisl);
} }
if (r==1 && thisl>maxf) maxf=thisl;
} }
*result=maxf+1; *result=maxf+1;
int r = closedir(d); int r = closedir(d);
...@@ -562,9 +549,7 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp, int *n_lo ...@@ -562,9 +549,7 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp, int *n_lo
int dirnamelen = strlen(directory); int dirnamelen = strlen(directory);
while ((de=readdir(d))) { while ((de=readdir(d))) {
long long thisl; long long thisl;
if ( !(is_a_logfile(de->d_name)) ) continue; //#2424: Skip over files that don't match the exact logfile template if ( !(is_a_logfile(de->d_name, &thisl)) ) continue; //#2424: Skip over files that don't match the exact logfile template
int r = sscanf(de->d_name, "log%lld.tokulog", &thisl);
if (r!=1) continue; // Skip over non-log files.
if (n_results+1>=result_limit) { if (n_results+1>=result_limit) {
result_limit*=2; result_limit*=2;
result = toku_realloc(result, result_limit*sizeof(*result)); result = toku_realloc(result, result_limit*sizeof(*result));
......
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