From d6ac91038d0058fcc841f136ef7b5a68af1d81ab Mon Sep 17 00:00:00 2001 From: "yanfei.zyf" Date: Fri, 18 Sep 2015 10:35:43 +0800 Subject: [PATCH] DB-883 tokudb broken after 'create database log002015' [summary] In is_a_logfile_any_version, the uninitialized variable is terrible when we complied with -O3 flag, if we have a directory named 'log02015', 'n' is undefined value after sscanf Copyright (c) 2015, BohuTANG All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --- ft/logger/logger.cc | 11 +++- ft/tests/recovery-find-redo-logs.cc | 87 +++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 ft/tests/recovery-find-redo-logs.cc diff --git a/ft/logger/logger.cc b/ft/logger/logger.cc index eacec9cb8..1c47a1fdd 100644 --- a/ft/logger/logger.cc +++ b/ft/logger/logger.cc @@ -75,10 +75,10 @@ static void toku_print_bytes (FILE *outf, uint32_t len, char *data) { static bool is_a_logfile_any_version (const char *name, uint64_t *number_result, uint32_t *version_of_log) { bool rval = true; - uint64_t result; - int n; + uint64_t result = 0UL; + int n = 0; int r; - uint32_t version; + uint32_t version = 0; r = sscanf(name, "log%" SCNu64 ".tokulog%" SCNu32 "%n", &result, &version, &n); if (r!=2 || name[n]!='\0' || version <= TOKU_LOG_VERSION_1) { //Version 1 does NOT append 'version' to end of '.tokulog' @@ -644,6 +644,11 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp, int *n_lo while ((de=readdir(d))) { uint64_t thisl; uint32_t version_ignore; + + // if de is directory, skip it + if (de->d_type == DT_DIR) + continue; + if ( !(is_a_logfile_any_version(de->d_name, &thisl, &version_ignore)) ) continue; //#2424: Skip over files that don't match the exact logfile template if (n_results+1>=result_limit) { result_limit*=2; diff --git a/ft/tests/recovery-find-redo-logs.cc b/ft/tests/recovery-find-redo-logs.cc new file mode 100644 index 000000000..4efe12218 --- /dev/null +++ b/ft/tests/recovery-find-redo-logs.cc @@ -0,0 +1,87 @@ +/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: +#ident "$Id$" +/*====== +This file is part of PerconaFT. + + +Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. + + PerconaFT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2, + as published by the Free Software Foundation. + + PerconaFT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PerconaFT. If not, see . + +---------------------------------------- + + PerconaFT is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License, version 3, + as published by the Free Software Foundation. + + PerconaFT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with PerconaFT. If not, see . +======= */ + +#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." + +// Test that find redo-log files works correctly. + +#include "test.h" +#include + +static int +run_test(void) { + int r; + + // setup the test dir + toku_os_recursive_delete(TOKU_TEST_FILENAME); + r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU); + assert(r == 0); + + char testdir[TOKU_PATH_MAX+1]; + char testfile[TOKU_PATH_MAX+1]; + + toku_path_join(testdir, 2, TOKU_TEST_FILENAME, "log002015"); + r = toku_os_mkdir(testdir, S_IRWXU); + assert(r == 0); + + toku_path_join(testfile, 2, TOKU_TEST_FILENAME, "log002015.tokulog27"); + int fd = open(testfile, O_CREAT+O_WRONLY+O_TRUNC+O_EXCL+O_BINARY, S_IRWXU); + assert(fd != -1); + close(fd); + + char **logfiles = nullptr; + int n_logfiles = 0; + r = toku_logger_find_logfiles(TOKU_TEST_FILENAME, &logfiles, &n_logfiles); + CKERR(r); + assert(n_logfiles == 1); + fprintf(stderr, "redo log nums: %d \n", n_logfiles); + for (int i; i < n_logfiles; i++) { + fprintf(stderr, "redo log %s \n", logfiles[i]); + } + + toku_logger_free_logfiles(logfiles, n_logfiles); + + toku_os_recursive_delete(TOKU_TEST_FILENAME); + + return 0; +} + +int +test_main(int UU(argc), const char *UU(argv[])) { + int r; + r = run_test(); + return r; +}