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