├── COPYING.AGPLv3 ├── COPYING.GPLv2 ├── README.md ├── backup ├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── CTestConfig.cmake ├── CTestCustom.cmake ├── DartConfig.cmake ├── MurmurHash3.cc ├── MurmurHash3.h ├── backtrace.h ├── backup.cc ├── backup.h ├── backup_callbacks.cc ├── backup_callbacks.h ├── backup_community.cc ├── backup_debug.cc ├── backup_debug.h ├── backup_directory.cc ├── backup_directory.h ├── backup_helgrind.h ├── backup_internal.h ├── check.cc ├── check.h ├── copier.cc ├── copier.h ├── db-benchmark-test │ ├── CMakeLists.txt │ ├── backup1.cc │ ├── db-benchmark-test.cc │ ├── db-verify.cc │ ├── multi-bench.cc │ ├── ptquery.cc │ ├── scanrace.cc │ ├── scanscan.cc │ ├── tokudb_common_funcs.h │ ├── tracedelta.py │ └── txncommit.cc ├── description.cc ├── description.h ├── destination_file.cc ├── destination_file.h ├── directory_set.cc ├── directory_set.h ├── dirsum.cc ├── doc │ ├── Makefile │ ├── figures │ │ └── overview.pdf │ └── hotbackup.tex ├── drd.suppressions ├── export.map ├── file_hash_table.cc ├── file_hash_table.h ├── fmap.cc ├── fmap.h ├── glassbox.h ├── helgrind.suppressions ├── manager.cc ├── manager.h ├── manager_state.cc ├── manager_state.h ├── mutex.cc ├── mutex.h ├── raii-malloc.h ├── real_syscalls.cc ├── real_syscalls.h ├── remote │ ├── Makefile │ └── backup.proto ├── rwlock.cc ├── rwlock.h ├── scripts │ ├── gcovr │ ├── tokugrind │ └── tokuvalgrind ├── source_file.cc ├── source_file.h ├── tests │ ├── .gitattributes │ ├── CMakeLists.txt │ ├── abort_while_holding_lock.cc │ ├── backup_directory_tests.cc │ ├── backup_no_fractal_tree.cc │ ├── backup_no_fractal_tree_threaded.cc │ ├── backup_no_ft2.cc │ ├── backup_test_helpers.cc │ ├── backup_test_helpers.h │ ├── cannotopen_dest_dir.cc │ ├── capture_only_rename.cc │ ├── check_check.cc │ ├── check_check2.cc │ ├── closedirfails_dest_dir.cc │ ├── copy_files.cc │ ├── create_rename_race.cc │ ├── create_unlink_race.cc │ ├── debug_coverage.cc │ ├── dest_no_permissions_10.cc │ ├── dest_no_permissions_with_open_10.cc │ ├── disable_race.cc │ ├── empty_dest.cc │ ├── end_race_open_6668.cc │ ├── end_race_rename_6668.cc │ ├── end_race_rename_6668b.cc │ ├── exclude_all_files.cc │ ├── failed_rename_kills_backup_6703.cc │ ├── failed_unlink_kills_backup_6704.cc │ ├── file_descriptor_map_tests.cc │ ├── file_hash_table_tests.cc │ ├── ftruncate.cc │ ├── ftruncate_injection_6480.cc │ ├── lseek_write.cc │ ├── many_directories.cc │ ├── multiple_backups.cc │ ├── no_dest_dir_6317b.cc │ ├── nondir_dest_dir_6317.cc │ ├── notinsource_6570.cc │ ├── notinsource_6570b.cc │ ├── null_dest_dir_6317.cc │ ├── open_close_6731.cc │ ├── open_injection_6476.cc │ ├── open_lseek_write.cc │ ├── open_prepare_race_6610.cc │ ├── open_write_close.cc │ ├── open_write_race.cc │ ├── pwrite_during_backup.cc │ ├── range_locks.cc │ ├── read_and_seek.cc │ ├── readdirfails_dest_dir.cc │ ├── realpath_error_injection.cc │ ├── rename.cc │ ├── rename_injection.cc │ ├── source_no_permissions_10.cc │ ├── test1.cc │ ├── test6128.cc │ ├── test6361.cc │ ├── test6415_enospc_injection.cc │ ├── test6431_postcopy.cc │ ├── test6469_many_enospc_injection.cc │ ├── test6477_close_injection.cc │ ├── test6478_read_injection.cc │ ├── test6483_mkdir_injection.cc │ ├── test_dirsum.cc │ ├── throttle_6564.cc │ ├── two_renames_race.cc │ ├── unlink.cc │ ├── unlink_copy_race.cc │ ├── unlink_create_close_race_6727.cc │ ├── unlink_during_copy_test6515.cc │ ├── unlink_during_copy_test6515b.cc │ ├── unlink_during_copy_test6515c.cc │ ├── unlink_injection.cc │ └── write_race.cc ├── tsan.suppressions └── valgrind.suppressions ├── speedtest ├── .gitignore ├── Makefile ├── pmprof ├── speed_pwrite.c └── speed_write.c └── tests ├── README.test.create.backup ├── run.backup.bash └── run.test.create.bash /README.md: -------------------------------------------------------------------------------- 1 | Percona TokuBackup 2 | ====== 3 | 4 | Percona TokuBackup is a C library that allows users to make consistent 5 | copies of a directory of files, even while the respective files are 6 | being edited, removed, added, and/or renamed. 7 | 8 | This repository contains the library and associated unit and 9 | integration tests. 10 | 11 | Building 12 | -------- 13 | 14 | This library requires cmake 2.8.8 or greater to create a build 15 | environment on your target machine. To create this environment, from 16 | the top of the repository: 17 | 18 | ``` 19 | cd backup 20 | mkdir MAKEDIR 21 | cd MAKEDIR 22 | CC=gcc47 CXX=g++47 cmake .. 23 | ``` 24 | 25 | To build you then simply have to type: 26 | 27 | make 28 | 29 | Testing 30 | -------- 31 | 32 | To run a combined suite of unit tests and integration tests, run the 33 | following command after building: 34 | 35 | ctest 36 | 37 | This will show the progress of the tests and run valgrind memory and 38 | thread checks for each test. 39 | -------------------------------------------------------------------------------- /backup/.gitattributes: -------------------------------------------------------------------------------- 1 | * ident 2 | -------------------------------------------------------------------------------- /backup/.gitignore: -------------------------------------------------------------------------------- 1 | Debug 2 | GPATH 3 | GRTAGS 4 | GTAGS 5 | TAGS 6 | tags 7 | *~ 8 | -------------------------------------------------------------------------------- /backup/CTestConfig.cmake: -------------------------------------------------------------------------------- 1 | set(CTEST_PROJECT_NAME "backup-enterprise") 2 | set(CTEST_NIGHTLY_START_TIME "23:59:00 EDT") 3 | 4 | set(CTEST_DROP_METHOD "http") 5 | set(CTEST_DROP_SITE "localhost:8080") 6 | set(CTEST_DROP_LOCATION "/CDash/submit.php?project=backup-enterprise") 7 | set(CTEST_DROP_SITE_CDASH TRUE) 8 | -------------------------------------------------------------------------------- /backup/CTestCustom.cmake: -------------------------------------------------------------------------------- 1 | # Don't run memcheck on these functions 2 | foreach(test 3 | abort_while_holding_lock 4 | ) 5 | list(APPEND CTEST_CUSTOM_MEMCHECK_IGNORE 6 | ${test} 7 | helgrind/${test} 8 | drd/${test} 9 | ) 10 | endforeach(test) 11 | 12 | # Don't run helgrind and drd when we are running valgrind 13 | foreach(test 14 | abort_while_holding_lock 15 | backup_directory_tests 16 | backup_no_fractal_tree 17 | backup_no_fractal_tree_threaded 18 | backup_no_ft2 19 | cannotopen_dest_dir 20 | capture_only_rename 21 | check_check 22 | check_check2 23 | closedirfails_dest_dir 24 | copy_files 25 | create_rename_race 26 | create_unlink_race 27 | debug_coverage 28 | dest_no_permissions_10 29 | dest_no_permissions_with_open_10 30 | disable_race 31 | empty_dest 32 | end_race_open_6668 33 | end_race_rename_6668 34 | end_race_rename_6668b 35 | failed_rename_kills_backup_6703 36 | failed_unlink_kills_backup_6704 37 | file_hash_table_tests 38 | ftruncate 39 | ftruncate_injection_6480 40 | multiple_backups 41 | open_injection_6476 42 | open_close_6731 43 | open_prepare_race_6610 44 | open_write_close 45 | open_write_race 46 | no_dest_dir_6317b 47 | notinsource_6570 48 | notinsource_6570b 49 | null_dest_dir_6317 50 | nondir_dest_dir_6317 51 | readdirfails_dest_dir 52 | realpath_error_injection 53 | rename_injection 54 | range_locks 55 | read_and_seek 56 | rename 57 | source_no_permissions_10 58 | test6128 59 | test6361 60 | test6415_enospc_injection 61 | test6431_postcopy 62 | test6469_many_enospc_injection 63 | test6477_close_injection 64 | test6478_read_injection 65 | test6483_mkdir_injection 66 | test_dirsum 67 | throttle_6564 68 | two_renames_race 69 | unlink 70 | unlink_create_close_race_6727 71 | unlink_copy_race 72 | unlink_during_copy_test6515 73 | unlink_during_copy_test6515b 74 | unlink_during_copy_test6515c 75 | unlink_injection 76 | write_race 77 | ) 78 | list(APPEND CTEST_CUSTOM_MEMCHECK_IGNORE 79 | helgrind/${test} 80 | drd/${test} 81 | ) 82 | endforeach(test) 83 | -------------------------------------------------------------------------------- /backup/DartConfig.cmake: -------------------------------------------------------------------------------- 1 | if(BUILD_TESTING) 2 | if (NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) 3 | # Valgrind on OSX 10.8 generally works but outputs some warning junk 4 | # that is hard to parse out, so we'll just let it run alone 5 | set(MEMORYCHECK_COMMAND "${PROJECT_SOURCE_DIR}/scripts/tokuvalgrind") 6 | endif () 7 | set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --soname-synonyms=somalloc=*tokuportability* --gen-suppressions=no --quiet --num-callers=20 --leak-check=full --show-reachable=yes --trace-children=yes --trace-children-skip=sh,*/sh,basename,*/basename,dirname,*/dirname,rm,*/rm,cp,*/cp,mv,*/mv,cat,*/cat,diff,*/diff,grep,*/grep,date,*/date,test,*/tokudb_dump,*/tdb-recover --trace-children-skip-by-arg=--only_create,--test,--no-shutdown,novalgrind" CACHE INTERNAL "options for valgrind") 8 | set(MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/valgrind.suppressions" CACHE INTERNAL "suppressions file for valgrind") 9 | set(UPDATE_COMMAND "svn") 10 | endif() 11 | -------------------------------------------------------------------------------- /backup/MurmurHash3.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // MurmurHash3 was written by Austin Appleby, and is placed in the public 3 | // domain. The author hereby disclaims copyright to this source code. 4 | 5 | // The code comes from https://code.google.com/p/smhasher/wiki/MurmurHash3 6 | 7 | #ifndef _MURMURHASH3_H_ 8 | #define _MURMURHASH3_H_ 9 | 10 | //----------------------------------------------------------------------------- 11 | // Platform-specific functions and macros 12 | 13 | // Microsoft Visual Studio 14 | 15 | #if defined(_MSC_VER) 16 | 17 | typedef unsigned char uint8_t; 18 | typedef unsigned long uint32_t; 19 | typedef unsigned __int64 uint64_t; 20 | 21 | // Other compilers 22 | 23 | #else // defined(_MSC_VER) 24 | 25 | #include 26 | 27 | #endif // !defined(_MSC_VER) 28 | 29 | //----------------------------------------------------------------------------- 30 | 31 | #define MURMUR_64_ONLY 32 | 33 | #ifndef MURMUR_64_ONLY 34 | void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out ) throw(); 35 | 36 | void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out ) throw(); 37 | #endif 38 | 39 | void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out ) throw(); 40 | 41 | //----------------------------------------------------------------------------- 42 | 43 | #endif // _MURMURHASH3_H_ 44 | -------------------------------------------------------------------------------- /backup/backtrace.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | 4 | /*====== 5 | This file is part of Percona TokuBackup. 6 | 7 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 8 | 9 | Percona TokuBackup is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License, version 2, 11 | as published by the Free Software Foundation. 12 | 13 | Percona TokuBackup is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Percona TokuBackup. If not, see . 20 | 21 | ---------------------------------------- 22 | 23 | Percona TokuBackup is free software: you can redistribute it and/or modify 24 | it under the terms of the GNU Affero General Public License, version 3, 25 | as published by the Free Software Foundation. 26 | 27 | Percona TokuBackup is distributed in the hope that it will be useful, 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | GNU Affero General Public License for more details. 31 | 32 | You should have received a copy of the GNU Affero General Public License 33 | along with Percona TokuBackup. If not, see . 34 | ======= */ 35 | 36 | #ifndef BACKTRACE_H 37 | #define BACKTRACE_H 38 | 39 | #ident "$Id: 0841ae5ad9bca639aa4874138ad94ee919875bc7 $" 40 | 41 | class backtrace { 42 | public: 43 | const char *file; 44 | const int line; 45 | const char *fun; 46 | const backtrace *prev; 47 | backtrace(void): file(0), line(-1), fun(0), prev(0) {} 48 | backtrace(const char *fi, int l, const char *fu, const backtrace *p) throw() : file(fi), line(l), fun(fu), prev(p) {} 49 | }; 50 | 51 | #define BACKTRACE(bt) backtrace(__FILE__, __LINE__, __FUNCTION__, bt) 52 | #endif 53 | -------------------------------------------------------------------------------- /backup/backup_callbacks.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 1d431cea89a04f94a919a73681a5a7c85b597103 $" 36 | 37 | #include "backup_callbacks.h" 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | // 41 | backup_callbacks::backup_callbacks(backup_poll_fun_t poll_fun, 42 | void *poll_extra, 43 | backup_error_fun_t error_fun, 44 | void *error_extra, 45 | backup_exclude_copy_fun_t exclude_copy_fun, 46 | void *exclude_copy_extra, 47 | backup_throttle_fun_t throttle_fun, 48 | backup_before_stop_capt_fun_t bsc_fun, 49 | void *bsc_extra, 50 | backup_after_stop_capt_fun_t asc_fun, 51 | void *asc_extra 52 | ) throw() 53 | : m_poll_function(poll_fun), 54 | m_poll_extra(poll_extra), 55 | m_error_function(error_fun), 56 | m_error_extra(error_extra), 57 | m_exclude_copy_function(exclude_copy_fun), 58 | m_exclude_copy_extra(exclude_copy_extra), 59 | m_throttle_function(throttle_fun), 60 | m_bsc_fun(bsc_fun), 61 | m_bsc_extra(bsc_extra), 62 | m_asc_fun(asc_fun), 63 | m_asc_extra(asc_extra) 64 | {} 65 | 66 | ////////////////////////////////////////////////////////////////////////////// 67 | // 68 | int backup_callbacks::poll(float progress, const char *progress_string) throw() { 69 | int r = 0; 70 | r = m_poll_function(progress, progress_string, m_poll_extra); 71 | return r; 72 | } 73 | 74 | ////////////////////////////////////////////////////////////////////////////// 75 | // 76 | void backup_callbacks::report_error(int error_number, const char *error_str) throw() { 77 | m_error_function(error_number, error_str, m_error_extra); 78 | } 79 | 80 | ////////////////////////////////////////////////////////////////////////////// 81 | // 82 | unsigned long backup_callbacks::get_throttle(void) throw() { 83 | return m_throttle_function(); 84 | } 85 | 86 | int backup_callbacks::exclude_copy(const char *source) throw() { 87 | int r = 0; 88 | if (m_exclude_copy_function) 89 | r = m_exclude_copy_function(source, m_exclude_copy_extra); 90 | return r; 91 | } 92 | -------------------------------------------------------------------------------- /backup/backup_callbacks.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ifndef BACKUP_CALLBACKS_H 36 | #define BACKUP_CALLBACKS_H 37 | 38 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 39 | #ident "$Id: bb132818c9eeb27193b5e8a0fdf74d1333c079bf $" 40 | 41 | #include "backup_internal.h" 42 | 43 | typedef unsigned long (*backup_throttle_fun_t)(void); 44 | 45 | ////////////////////////////////////////////////////////////////////////////// 46 | // 47 | class backup_callbacks 48 | { 49 | public: 50 | backup_callbacks(backup_poll_fun_t poll_fun, 51 | void *poll_extra, 52 | backup_error_fun_t error_fun, 53 | void *error_extra, 54 | backup_exclude_copy_fun_t exclude_copy_fun, 55 | void *exclude_copy_extra, 56 | backup_throttle_fun_t throttle_fun, 57 | backup_before_stop_capt_fun_t bsc_fun = nullptr, 58 | void *bsc_extra = nullptr, 59 | backup_after_stop_capt_fun_t asc_fun = nullptr, 60 | void *asc_extra = nullptr) throw(); 61 | int poll(float progress, const char *progress_string) throw(); 62 | void report_error(int error_number, const char *error_description) throw(); 63 | unsigned long get_throttle(void) throw(); 64 | int exclude_copy(const char *source) throw(); 65 | void before_stop_capt_call() throw() { 66 | if (m_bsc_fun) 67 | m_bsc_fun(m_bsc_extra); 68 | } 69 | void after_stop_capt_call() throw() { 70 | if (m_asc_fun) 71 | m_asc_fun(m_asc_extra); 72 | } 73 | private: 74 | backup_callbacks() throw() {}; 75 | backup_poll_fun_t m_poll_function; 76 | void *m_poll_extra; 77 | backup_error_fun_t m_error_function; 78 | void *m_error_extra; 79 | backup_exclude_copy_fun_t m_exclude_copy_function; 80 | void *m_exclude_copy_extra; 81 | backup_throttle_fun_t m_throttle_function; 82 | backup_before_stop_capt_fun_t m_bsc_fun; 83 | void *m_bsc_extra; 84 | backup_after_stop_capt_fun_t m_asc_fun; 85 | void *m_asc_extra; 86 | }; 87 | 88 | #endif // end of header guardian. 89 | -------------------------------------------------------------------------------- /backup/backup_community.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: b821b2e88010cd34ce04fea3c2618fd126415d1b $" 36 | 37 | #include "backup.h" 38 | #include 39 | #include 40 | 41 | extern "C" int tokubackup_create_backup(const char *source_dirs[] __attribute__((unused)), 42 | const char *dest_dirs[] __attribute__((unused)), 43 | int dir_count __attribute__((unused)), 44 | backup_poll_fun_t poll_fun __attribute__((unused)), 45 | void *poll_extra __attribute__((unused)), 46 | backup_error_fun_t error_fun, 47 | void *error_extra) { 48 | error_fun(ENOSYS, "Sorry, backup is not implemented", error_extra); 49 | return ENOSYS; 50 | } 51 | 52 | extern "C" void tokubackup_throttle_backup(unsigned long bytes_per_second __attribute__((unused))) { 53 | fprintf(stderr, "Sorry, backup is not implemented\n"); 54 | } 55 | 56 | const char tokubackup_sql_suffix[] = ""; 57 | -------------------------------------------------------------------------------- /backup/backup_debug.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ifndef BACKUP_DEBUG_H 36 | #define BACKUP_DEBUG_H 37 | 38 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 39 | #ident "$Id: a57f2373b75a9341dc41c4623ecef3b4a1447810 $" 40 | 41 | #ifndef DEBUG_HOTBACKUP 42 | #define DEBUG_HOTBACKUP 0 43 | #endif 44 | 45 | #ifndef PAUSE_POINTS_ON 46 | #define PAUSE_POINTS_ON 1 47 | #endif 48 | 49 | namespace HotBackup { 50 | 51 | // Debug flag for backup_copier debugging. 52 | const int CPY_DBG = 0; 53 | // Debug flag just for the backup manager. 54 | const int MGR_DBG = 0; 55 | // Debug flag for the file descriptor map. 56 | const int MAP_DBG = 0; 57 | 58 | // Components: 59 | // COPY 60 | const int COPY_FLAG = 0x01; 61 | // CAPTURE 62 | const int CAPUTRE_FLAG = 0x02; 63 | // INTERPOSE 64 | const int INTERPOSE_FLAG = 0x04; 65 | 66 | void CopyTrace(const char *s, const char *arg) throw(); 67 | void CopyWarn(const char *s, const char *arg) throw(); 68 | void CopyError(const char *s, const char *arg) throw(); 69 | void CaptureTrace(const char *s, const char *arg) throw(); 70 | void CaptureTrace(const char *s, const int arg) throw(); 71 | void CaptureWarn(const char *s, const char *arg) throw(); 72 | void CaptureError(const char *s, const char *arg) throw(); 73 | void CaptureError(const char *s, const int arg) throw(); 74 | void InterposeTrace(const char *s, const char *arg) throw(); 75 | void InterposeTrace(const char *s, const int arg) throw(); 76 | void InterposeWarn(const char *s, const char *arg) throw(); 77 | void InterposeError(const char *s, const char *arg) throw(); 78 | 79 | // Pause Points: 80 | // 81 | // Pause Point Flags: 82 | // 83 | const int COPIER_BEFORE_READ = 0x01; 84 | const int COPIER_AFTER_READ_BEFORE_WRITE = 0x02; 85 | const int COPIER_AFTER_WRITE = 0x04; 86 | const int MANAGER_IN_PREPARE = 0x08; 87 | const int MANAGER_IN_DISABLE = 0x10; 88 | const int COPIER_AFTER_OPEN_SOURCE = 0x20; 89 | const int OPEN_DESTINATION_FILE = 0x40; 90 | const int CAPTURE_OPEN = 0x80; 91 | 92 | bool should_pause(int) throw(); 93 | void toggle_pause_point(int) throw(); 94 | 95 | } // End of namespace. 96 | 97 | 98 | 99 | #endif // End of header guardian. 100 | -------------------------------------------------------------------------------- /backup/backup_directory.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ifndef BACKUP_DIRECTORY_H 36 | #define BACKUP_DIRECTORY_H 37 | 38 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 39 | #ident "$Id: 089f73ea991be2208c25828917a97e42f789b75c $" 40 | 41 | #include "description.h" 42 | #include "fmap.h" 43 | #include "copier.h" 44 | #include "backup_callbacks.h" 45 | #include "directory_set.h" 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | ////////////////////////////////////////////////////////////////////////////// 52 | // 53 | class backup_session 54 | { 55 | public: 56 | backup_session(directory_set *dirs, backup_callbacks *call, file_hash_table * const table) throw(); // returns a nonzero in *errnum if an error callback has occured. 57 | ~backup_session() throw(); 58 | int do_copy() throw() __attribute__((warn_unused_result)); // returns the error code (not in errno) 59 | int directories_set(backup_callbacks*) throw(); 60 | bool is_prefix(const char *file) throw(); 61 | bool is_prefix_of_realpath(const char *absfile) throw(); 62 | 63 | char* translate_prefix(const char *file) throw(); 64 | // Effect: Returns a malloc'd string which is the realpath of the filename translated from source directory to destination. 65 | 66 | char* translate_prefix_of_realpath(const char *absfile) throw(); 67 | // Effect: Like translate_prefix, but requires that absfile is already the realpath of the file name. 68 | 69 | // Capture interface. 70 | int capture_open(const char *file, char **result) throw() __attribute__((warn_unused_result)); // if any errors occur, report them, and return the error code. Otherwise return 0 and store the malloc'd name of the dest file in *result. If the file isn't in the destspace return 0 and set *result=NULL. 71 | int capture_mkdir(const char *pathname) throw() __attribute__((warn_unused_result)); // return 0 on success, error otherwise. 72 | void add_to_copy_todo_list(const char *file_path) throw(); 73 | void cleanup(void) throw(); 74 | bool file_is_excluded(const char *) throw(); 75 | private: 76 | const directory_set * const m_dirs; 77 | copier m_copier; 78 | }; 79 | 80 | #endif // End of header guardian. 81 | -------------------------------------------------------------------------------- /backup/backup_helgrind.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 35 | 36 | #ifndef BACKUP_HELGRIND_H 37 | #define BACKUP_HELGRIND_H 38 | 39 | #if defined(BACKUP_USE_VALGRIND) 40 | #include 41 | #define TOKUBACKUP_VALGRIND_HG_DISABLE_CHECKING(x, y) VALGRIND_HG_DISABLE_CHECKING(x, y) 42 | #define TOKUBACKUP_VALGRIND_HG_ENABLE_CHECKING(x, y) VALGRIND_HG_ENABLE_CHECKING(x, y) 43 | #else 44 | #define TOKUBACKUP_VALGRIND_HG_DISABLE_CHECKING(x, y) ((void) x, (void) y) 45 | #define TOKUBACKUP_VALGRIND_HG_ENABLE_CHECKING(x, y) ((void) x, (void) y) 46 | #endif 47 | 48 | #endif /* BACKUP_HELGPIND_H */ 49 | -------------------------------------------------------------------------------- /backup/check.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: 06a9fed9f09e8fd1c32c645e22318e3883e797ce $" 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "check.h" 40 | #include "manager.h" 41 | 42 | void check_fun(long predicate, const char *expr, const backtrace bt) throw() { 43 | if (!predicate) { 44 | the_manager.kill(); 45 | int e = errno; 46 | fprintf(stderr, "check(%s) failed\n", expr); 47 | fprintf(stderr, "errno=%d\n", e); 48 | const backtrace *btp=&bt; 49 | fprintf(stderr, "backtrace:\n"); 50 | while (btp) { 51 | fprintf(stderr, " %s:%d (%s)\n", btp->file, btp->line, btp->fun); 52 | btp = btp->prev; 53 | } 54 | abort(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /backup/check.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ifndef CHECK_H 36 | #define CHECK_H 37 | 38 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 39 | #ident "$Id: 4e023f249d14bb47ac3bc2ae09fa8828329bd5c6 $" 40 | 41 | #include "backtrace.h" 42 | 43 | void check_fun(long predicate, const char *expr, const backtrace bt) throw(); 44 | 45 | // Like assert, except it doesn't go away under NDEBUG. 46 | // Do this with a function so that we don't get false answers on branch coverage. 47 | #define check(x) check_fun((long)(x), #x, BACKTRACE(NULL)) 48 | #define check_bt(x, bt) check_fun((long)(x), #x, BACKTRACE(&bt)) 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /backup/db-benchmark-test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package( Threads ) 2 | 3 | set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE DONT_DEPRECATE_ERRNO) 4 | 5 | set(all_bins 6 | db-benchmark-test 7 | backup1 8 | # scanscan 9 | # ptquery 10 | # txncommit 11 | # scanrace 12 | # multi-bench 13 | # db-verify 14 | ) 15 | 16 | include_directories("${PROJECT_SOURCE_DIR}/../tokudb/toku_include" "${PROJECT_SOURCE_DIR}/../tokudb/release/include" "${PROJECT_SOURCE_DIR}/../tokudb/portability" "${PROJECT_SOURCE_DIR}/../backup") 17 | find_library(LIBTOKUPORTABILITY NAMES tokuportability PATHS "${PROJECT_SOURCE_DIR}/../tokudb/release/lib/") 18 | find_library(LIBTOKUDB NAMES tokudb PATHS "${PROJECT_SOURCE_DIR}/../tokudb/release/lib/") 19 | foreach(tokudb_bin ${all_bins}) 20 | add_executable(${tokudb_bin} ${tokudb_bin}) 21 | target_link_libraries(${tokudb_bin} ${LIBTOKUDB} ${LIBTOKUPORTABILITY} HotBackup ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 22 | add_test(${tokudb_bin} ${tokudb_bin} 1) 23 | endforeach(tokudb_bin) 24 | -------------------------------------------------------------------------------- /backup/db-benchmark-test/db-verify.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | #ident "$Id: 2ec3a29438ed7ad0594fdee75534014ecb1885e1 $" 4 | #ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved." 5 | #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." 6 | #include 7 | #include 8 | #include 9 | #include "tokudb_common_funcs.h" 10 | #include 11 | 12 | static int verbose = 0; 13 | static int env_open_flags_yesx = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOG|DB_INIT_LOCK; 14 | static int env_open_flags_nox = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL; 15 | 16 | int test_main(int argc, char * const argv[]) { 17 | int r; 18 | const char *envdir = "bench.tokudb"; 19 | const char *dbfilename = "bench.db"; 20 | bool do_txns = false; 21 | 22 | for (int i = 1; i < argc; i++) { 23 | if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) { 24 | verbose++; 25 | continue; 26 | } 27 | if (strcmp(argv[i], "-q") == 0) { 28 | if (verbose > 0) 29 | verbose--; 30 | continue; 31 | } 32 | if (strcmp(argv[i], "-x") == 0) { 33 | do_txns = true; 34 | continue; 35 | } 36 | } 37 | 38 | DB_ENV *env = NULL; 39 | r = db_env_create(&env, 0); 40 | assert(r == 0); 41 | 42 | r = env->open(env, envdir, do_txns ? env_open_flags_yesx : env_open_flags_nox, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); 43 | assert(r == 0); 44 | 45 | DB *db = NULL; 46 | r = db_create(&db, env, 0); 47 | assert(r == 0); 48 | 49 | r = db->open(db, NULL, dbfilename, NULL, DB_BTREE, DB_AUTO_COMMIT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); 50 | assert(r == 0); 51 | 52 | if (verbose) { 53 | DB_BTREE_STAT64 s; 54 | r = db->stat64(db, NULL, &s); assert(r == 0); 55 | printf("nkeys=%" PRIu64 " dsize=%" PRIu64 "\n", s.bt_nkeys, s.bt_dsize); 56 | } 57 | 58 | r = db->verify_with_progress(db, NULL, NULL, verbose > 0, false); 59 | assert(r == 0); 60 | 61 | r = db->close(db, 0); 62 | assert(r == 0); 63 | 64 | r = env->close(env, 0); 65 | assert(r == 0); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /backup/db-benchmark-test/tokudb_common_funcs.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | #ident "$Id: 04d93f6b18462c9d923f7e5212fc4c370d41f1b2 $" 4 | #if !defined(TOKUDB_COMMON_FUNCS_H) 5 | #define TOKUDB_COMMON_FUNCS_H 6 | 7 | #ident "Copyright (c) 2007 Tokutek Inc. All rights reserved." 8 | 9 | 10 | #include 11 | #include 12 | #if defined(TOKUDB) && TOKU_WINDOWS 13 | #include 14 | #endif 15 | static int test_main (int argc, char *const argv[]); 16 | int 17 | main(int argc, char *const argv[]) { 18 | int r; 19 | #if defined(TOKUDB) && TOKU_WINDOWS 20 | toku_ydb_init(); 21 | #endif 22 | #if !defined(TOKUDB) && DB_VERSION_MINOR==4 && DB_VERSION_MINOR == 7 23 | r = db_env_set_func_malloc(toku_malloc); assert(r==0); 24 | r = db_env_set_func_free(toku_free); assert(r==0); 25 | r = db_env_set_func_realloc(toku_realloc); assert(r==0); 26 | #endif 27 | r = test_main(argc, argv); 28 | #if defined(TOKUDB) && TOKU_WINDOWS 29 | toku_ydb_destroy(); 30 | #endif 31 | return r; 32 | } 33 | 34 | static __attribute__((__unused__)) void 35 | print_engine_status(DB_ENV * UU(env)) { 36 | #if defined(TOKUDB) 37 | int buffsize = 1024 * 128; 38 | char buff[buffsize]; 39 | env->get_engine_status_text(env, buff, buffsize); 40 | printf("Engine status:\n"); 41 | printf("%s", buff); 42 | #endif 43 | } 44 | 45 | 46 | #endif /* #if !defined(TOKUDB_COMMON_H) */ 47 | 48 | -------------------------------------------------------------------------------- /backup/db-benchmark-test/tracedelta.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def main(): 4 | ts = None 5 | while 1: 6 | b = sys.stdin.readline() 7 | if b == "": break 8 | f = b.split() 9 | if len(f) != 2: continue 10 | newts = int(f[0]) 11 | event = f[1] 12 | if ts is None: 13 | ts = int(f[0]) 14 | else: 15 | print "%8d %s" % (newts - ts, event) 16 | ts = newts 17 | return 0 18 | sys.exit(main()) 19 | -------------------------------------------------------------------------------- /backup/db-benchmark-test/txncommit.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | #ident "$Id: 680151cec1bb7da9f888325de7ef8cff60bae612 $" 4 | #ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved." 5 | #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." 6 | // run txn begin commit on multiple threads and measure the throughput 7 | 8 | #include "toku_portability.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "db.h" 15 | #include "toku_pthread.h" 16 | 17 | static double now(void) { 18 | struct timeval tv; 19 | int r = gettimeofday(&tv, NULL); assert(r == 0); 20 | return tv.tv_sec * 1000000.0 + tv.tv_usec; 21 | } 22 | 23 | static void test_txn(DB_ENV *env, uint32_t ntxns, long usleep_time) { 24 | int r; 25 | for (uint32_t i = 0; i < ntxns; i++) { 26 | DB_TXN *txn = NULL; 27 | r = env->txn_begin(env, NULL, &txn, DB_TXN_SNAPSHOT); assert(r == 0); 28 | r = txn->commit(txn, 0); assert(r == 0); 29 | if (usleep_time) 30 | usleep(usleep_time); 31 | else 32 | sched_yield(); 33 | } 34 | } 35 | 36 | struct arg { 37 | DB_ENV *env; 38 | uint32_t ntxns; 39 | long usleep_time; 40 | }; 41 | 42 | static void *test_thread(void *arg) { 43 | struct arg *myarg = (struct arg *) arg; 44 | test_txn(myarg->env, myarg->ntxns, myarg->usleep_time); 45 | return arg; 46 | } 47 | 48 | int main(int argc, char * const argv[]) { 49 | uint32_t ntxns = 1000000; 50 | uint32_t nthreads = 1; 51 | long usleep_time = 0; 52 | 53 | for (int i = 1; i < argc; i++) { 54 | char * const arg = argv[i]; 55 | if (strcmp(arg, "--ntxns") == 0 && i+1 < argc) { 56 | ntxns = atoll(argv[++i]); 57 | continue; 58 | } 59 | if (strcmp(arg, "--nthreads") == 0 && i+1 < argc) { 60 | nthreads = atoll(argv[++i]); 61 | continue; 62 | } 63 | if (strcmp(arg, "--usleep") == 0 && i+1 < argc) { 64 | usleep_time = atol(argv[++i]); 65 | continue; 66 | } 67 | return 1; 68 | } 69 | 70 | int r; 71 | 72 | char cmd[256]; 73 | sprintf(cmd, "rm -rf %s", ENVDIR); 74 | r = system(cmd); assert(r == 0); 75 | r = toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO); assert(r == 0); 76 | 77 | DB_ENV *env = NULL; 78 | r = db_env_create(&env, 0); assert(r == 0); 79 | r = env->set_cachesize(env, 4, 0, 1); assert(r == 0); 80 | r = env->open(env, ENVDIR, DB_PRIVATE + DB_THREAD + DB_CREATE + DB_INIT_TXN + DB_INIT_LOG + DB_INIT_MPOOL + DB_RECOVER, 0); assert(r == 0); 81 | 82 | double tstart = now(); 83 | assert(nthreads > 0); 84 | struct arg myargs[nthreads-1]; 85 | toku_pthread_t mytids[nthreads]; 86 | for (uint32_t i = 0; i < nthreads-1; i++) { 87 | myargs[i] = (struct arg) { env, ntxns, usleep_time}; 88 | r = toku_pthread_create(&mytids[i], NULL, test_thread, &myargs[i]); assert(r == 0); 89 | } 90 | test_txn(env, ntxns, usleep_time); 91 | for (uint32_t i = 0; i < nthreads-1; i++) { 92 | void *ret; 93 | r = toku_pthread_join(mytids[i], &ret); assert(r == 0); 94 | } 95 | double tend = now(); 96 | double t = tend-tstart; 97 | double n = ntxns * nthreads; 98 | printf("%f %f %f\n", n, t, (n/t)*1000000.0); 99 | r = env->close(env, 0); assert(r == 0); 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /backup/description.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 312cc2498bde5f45393e4397429cd006164d8323 $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "backup_debug.h" 45 | #include "check.h" 46 | #include "manager.h" 47 | #include "mutex.h" 48 | #include "description.h" 49 | #include "real_syscalls.h" 50 | #include "source_file.h" 51 | 52 | /////////////////////////////////////////////////////////////////////////////// 53 | // 54 | description::description() throw() 55 | : m_offset(0), 56 | m_source_file(NULL) 57 | { 58 | int r = pthread_mutex_init(&m_mutex, NULL); 59 | check(r==0); 60 | } 61 | 62 | /////////////////////////////////////////////////////////////////////////////// 63 | // 64 | description::~description(void) throw() 65 | { 66 | int r = pthread_mutex_destroy(&m_mutex); 67 | check(r==0); 68 | } 69 | 70 | 71 | /////////////////////////////////////////////////////////////////////////////// 72 | // 73 | void description::set_source_file(source_file *file) throw() { 74 | m_source_file = file; 75 | } 76 | 77 | /////////////////////////////////////////////////////////////////////////////// 78 | // 79 | source_file * description::get_source_file(void) const throw() 80 | { 81 | return m_source_file; 82 | } 83 | 84 | /////////////////////////////////////////////////////////////////////////////// 85 | // 86 | void description::lock(const backtrace bt) throw() { 87 | pmutex_lock(&m_mutex, BACKTRACE(&bt)); 88 | } 89 | 90 | /////////////////////////////////////////////////////////////////////////////// 91 | // 92 | void description::unlock(const backtrace bt) throw() { 93 | pmutex_unlock(&m_mutex, BACKTRACE(&bt)); 94 | } 95 | 96 | /////////////////////////////////////////////////////////////////////////////// 97 | // 98 | void description::increment_offset(ssize_t nbyte) throw() { 99 | m_offset += nbyte; 100 | } 101 | 102 | /////////////////////////////////////////////////////////////////////////////// 103 | // 104 | off_t description::get_offset(void) throw() { 105 | return m_offset; 106 | } 107 | 108 | /////////////////////////////////////////////////////////////////////////////// 109 | // 110 | void description::lseek(off_t new_offset) throw() { 111 | m_offset = new_offset; 112 | } 113 | -------------------------------------------------------------------------------- /backup/description.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ifndef DESCRIPTION_H 36 | #define DESCRIPTION_H 37 | 38 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 39 | #ident "$Id: 46339984e0e13b67c18679f44f4686ff83a0a397 $" 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #include "backtrace.h" 46 | 47 | class source_file; 48 | 49 | class description { 50 | private: 51 | off_t m_offset; // The offset that is moved by read(), write() and lseek(). 52 | source_file *m_source_file; 53 | pthread_mutex_t m_mutex; // A mutex used to make m_offset move atomically when we perform a write (or read). 54 | 55 | public: 56 | description() throw(); 57 | ~description(void) throw(); 58 | int init(void) throw() __attribute__((warn_unused_result)); 59 | // Effect: Initialize a description. (Note that the constructor isn't allowed to do anything meaningful, since error handling is tricky. 60 | // Return 0 on success, otherwise inform the backup manager of the error (fatal_error or backup_error) and return the error code. 61 | void set_source_file(source_file *file) throw(); 62 | source_file * get_source_file(void) const throw(); 63 | void lock(const backtrace bt) throw(); 64 | void unlock(const backtrace bt) throw(); 65 | 66 | void lseek(off_t new_offset) throw(); 67 | void increment_offset(ssize_t nbyte) throw(); 68 | off_t get_offset(void) throw(); // return the current offset. 69 | }; 70 | 71 | #endif // end of header guardian. 72 | -------------------------------------------------------------------------------- /backup/destination_file.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 35 | #ident "$Id: 34a6fc1026c9c6f38f61ad3b565b50963a6a34bf $" 36 | 37 | #ifndef DESTINATION_FILE_H 38 | #define DESTINATION_FILE_H 39 | 40 | #include 41 | 42 | class destination_file { 43 | public: 44 | destination_file(const int opened_fd, const char * full_path) throw(); 45 | ~destination_file() throw(); 46 | int close(void) const throw(); 47 | int pwrite(const void *buf, size_t nbyte, off_t offset) const throw(); 48 | int truncate(off_t length) const throw(); 49 | int unlink(void) const throw(); 50 | int rename(const char *new_path) throw(); 51 | int get_fd(void) const throw(); 52 | const char * get_path(void) const throw(); 53 | private: 54 | const int m_fd; 55 | const char * m_path; 56 | }; 57 | 58 | #endif // End of header guardian. 59 | -------------------------------------------------------------------------------- /backup/directory_set.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ifndef DIRECTORY_SET_H 36 | #define DIRECTORY_SET_H 37 | 38 | #include 39 | 40 | class directory_set { 41 | public: 42 | //---------------------------------------------------------- 43 | // Allocates memory for storing given directories. 44 | directory_set(const int count, 45 | const char **sources, 46 | const char **destinations); 47 | 48 | //---------------------------------------------------------- 49 | // De-allocates memory allocated in constructor and realpath() 50 | // calls. 51 | ~directory_set(); 52 | 53 | //---------------------------------------------------------- 54 | // Creates realpath() versions of currently set directory 55 | // paths. Returns an error if realpath() fails. 56 | int update_to_full_path(void); 57 | 58 | //---------------------------------------------------------- 59 | // Returns an error if any of the following criteria are NOT 60 | // met: 61 | int validate(void) const; 62 | 63 | //---------------------------------------------------------- 64 | // Returns index of matching source dir, or -1 if given file 65 | // not in directory set. 66 | int find_index_matching_prefix(const char *file) const; 67 | 68 | //---------------------------------------------------------- 69 | // Accessors for number of, source, and destination 70 | // directories. 71 | const char *source_directory_at(const int index) const; 72 | const char *destination_directory_at(const int index) const; 73 | int number_of_directories() const; 74 | 75 | private: 76 | const char **m_sources; 77 | const char **m_destinations; 78 | const int m_count; 79 | bool m_real_path_successful; 80 | directory_set(); 81 | int verify_destination_is_empty(const int index, DIR *dir) const; 82 | void handle_realpath_results(const int r, const int allocated_pairs); 83 | int update_to_real_path_on_index(const int i); 84 | int verify_no_two_directories_are_the_same(void); 85 | }; 86 | 87 | #endif // End of header guardian. 88 | -------------------------------------------------------------------------------- /backup/dirsum.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: cee1b3b244f8c03ae0b101342afcb98bef36c2a6 $" 36 | 37 | // Walk a directory and return the total size. 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "raii-malloc.h" 45 | #include "backup_internal.h" 46 | #include "check.h" 47 | 48 | long long dirsum(const char *dname) throw() { 49 | DIR *dir = opendir(dname); 50 | if (dir==0) return 0; 51 | long long sum = 0; 52 | while (1) { 53 | struct dirent *dent = readdir(dir); 54 | if (dent==0) break; 55 | if (!strcmp(dent->d_name, "." )) continue; 56 | if (!strcmp(dent->d_name, "..")) continue; 57 | int len = strlen(dname) + 1 + strlen(dent->d_name) + 1; // one for the slash, one for the NUL. 58 | with_object_to_free str((char*)malloc(len)); 59 | { 60 | int r = snprintf(str.value, len, "%s/%s", dname, dent->d_name); 61 | check(r==len-1); 62 | } 63 | struct stat st; 64 | int r = lstat(str.value, &st); 65 | if (r == -1) continue; 66 | if (S_ISLNK(st.st_mode)) continue; 67 | if (S_ISDIR(st.st_mode)) { 68 | long long sub_dirsum = dirsum(str.value); 69 | sum += sub_dirsum; 70 | continue; 71 | } 72 | sum += st.st_size; 73 | } 74 | closedir(dir); 75 | return sum; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /backup/doc/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: FORCE_MAKE 2 | all: hotbackup.pdf 3 | master-preamble.isy: master-ipe.tex 4 | ipescript update-master master-ipe.tex figures/*.pdf 5 | %.pdf : %.tex master-preamble.isy FORCE_MAKE 6 | latexmk -pdf -dvi- -ps- $< 7 | -------------------------------------------------------------------------------- /backup/doc/figures/overview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/percona/Percona-TokuBackup/032ea2119b3d026ff9214d499c110b280fab64ad/backup/doc/figures/overview.pdf -------------------------------------------------------------------------------- /backup/drd.suppressions: -------------------------------------------------------------------------------- 1 | { 2 | 3 | drd:ConflictingAccess 4 | obj:/usr/lib64/libpthread-2.15.so 5 | } 6 | { 7 | 8 | drd:ConflictingAccess 9 | obj:/lib64/libpthread-2.5.so 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /backup/export.map: -------------------------------------------------------------------------------- 1 | { 2 | global: 3 | close; 4 | ftruncate64; ftruncate; 5 | lseek64; lseek; 6 | mkdir; 7 | open64; open; 8 | pwrite64; pwrite; 9 | read; 10 | rename; 11 | realpath; 12 | tokubackup_create_backup; 13 | tokubackup_sql_suffix; 14 | tokubackup_throttle_backup; 15 | tokubackup_version_string; 16 | truncate64; truncate; 17 | unlink; 18 | write; 19 | local: *; 20 | }; 21 | -------------------------------------------------------------------------------- /backup/fmap.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | #ifndef FMAP_H 35 | #define FMAP_H 36 | 37 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 38 | #ident "$Id: 4cfd6d0a8d114507a411c471c23f8e3612e6fae3 $" 39 | 40 | 41 | #include 42 | #include "description.h" 43 | #include "backup_directory.h" 44 | #include "backtrace.h" 45 | 46 | class backup_directory; 47 | 48 | extern template class std::vector; 49 | 50 | class fmap 51 | { 52 | private: 53 | std::vector m_map; 54 | public: 55 | fmap() throw(); 56 | ~fmap() throw(); 57 | 58 | void get(int fd, description**result, const backtrace bt) throw(); 59 | // Effect: Returns pointer (in *result) to the file description object that matches the 60 | // given file descriptor. This will return NULL if the given file 61 | // descriptor has not been added to this map. 62 | // No errors can occur. 63 | 64 | void put(int fd, description *file) throw(); 65 | // Effect: adds given description pointer to array (acquires a lock) 66 | 67 | description* get_unlocked(int fd) throw(); // use this one instead of get() when you already have the lock. 68 | int erase(int fd, const backtrace bt) throw() __attribute__((warn_unused_result)); // returns 0 or an error number. 69 | int size(void) throw(); 70 | private: 71 | void grow_array(int fd) throw(); 72 | 73 | // Global locks used when the file descriptor map is updated. Sometimes the backup system needs to hold the lock for several operations. 74 | // No errors are countenanced. 75 | static void lock_fmap(backtrace bt) throw(); 76 | static void unlock_fmap(backtrace bt) throw(); 77 | friend class with_fmap_locked; 78 | 79 | friend class fmap_unit_test; 80 | 81 | }; 82 | 83 | 84 | class with_fmap_locked { 85 | private: 86 | const backtrace m_bt; 87 | public: 88 | with_fmap_locked(backtrace bt): m_bt(bt) { 89 | fmap::lock_fmap(m_bt); 90 | } 91 | ~with_fmap_locked(void) { 92 | fmap::unlock_fmap(m_bt); 93 | } 94 | }; 95 | 96 | 97 | #endif // End of header guardian. 98 | -------------------------------------------------------------------------------- /backup/glassbox.h: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | #ifndef GLASSBOX_H 33 | #define GLASSBOX_H 34 | 35 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 36 | #ident "$Id: 587893d6b250017823dcbd5859c5ba262cf506eb $" 37 | 38 | #ifdef GLASSBOX 39 | #include 40 | #define HAS_GLASSBOX 1 41 | #define WHEN_GLASSBOX(x) x 42 | #define glass_assert(x) assert(x) 43 | #else 44 | #define HAS_GLASSBOX 0 45 | #define WHEN_GLASSBOX(x) ((void)0) 46 | #define glass_assert(x) ignore(x) 47 | #endif 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /backup/helgrind.suppressions: -------------------------------------------------------------------------------- 1 | { 2 | this_supression_should_go_away_when_helgrind_fixes_the_problem 3 | Helgrind:Misc 4 | fun:pthread_cond_destroy_WRK 5 | fun:pthread_cond_destroy@* 6 | } 7 | -------------------------------------------------------------------------------- /backup/manager_state.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 0ec40adf0987c31bf97c3757f1fec9f064083f19 $" 36 | 37 | #include 38 | 39 | #include "backup_helgrind.h" 40 | 41 | #include "manager_state.h" 42 | 43 | manager_state::manager_state() throw() 44 | : m_is_dead(false), 45 | m_capture_enabled(false), 46 | m_copy_enabled(false) 47 | { 48 | TOKUBACKUP_VALGRIND_HG_DISABLE_CHECKING(&m_is_dead, sizeof(m_is_dead)); 49 | TOKUBACKUP_VALGRIND_HG_DISABLE_CHECKING(&m_capture_enabled, sizeof(m_capture_enabled)); 50 | TOKUBACKUP_VALGRIND_HG_DISABLE_CHECKING(&m_copy_enabled, sizeof(m_copy_enabled)); 51 | } 52 | 53 | bool manager_state::is_dead(void) throw() { 54 | return m_is_dead; 55 | } 56 | 57 | bool manager_state::is_alive(void) throw() { 58 | return !m_is_dead; 59 | } 60 | 61 | void manager_state::kill(void) throw() { 62 | m_is_dead = true; 63 | } 64 | 65 | bool manager_state::capture_is_enabled(void) throw() { 66 | return m_capture_enabled; 67 | } 68 | 69 | void manager_state::enable_capture(void) throw() { 70 | m_capture_enabled = true; 71 | } 72 | 73 | void manager_state::disable_capture(void) throw() { 74 | m_capture_enabled = false; 75 | } 76 | 77 | bool manager_state::copy_is_enabled(void) throw() { 78 | return m_copy_enabled; 79 | } 80 | 81 | void manager_state::enable_copy(void) throw() { 82 | m_copy_enabled = true; 83 | } 84 | 85 | void manager_state::disable_copy(void) throw() { 86 | m_copy_enabled = false; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /backup/manager_state.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | #ifndef MANAGER_STATE_H 35 | #define MANAGER_STATE_H 36 | 37 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 38 | #ident "$Id: 360b61711267c7f69d351d096533785dc1e93156 $" 39 | 40 | #include 41 | #include 42 | 43 | class manager_state { 44 | public: 45 | manager_state() throw(); 46 | bool is_dead(void) throw(); 47 | bool is_alive(void) throw(); 48 | void kill(void) throw(); 49 | bool capture_is_enabled(void) throw(); 50 | bool copy_is_enabled(void) throw(); 51 | protected: 52 | void enable_capture(void) throw(); 53 | void disable_capture(void) throw(); 54 | void enable_copy(void) throw(); 55 | void disable_copy(void) throw(); 56 | private: 57 | std::atomic_bool m_is_dead; 58 | std::atomic_bool m_capture_enabled; 59 | std::atomic_bool m_copy_enabled; 60 | }; 61 | 62 | #endif // End of header guardian. 63 | -------------------------------------------------------------------------------- /backup/mutex.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: fbda773ddb8998e35dbb4a896f64a8b1dd25b3ff $" 36 | 37 | #include 38 | #include 39 | #include "manager.h" 40 | 41 | #define NO_DEPRECATE_PTHREAD_MUTEXES 42 | #include "mutex.h" 43 | #include "check.h" 44 | 45 | void pmutex_lock(pthread_mutex_t *mutex, const backtrace bt) throw() { 46 | int r = pthread_mutex_lock(mutex); 47 | if (r != 0) { 48 | printf("HotBackup::pmutex_lock() failed, r = %d", r); 49 | } 50 | check_bt(r==0, bt); 51 | } 52 | 53 | void pmutex_unlock(pthread_mutex_t *mutex, const backtrace bt) throw() { 54 | int r = pthread_mutex_unlock(mutex); 55 | if (r != 0) { 56 | printf("HotBackup::pmutex_unlock() failed, r = %d", r); 57 | } 58 | check_bt(r==0, bt); 59 | } 60 | 61 | void pmutex_lock(pthread_mutex_t *mutex) throw() { 62 | pmutex_lock(mutex, BACKTRACE(NULL)); 63 | } 64 | 65 | void pmutex_unlock(pthread_mutex_t *mutex) throw() { 66 | pmutex_unlock(mutex, BACKTRACE(NULL)); 67 | } 68 | -------------------------------------------------------------------------------- /backup/mutex.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ifndef MUTEX_H 36 | #define MUTEX_H 37 | 38 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 39 | #ident "$Id: 19241b7a8d2ff2ab2e0b6dbe0e4cbedfea33af8c $" 40 | 41 | #include 42 | #include "backtrace.h" 43 | 44 | #ifndef NO_DEPRECATE_PTHREAD_MUTEXES 45 | extern int pthread_mutex_lock(pthread_mutex_t *) __attribute__((deprecated)); 46 | extern int pthread_mutex_unlock(pthread_mutex_t *) __attribute__((deprecated)); 47 | #endif 48 | 49 | // We assume there are no errors returned by these functions (if mutexes are broken, then other things are going wrong...) This function checks for errors and aborts. 50 | extern void pmutex_lock(pthread_mutex_t *) throw(); 51 | extern void pmutex_unlock(pthread_mutex_t *) throw(); 52 | 53 | extern void pmutex_lock(pthread_mutex_t *, const backtrace) throw(); 54 | extern void pmutex_unlock(pthread_mutex_t *, const backtrace) throw(); 55 | 56 | class with_mutex_locked { 57 | private: 58 | pthread_mutex_t *m_mutex; 59 | bool m_have_backtrace; 60 | const backtrace m_backtrace; 61 | public: 62 | with_mutex_locked(pthread_mutex_t *m): m_mutex(m), m_have_backtrace(false) { 63 | pmutex_lock(m_mutex); 64 | } 65 | with_mutex_locked(pthread_mutex_t *m, const backtrace bt): m_mutex(m), m_have_backtrace(true), m_backtrace(bt) { 66 | pmutex_lock(m_mutex, m_backtrace); 67 | } 68 | ~with_mutex_locked(void) { 69 | if (m_have_backtrace) { 70 | pmutex_unlock(m_mutex, m_backtrace); 71 | } else { 72 | pmutex_unlock(m_mutex); 73 | } 74 | } 75 | }; 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /backup/raii-malloc.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 35 | #ident "$Id: 410351372874d295c63be49beda4da9e63d567d6 $" 36 | 37 | #include "stdlib.h" 38 | 39 | template class with_object_to_free { 40 | public: 41 | const T value; 42 | with_object_to_free(T v): value(v) {}; 43 | ~with_object_to_free(void) { if(value) free((void*)value); } 44 | }; 45 | 46 | template class with_malloced { 47 | public: 48 | const T value; 49 | with_malloced(size_t size): value((T)malloc(size)) {}; 50 | ~with_malloced(void) { if(value) free((void*)value); } 51 | }; 52 | -------------------------------------------------------------------------------- /backup/remote/Makefile: -------------------------------------------------------------------------------- 1 | backup.pb.o: backup.pb.h 2 | CXXFLAGS = -W -Wall -Werror -O1 3 | backup.pb.cc backup.bp.h: backup.proto 4 | protoc -I=. --cpp_out=. backup.proto 5 | -------------------------------------------------------------------------------- /backup/remote/backup.proto: -------------------------------------------------------------------------------- 1 | package backup; 2 | 3 | message Backup { 4 | repeated Action action = 1; 5 | } 6 | 7 | message Action { 8 | enum ActionType { 9 | CREATE = 0; 10 | RENAME = 1; 11 | UNLINK = 2; 12 | LINK = 3; 13 | OPEN = 4; 14 | CLOSE = 5; 15 | PWRITE = 6; 16 | }; 17 | required ActionType action = 1; 18 | 19 | message Create { 20 | required string name = 1; 21 | optional int32 mode = 2; // protection and so forth. 22 | } 23 | optional Create create = 2; 24 | 25 | message Rename { 26 | required string oldname = 1; 27 | required string newname = 2; 28 | } 29 | optional Rename rename = 3; 30 | 31 | message Unlink { 32 | required string name = 1; 33 | } 34 | optional Unlink unlink = 4; 35 | 36 | message Link { 37 | required string oldname = 1; 38 | required string newname = 2; 39 | } 40 | optional Link link = 5; 41 | 42 | message Open { 43 | required string name = 1; 44 | required uint32 fd = 2; 45 | } 46 | optional Open open = 6; 47 | 48 | message Close { 49 | required uint32 fd = 1; 50 | } 51 | optional Close close = 7; 52 | 53 | message Pwrite { 54 | required uint32 fd = 1; 55 | required bytes data = 2; 56 | required uint64 off = 3; 57 | } 58 | optional Pwrite pwrite = 8; 59 | } 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /backup/rwlock.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: c1d6877bb733f3379327172ae0b168d3493c98f3 $" 36 | 37 | #include 38 | #include "check.h" 39 | #include "manager.h" 40 | #include "mutex.h" 41 | #include "rwlock.h" 42 | 43 | void prwlock_rdlock(pthread_rwlock_t *lock, const backtrace bt) throw() { 44 | int r = pthread_rwlock_rdlock(lock); 45 | check_bt(r==0, bt); 46 | } 47 | 48 | void prwlock_wrlock(pthread_rwlock_t *lock, const backtrace bt) throw() { 49 | int r = pthread_rwlock_wrlock(lock); 50 | check_bt(r==0, bt); 51 | } 52 | 53 | void prwlock_unlock(pthread_rwlock_t *lock, const backtrace bt) throw() { 54 | int r = pthread_rwlock_unlock(lock); 55 | check_bt(r==0, bt); 56 | } 57 | 58 | void prwlock_rdlock(pthread_rwlock_t *lock) throw() { 59 | int r = pthread_rwlock_rdlock(lock); 60 | check(r==0); 61 | } 62 | 63 | void prwlock_wrlock(pthread_rwlock_t *lock) throw() { 64 | int r = pthread_rwlock_wrlock(lock); 65 | check(r==0); 66 | } 67 | 68 | void prwlock_unlock(pthread_rwlock_t *lock) throw() { 69 | int r = pthread_rwlock_unlock(lock); 70 | check(r==0); 71 | } 72 | -------------------------------------------------------------------------------- /backup/rwlock.h: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | #ifndef RWLOCK_H 33 | #define RWLOCK_H 34 | 35 | #ident "Copyright (c) 2012-2013 Tokutek Inc. All rights reserved." 36 | #ident "$Id: 3b118bdcc3458adeec23e7c58944aa1766789fc2 $" 37 | 38 | #include 39 | 40 | extern void prwlock_rdlock(pthread_rwlock_t *) throw(); 41 | extern void prwlock_wrlock(pthread_rwlock_t *) throw(); 42 | extern void prwlock_unlock(pthread_rwlock_t *) throw(); 43 | extern void prwlock_rdlock(pthread_rwlock_t *, const backtrace) throw(); 44 | extern void prwlock_wrlock(pthread_rwlock_t *, const backtrace) throw(); 45 | extern void prwlock_unlock(pthread_rwlock_t *, const backtrace) throw(); 46 | 47 | class with_rwlock_rdlocked { 48 | private: 49 | pthread_rwlock_t *m_rwlock; 50 | bool m_have_backtrace; 51 | const backtrace m_backtrace; 52 | public: 53 | with_rwlock_rdlocked(pthread_rwlock_t *rw): m_rwlock(rw), m_have_backtrace(false) { 54 | prwlock_rdlock(m_rwlock); 55 | } 56 | with_rwlock_rdlocked(pthread_rwlock_t *m, const backtrace bt): m_rwlock(m), m_have_backtrace(true), m_backtrace(bt) { 57 | prwlock_rdlock(m_rwlock, m_backtrace); 58 | } 59 | ~with_rwlock_rdlocked(void) { 60 | if (m_have_backtrace) { 61 | prwlock_unlock(m_rwlock, m_backtrace); 62 | } else { 63 | prwlock_unlock(m_rwlock); 64 | } 65 | } 66 | }; 67 | 68 | class with_rwlock_wrlocked { 69 | private: 70 | pthread_rwlock_t *m_rwlock; 71 | bool m_have_backtrace; 72 | const backtrace m_backtrace; 73 | public: 74 | with_rwlock_wrlocked(pthread_rwlock_t *rw): m_rwlock(rw), m_have_backtrace(false) { 75 | prwlock_wrlock(m_rwlock); 76 | } 77 | with_rwlock_wrlocked(pthread_rwlock_t *m, const backtrace bt): m_rwlock(m), m_have_backtrace(true), m_backtrace(bt) { 78 | prwlock_wrlock(m_rwlock, m_backtrace); 79 | } 80 | ~with_rwlock_wrlocked(void) { 81 | if (m_have_backtrace) { 82 | prwlock_unlock(m_rwlock, m_backtrace); 83 | } else { 84 | prwlock_unlock(m_rwlock); 85 | } 86 | } 87 | }; 88 | 89 | 90 | #endif // End of header guardian. 91 | -------------------------------------------------------------------------------- /backup/scripts/tokugrind: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function usage() { 4 | echo "check for valgrind error and set the exit code" 5 | } 6 | 7 | function cleanup() { 8 | if [ "$logfile" != "" ] ; then rm $logfile; fi 9 | exit 1 10 | } 11 | 12 | args=$* 13 | 14 | logfile= 15 | createlogfile=0 16 | errorexitcode=1 17 | 18 | while [ $# -gt 0 ] ; do 19 | arg=$1; shift 20 | if [[ $arg =~ "--" ]] ; then 21 | if [[ $arg =~ --log-file=(.*) ]] ; then 22 | logfile=${BASH_REMATCH[1]} 23 | elif [[ $arg =~ --error-exitcode=(.*) ]] ; then 24 | errorexitcode=${BASH_REMATCH[1]} 25 | fi 26 | else 27 | break 28 | fi 29 | done 30 | 31 | if [ "$logfile" = "" ] ; then 32 | createlogfile=1 33 | trap cleanup SIGINT 34 | logfile=`mktemp /tmp/$(whoami).tokugrind.XXXXXXXX` 35 | args="--log-file=$logfile $args" 36 | fi 37 | 38 | valgrind $args 39 | exitcode=$? 40 | if [ $exitcode = 0 ] ; then 41 | lines=$(wc -l <$logfile) 42 | if [ $lines -ne 0 ] ; then 43 | exitcode=$errorexitcode 44 | fi 45 | fi 46 | 47 | if [ $createlogfile != 0 ] ; then 48 | cat $logfile >>/dev/stderr 49 | rm $logfile 50 | fi 51 | 52 | exit $exitcode 53 | -------------------------------------------------------------------------------- /backup/scripts/tokuvalgrind: -------------------------------------------------------------------------------- 1 | tokugrind -------------------------------------------------------------------------------- /backup/tests/.gitattributes: -------------------------------------------------------------------------------- 1 | * ident 2 | -------------------------------------------------------------------------------- /backup/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(BackupTests) 3 | include_directories(..) 4 | find_package( Threads ) 5 | 6 | if (USE_VALGRIND) 7 | option(USE_GRIND "Use helgrind and valgrind." ON) 8 | endif () 9 | 10 | function(add_valgrind_tool_test tool test) 11 | add_test( 12 | NAME 13 | ${tool}/${test} 14 | COMMAND 15 | valgrind --tool=${tool} --suppressions=${PROJECT_SOURCE_DIR}/../${tool}.suppressions --error-exitcode=1 $ --testname ${test}.${tool} 16 | ) 17 | endfunction(add_valgrind_tool_test) 18 | 19 | set(blackboxtests 20 | cannotopen_dest_dir 21 | closedirfails_dest_dir 22 | dest_no_permissions_10 23 | dest_no_permissions_with_open_10 24 | empty_dest 25 | multiple_backups 26 | open_close_6731 27 | open_write_close 28 | open_prepare_race_6610 29 | read_and_seek 30 | test6128 31 | no_dest_dir_6317b 32 | notinsource_6570 33 | notinsource_6570b 34 | null_dest_dir_6317 35 | nondir_dest_dir_6317 36 | readdirfails_dest_dir 37 | open_write_race 38 | source_no_permissions_10 39 | test6361 40 | throttle_6564 41 | unlink_during_copy_test6515 42 | unlink_during_copy_test6515b 43 | ) 44 | 45 | set(glassboxtests 46 | backup_directory_tests 47 | backup_no_fractal_tree ## Needs the keep_capturing API 48 | backup_no_fractal_tree_threaded ## Needs the keep_capturing API 49 | backup_no_ft2 ## Needs the keep_capturing API 50 | capture_only_rename 51 | check_check 52 | check_check2 53 | create_rename_race 54 | create_unlink_race 55 | debug_coverage 56 | exclude_all_files 57 | failed_rename_kills_backup_6703 ## Needs the keep_capturing API 58 | failed_unlink_kills_backup_6704 ## Needs the keep_capturing API 59 | ftruncate ## Needs the keep_capturing API 60 | ftruncate_injection_6480 61 | copy_files 62 | test_dirsum 63 | disable_race 64 | end_race_open_6668 65 | end_race_rename_6668 66 | end_race_rename_6668b 67 | many_directories 68 | range_locks 69 | realpath_error_injection 70 | test6415_enospc_injection 71 | test6431_postcopy 72 | test6469_many_enospc_injection 73 | test6477_close_injection 74 | test6478_read_injection 75 | test6483_mkdir_injection 76 | two_renames_race 77 | open_injection_6476 78 | rename 79 | rename_injection 80 | unlink 81 | ## unlink_create_close_race_6727 ## This test fails because of a known and immaterial issue between rename and close. 82 | unlink_copy_race 83 | unlink_during_copy_test6515c 84 | unlink_injection 85 | write_race 86 | lseek_write 87 | open_lseek_write 88 | pwrite_during_backup 89 | ) 90 | 91 | set(glassboxtests_no_grind 92 | abort_while_holding_lock ## needs to register a rename function. This function won't work well under helgrind or memcheck since it exits out of a signal handler. 93 | ) 94 | 95 | foreach(test ${blackboxtests}) 96 | add_executable(${test} ${test} backup_test_helpers) 97 | target_link_libraries(${test} HotBackup ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 98 | add_test(${test} ${test} --testname ${test}) 99 | endforeach(test) 100 | 101 | foreach(test ${glassboxtests} ${glassboxtests_no_grind}) 102 | add_executable(${test} ${test} backup_test_helpers) 103 | target_link_libraries(${test} HotBackupGlassbox ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 104 | add_test(${test} ${test} --testname ${test}) 105 | endforeach(test) 106 | 107 | foreach(test ${blackboxtests} ${glassboxtests}) 108 | if (USE_GRIND) 109 | add_valgrind_tool_test(helgrind ${test}) 110 | add_valgrind_tool_test(drd ${test}) 111 | endif (USE_GRIND) 112 | endforeach(test) 113 | -------------------------------------------------------------------------------- /backup/tests/abort_while_holding_lock.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 4827c04880b8436ffda76ab38c99d09086aecfdf $" 36 | 37 | // We want to make sure that the check() macro doesn't deadlock if 38 | // it's called while holding one of the backup locks, even if while 39 | // running abort(), or some signal handler that abort might call, an 40 | // I/O happens that might try to grab that lock if the backup system 41 | // is running. This is covered in git issue #24. 42 | #undef NDEBUG 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "backtrace.h" 50 | #include "backup_test_helpers.h" 51 | #include "real_syscalls.h" 52 | 53 | // Get rid of the check in backup_test_helpers, in favor of the one that the rest of the backup library uses. 54 | #undef check 55 | #include "../check.h" 56 | 57 | rename_fun_t real_rename = NULL; 58 | 59 | __thread int stack_depth = 0; 60 | 61 | int my_rename(const char *a, const char *b) { 62 | printf("Doing rename\n"); 63 | int r = real_rename(a, b); 64 | stack_depth++; 65 | if (stack_depth==1) { 66 | check_fun(0, "call check fun to make sure it fails properly", BACKTRACE(NULL)); 67 | } 68 | stack_depth--; 69 | return r; 70 | } 71 | 72 | char *A, *B, *C, *D; 73 | 74 | void handler(int i __attribute__((unused))) { 75 | int r = rename(C, D); 76 | if (0) printf("%s:%d r=%d\n", __FILE__, __LINE__, r); 77 | exit(0); // want to exit gracefully. 78 | } 79 | 80 | int test_main(int argc __attribute__((unused)), const char *argv[] __attribute__((unused))) { 81 | signal(SIGABRT, handler); 82 | real_rename = register_rename(my_rename); 83 | setup_source(); 84 | char *src = get_src(); 85 | size_t len = strlen(src)+100; 86 | A = (char*)malloc(len); { int r = snprintf(A, len, "%s/A", src); check(size_t(r)=0); 93 | int r = close(fd); 94 | check(r==0); 95 | } 96 | { 97 | int r = rename(A, B); 98 | check(r==0); 99 | } 100 | cleanup_dirs(); 101 | free(src); 102 | free(A); 103 | free(B); 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /backup/tests/backup_directory_tests.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 4b0059602f91e9636a13cdaab3ce999c14af7356 $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "backup_test_helpers.h" 43 | #include "backup_internal.h" 44 | #include "backup_directory.h" 45 | 46 | #define LONG_DIR "/ThisIsALongDirectory/WithNothing/InIt/" 47 | 48 | static int backup_sub_dirs(void) { 49 | setup_destination(); 50 | setup_source(); 51 | 52 | char *src = get_src(); 53 | char *dst = get_dst(); 54 | char *source = realpath(src, NULL); 55 | char *destination = realpath(dst, NULL); 56 | 57 | // We need to pretend that there is a source directory with this 58 | // long path. So, let's first create enough space for it. 59 | char *newpath = (char*)malloc(PATH_MAX); 60 | strcpy(newpath, destination); 61 | char *temp = newpath; 62 | 63 | // Move to the end of the absolute destination path we just 64 | // copied. 65 | while(*temp++) {;} 66 | --temp; 67 | 68 | // Append the long directory path to the destination path we just 69 | // copied. 70 | const char *longname = LONG_DIR; 71 | while(*longname) { 72 | *temp = *(longname)++; 73 | temp++; 74 | } 75 | 76 | *temp = 0; 77 | { 78 | int r = create_subdirectories(newpath); 79 | check(r==0); 80 | } 81 | free(newpath); 82 | 83 | // Verify: 84 | struct stat sb; 85 | char dst_long_dir[PATH_MAX]; 86 | { 87 | int r = snprintf(dst_long_dir, sizeof(dst_long_dir), "%s%s", dst, LONG_DIR); 88 | check(r. 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: 3e49f379d56063dbf18ee88285d68bbc95049355 $" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "backup_test_helpers.h" 43 | #include "backup_internal.h" 44 | 45 | char *src, *dst; 46 | 47 | #define FIRSTBYTES "first bytes\n" 48 | #define MOREBYTES "more bytes\n" 49 | 50 | int test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 51 | setup_destination(); 52 | setup_source(); 53 | src = get_src(); 54 | dst = get_dst(); 55 | 56 | int fd0 = openf(O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO, "%s/file0", src); 57 | check(fd0>=0); 58 | { 59 | ssize_t r = write(fd0, FIRSTBYTES, sizeof(FIRSTBYTES)-1); 60 | check(r==sizeof(FIRSTBYTES)-1); 61 | } 62 | backup_set_keep_capturing(true); 63 | pthread_t thread; 64 | start_backup_thread(&thread); 65 | usleep(100000); 66 | { 67 | ssize_t r = write(fd0, MOREBYTES, sizeof(MOREBYTES)-1); 68 | check(r==sizeof(MOREBYTES)-1); 69 | } 70 | backup_set_keep_capturing(false); 71 | finish_backup_thread(thread); 72 | { 73 | int status = systemf("diff -r %s %s", src, dst); 74 | check(status!=-1); 75 | check(WIFEXITED(status)); 76 | check(WEXITSTATUS(status)==0); 77 | } 78 | free(src); 79 | free(dst); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /backup/tests/backup_no_ft2.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: 6596e26468b309f2a6914493c726e2c6772dd7ae $" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "backup_test_helpers.h" 43 | #include "backup_internal.h" 44 | 45 | char *src, *dst; 46 | 47 | static int fds[4]; 48 | static void open_n(int n) { 49 | fds[n] = openf(O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO, "%s/file%d", src, n); 50 | check(fds[n]>=0); 51 | } 52 | static void close_n(int n) { 53 | int r = close(fds[n]); 54 | check(r==0); 55 | fds[n] = 0; 56 | } 57 | static void write_n(int n) { 58 | char data[100]; 59 | snprintf(data, sizeof(data), "%d", n); 60 | const size_t len = strlen(data); 61 | const ssize_t r = write(fds[n], data, len); 62 | check(r == (ssize_t)len); 63 | } 64 | 65 | int test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 66 | setup_destination(); 67 | setup_source(); 68 | src = get_src(); 69 | dst = get_dst(); 70 | 71 | backup_set_keep_capturing(true); 72 | pthread_t thread; 73 | start_backup_thread(&thread); 74 | 75 | open_n(0); 76 | write_n(0); 77 | 78 | open_n(1); 79 | write_n(1); 80 | 81 | open_n(2); 82 | write_n(2); 83 | 84 | close_n(0); 85 | 86 | open_n(3); 87 | write_n(3); 88 | write_n(2); 89 | write_n(1); 90 | 91 | close_n(1); 92 | close_n(2); 93 | close_n(3); 94 | 95 | backup_set_keep_capturing(false); 96 | finish_backup_thread(thread); 97 | 98 | { 99 | int status = systemf("diff -r %s %s", src, dst); 100 | check(status!=-1); 101 | check(WIFEXITED(status)); 102 | check(WEXITSTATUS(status)==0); 103 | } 104 | free(src); 105 | free(dst); 106 | return 0; 107 | } 108 | -------------------------------------------------------------------------------- /backup/tests/cannotopen_dest_dir.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: a2ef0fef2a97a059a0a127a804ecaf4e70636515 $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | 44 | #include "backup.h" 45 | #include "backup_test_helpers.h" 46 | 47 | // Test for #6317 dest dir is not a directory. 48 | const int expect_result = EACCES; // 49 | int error_count=0; 50 | bool ok=true; 51 | 52 | static void expect_error(int error_number, const char *error_string, void *error_extra) { 53 | if (error_count!=0) { ok=false; fprintf(stderr, "%s:%d error function called twice\n", __FILE__, __LINE__); } 54 | error_count++; 55 | if (error_number!=expect_result) { ok=false; fprintf(stderr, "%s:%d error_number=%d expected %d\n", __FILE__, __LINE__, error_number, expect_result); } 56 | if (error_string==NULL) { ok=false; fprintf(stderr, "%s:%d expect error_string nonnull\n", __FILE__, __LINE__); } 57 | printf("error_string (expected)=%s\n", error_string); 58 | if (error_extra!=NULL) { ok=false; fprintf(stderr, "%s:%d expect error_extra NULL\n", __FILE__, __LINE__); } 59 | } 60 | 61 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 62 | cleanup_dirs(); // remove destination dir 63 | setup_source(); 64 | setup_destination(); // set up the dest 65 | setup_dirs(); 66 | // But make the dest unreadable 67 | { 68 | char *dst = get_dst(); 69 | int r = systemf("chmod ugo-rwx %s", dst); 70 | check(r==0); 71 | free(dst); 72 | } 73 | // Dest dir is a file, not a directory 74 | pthread_t thread; 75 | start_backup_thread_with_funs(&thread, get_src(), get_dst(), simple_poll_fun, NULL, expect_error, NULL, expect_result); 76 | finish_backup_thread(thread); 77 | if (ok && error_count!=1) { 78 | ok=false; 79 | fprintf(stderr, "%s:%d expect error_count==1 but it is %d\n", __FILE__, __LINE__, error_count); 80 | } 81 | cleanup_dirs(); 82 | if (ok) { 83 | pass(); 84 | } else { 85 | fail(); 86 | } 87 | printf(": test6317()\n"); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /backup/tests/check_check.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 8e84aa848f375ebf9e97399003933c813c5ce460 $" 36 | 37 | #include "check.h" 38 | #include 39 | #include 40 | 41 | // To see if check(0) aborts, install a signal handler that does exit(0). 42 | 43 | void handler(int i __attribute__((unused))) { 44 | exit(0); 45 | } 46 | 47 | int test_main (int argc __attribute__((unused)), const char *argv[] __attribute__((unused))) { 48 | signal(SIGABRT, handler); 49 | check(0); 50 | return 1; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /backup/tests/check_check2.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 23786a97feacc000d2497594d749090e62a5da55 $" 36 | 37 | #include "backtrace.h" 38 | #include "check.h" 39 | #include 40 | #include 41 | 42 | // To see if check(0) aborts, install a signal handler that does exit(0). 43 | 44 | void handler(int i __attribute__((unused))) { 45 | exit(0); 46 | } 47 | 48 | void doit2(const backtrace bt) { 49 | check_bt(0, bt); 50 | } 51 | 52 | void doit(const backtrace bt) { 53 | doit2(BACKTRACE(&bt)); 54 | } 55 | 56 | int test_main (int argc __attribute__((unused)), const char *argv[] __attribute__((unused))) { 57 | signal(SIGABRT, handler); 58 | doit(BACKTRACE(NULL)); 59 | return 1; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /backup/tests/closedirfails_dest_dir.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: ed7753f6a00403c47048a307eedd23fd9b9ba8e6 $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | 46 | #include "backup.h" 47 | #include "backup_test_helpers.h" 48 | 49 | // Test for #6317 dest dir is not a directory. 50 | const int expect_result = EINVAL; // 51 | int error_count=0; 52 | bool ok=true; 53 | 54 | static void expect_error(int error_number, const char *error_string, void *error_extra) { 55 | if (error_count!=0) { ok=false; fprintf(stderr, "%s:%d error function called twice\n", __FILE__, __LINE__); } 56 | error_count++; 57 | if (error_number!=expect_result) { ok=false; fprintf(stderr, "%s:%d error_number=%d expected %d\n", __FILE__, __LINE__, error_number, expect_result); } 58 | if (error_string==NULL) { ok=false; fprintf(stderr, "%s:%d expect error_string nonnull\n", __FILE__, __LINE__); } 59 | printf("error_string (expected)=%s\n", error_string); 60 | if (error_extra!=NULL) { ok=false; fprintf(stderr, "%s:%d expect error_extra NULL\n", __FILE__, __LINE__); } 61 | } 62 | 63 | #if 1 64 | int closedir(DIR *dirp) { 65 | // use this version of closedir which, as expected by the test, won't work. 66 | int (*real_closedir)(DIR*) = (int(*)(DIR*))dlsym(RTLD_NEXT, "closedir"); 67 | int r = real_closedir(dirp); 68 | check(r==0); 69 | errno = EINVAL; 70 | return -1; 71 | } 72 | #endif 73 | 74 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 75 | cleanup_dirs(); // remove destination dir 76 | setup_source(); 77 | setup_destination(); // set up the dest 78 | setup_dirs(); 79 | // Dest dir is a file, not a directory 80 | pthread_t thread; 81 | start_backup_thread_with_funs(&thread, get_src(), get_dst(), simple_poll_fun, NULL, expect_error, NULL, expect_result); 82 | finish_backup_thread(thread); 83 | if (ok && error_count!=1) { 84 | ok=false; 85 | fprintf(stderr, "%s:%d expect error_count==1 but it is %d\n", __FILE__, __LINE__, error_count); 86 | } 87 | cleanup_dirs(); 88 | if (ok) { 89 | pass(); 90 | } else { 91 | fail(); 92 | } 93 | printf(": test6317()\n"); 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /backup/tests/debug_coverage.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 6c156563b7cd54dac608c7a2eb4dc661ba7a013d $" 36 | 37 | #include "backup_debug.h" 38 | #include "backup.h" 39 | // Call all the trace and warn code (for coverage) 40 | int test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 41 | HotBackup::CopyTrace("hello", "there"); 42 | HotBackup::CopyWarn("hello", "there"); 43 | HotBackup::CopyError("hello", "there"); 44 | 45 | HotBackup::CaptureTrace("hello", "there"); 46 | HotBackup::CaptureTrace("hello", 3); 47 | HotBackup::CaptureWarn("hello", "there"); 48 | HotBackup::CaptureError("hello", "there"); 49 | HotBackup::CaptureError("hello", 3); 50 | 51 | HotBackup::InterposeTrace("hello", "there"); 52 | HotBackup::InterposeTrace("hello", 3); 53 | HotBackup::InterposeWarn("hello", "there"); 54 | HotBackup::InterposeError("hello", "there"); 55 | 56 | HotBackup::should_pause(HotBackup::MANAGER_IN_PREPARE); 57 | HotBackup::should_pause(HotBackup::MANAGER_IN_DISABLE); 58 | HotBackup::should_pause(-1); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /backup/tests/dest_no_permissions_10.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 075e3f655953dc98f002319737378867f21f1d32 $" 36 | 37 | // Test to make sure nothing crashes if the backup destination directory has unwriteable permissions. 38 | 39 | #include 40 | 41 | #include "backup_test_helpers.h" 42 | 43 | volatile bool saw_error = false; 44 | 45 | static void expect_eacces_error_fun(int error_number, const char *error_string, void *backup_extra __attribute__((unused))) { 46 | fprintf(stderr, "EXPECT ERROR %d: %d (%s)\n", EACCES, error_number, error_string); 47 | check(error_number==EACCES); 48 | saw_error = true; 49 | } 50 | 51 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 52 | setup_source(); 53 | setup_destination(); 54 | setup_dirs(); 55 | char *src = get_src(); 56 | char *dst = get_dst(); 57 | { 58 | int r = systemf("chmod ugo-w %s", dst); 59 | check(r==0); 60 | } 61 | { 62 | const char *srcs[1] = {src}; 63 | const char *dsts[1] = {dst}; 64 | int r = tokubackup_create_backup(srcs, dsts, 1, 65 | simple_poll_fun, NULL, 66 | expect_eacces_error_fun, NULL, 67 | NULL, NULL); 68 | check(r==EACCES); 69 | check(saw_error); 70 | } 71 | cleanup_dirs(); 72 | free(src); 73 | free(dst); 74 | return 0; 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /backup/tests/dest_no_permissions_with_open_10.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: a1c114a3c56af9d21ca0de01f7973f1f1cd06bdc $" 36 | 37 | // Test to make sure nothing crashes if the backup destination directory has unwriteable permissions. 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "backup_test_helpers.h" 45 | 46 | volatile bool saw_error = false; 47 | 48 | static void expect_eacces_error_fun(int error_number, const char *error_string, void *backup_extra __attribute__((unused))) { 49 | fprintf(stderr, "EXPECT ERROR %d: %d (%s)\n", EACCES, error_number, error_string); 50 | check(error_number==EACCES); 51 | saw_error = true; 52 | } 53 | 54 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 55 | setup_source(); 56 | setup_destination(); 57 | setup_dirs(); 58 | char *src = get_src(); 59 | int foo_fd; 60 | { 61 | foo_fd = openf(O_RDWR, 0, "%s/%s", src, "foo"); 62 | check(foo_fd >= 0); 63 | } 64 | char *dst = get_dst(); 65 | { 66 | int r = systemf("chmod ugo-w %s", dst); 67 | check(r==0); 68 | } 69 | { 70 | const char *srcs[1] = {src}; 71 | const char *dsts[1] = {dst}; 72 | int r = tokubackup_create_backup(srcs, dsts, 1, 73 | simple_poll_fun, NULL, 74 | expect_eacces_error_fun, NULL, 75 | NULL, NULL); 76 | check(r==EACCES); 77 | check(saw_error); 78 | } 79 | close(foo_fd); 80 | cleanup_dirs(); 81 | free(src); 82 | free(dst); 83 | return 0; 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /backup/tests/empty_dest.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: 10b88936e186dda2eac9c946cb273a35931f3bab $" 34 | 35 | // Test to make sure that if the destination isn't empty, then the backup fails. For 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "backup_test_helpers.h" 43 | 44 | static char *src; 45 | static char *dst; 46 | 47 | const int expect_result = EINVAL; // 48 | int error_count=0; 49 | bool ok=true; 50 | 51 | static void expect_error(int error_number, const char *error_string, void *error_extra) { 52 | if (error_count!=0) { ok=false; fprintf(stderr, "%s:%d error function called twice\n", __FILE__, __LINE__); } 53 | error_count++; 54 | if (error_number!=expect_result) { ok=false; fprintf(stderr, "%s:%d error_number=%d expected %d\n", __FILE__, __LINE__, error_number, expect_result); } 55 | if (error_string==NULL) { ok=false; fprintf(stderr, "%s:%d expect error_string nonnull\n", __FILE__, __LINE__); } 56 | printf("error_string (expected)=%s\n", error_string); 57 | if (error_extra!=NULL) { ok=false; fprintf(stderr, "%s:%d expect error_extra NULL\n", __FILE__, __LINE__); } 58 | } 59 | 60 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 61 | src = get_src(); 62 | dst = get_dst(); 63 | setup_source(); 64 | setup_destination(); 65 | setup_dirs(); 66 | 67 | { 68 | int r = systemf("echo hello > %s/a_file_is_there_but_shouldnt_be", dst); 69 | check(r!=-1); 70 | check(WIFEXITED(r)); 71 | check(WEXITSTATUS(r)==0); 72 | } 73 | 74 | pthread_t thread; 75 | start_backup_thread_with_funs(&thread, 76 | strdup(src), strdup(dst), // free's src and dst 77 | simple_poll_fun, NULL, 78 | expect_error, NULL, 79 | expect_result); 80 | finish_backup_thread(thread); 81 | free(src); 82 | free(dst); 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /backup/tests/failed_rename_kills_backup_6703.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 1b6551638e272e9d989ae105b352e36f16af0493 $" 36 | 37 | /* Create a race at the end */ 38 | 39 | #include "backup_internal.h" 40 | #include "backup_test_helpers.h" 41 | #include "real_syscalls.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 52 | char *src = get_src(); 53 | char *dst = get_dst(); 54 | setup_source(); 55 | setup_destination(); 56 | 57 | size_t len = strlen(src) + 20; 58 | char *no_such_path = (char*)malloc(len); 59 | char *newpath = (char*)malloc(len); 60 | { 61 | size_t r = snprintf(no_such_path, len, "%s/no_such.data", src); 62 | check(r. 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: c2ebd64b657521bbb636dbed2eac08daf5e2733d $" 36 | 37 | /* Create a race at the end */ 38 | 39 | #include "backup_internal.h" 40 | #include "backup_test_helpers.h" 41 | #include "real_syscalls.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 52 | char *src = get_src(); 53 | char *dst = get_dst(); 54 | setup_source(); 55 | setup_destination(); 56 | 57 | size_t len = strlen(src) + 20; 58 | char *no_such_path = (char*)malloc(len); 59 | { 60 | size_t r = snprintf(no_such_path, len, "%s/no_such.data", src); 61 | check(r. 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 5d28919809bcb2fcc38be97090a5ac79ee1ca21f $" 36 | 37 | 38 | // 39 | -------------------------------------------------------------------------------- /backup/tests/ftruncate.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 8aa8ff0c68c03a2cdf8d673e8eccafb401aa1289 $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #include "backup_test_helpers.h" 48 | #include "backup_internal.h" 49 | 50 | // 51 | void test_truncate(void) { 52 | int result = 0; 53 | setup_source(); 54 | setup_dirs(); 55 | setup_destination(); 56 | 57 | char *src = get_src(); 58 | 59 | backup_set_keep_capturing(true); 60 | pthread_t thread; 61 | start_backup_thread(&thread); 62 | 63 | // Create a new file. 64 | int fd = openf(O_CREAT | O_RDWR, 0777, "%s/my.data", src); 65 | check(fd >= 0); 66 | free(src); 67 | 68 | // Write a large chunk of data to it. 69 | result = write(fd, "Hello World", 12); 70 | 71 | // Truncate the end off. 72 | { 73 | int r = ftruncate(fd, 6); 74 | check(r==0); 75 | } 76 | backup_set_keep_capturing(false); 77 | const int SIZE = 20; 78 | char buf_source[SIZE]; 79 | size_t src_n_read = pread(fd, buf_source, SIZE, 0); 80 | check(src_n_read==6); 81 | 82 | finish_backup_thread(thread); 83 | 84 | // Confirm that the both files are the same size. 85 | char *dst = get_dst(); 86 | int backup_fd = openf(O_RDWR, 0, "%s/my.data", dst); 87 | check(backup_fd>=0); 88 | free(dst); 89 | char buf_copy[SIZE]; 90 | size_t dst_n_read = read(backup_fd, buf_copy, SIZE); 91 | check(dst_n_read==6); 92 | result = memcmp(buf_source, buf_copy, src_n_read); 93 | 94 | if (result != 0) { 95 | fail(); 96 | printf(": BACKUP: Files don't match! %s != %s\n", buf_source, buf_copy); 97 | fail(); 98 | } else { 99 | pass(); 100 | } 101 | 102 | printf(": test_truncate()\n"); 103 | } 104 | 105 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 106 | test_truncate(); 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /backup/tests/lseek_write.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | // Test that lseeks are intercepted by backup and executed while backup is 36 | // still capturing. 37 | 38 | #ident "$Id: 8e2a7fd9b7132da415bdaf6a02ce036692e2fabc $" 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "backup.h" 50 | #include "backup_test_helpers.h" 51 | 52 | static int verify(void) { 53 | char *src = get_src(); 54 | char *dst = get_dst(); 55 | int r = systemf("diff -r %s %s", src, dst); 56 | free(src); 57 | free(dst); 58 | if (!WIFEXITED(r)) return -1; 59 | if (WEXITSTATUS(r)!=0) return -1; 60 | return 0; 61 | } 62 | 63 | int lseek_write_after_copy(void) { 64 | int result = 0; 65 | int fd = 0; 66 | setup_source(); 67 | setup_dirs(); 68 | setup_destination(); 69 | 70 | // keep backup capturing until after the test executes the 71 | // final lseek and write. 72 | backup_set_keep_capturing(true); 73 | 74 | // start backup 75 | pthread_t thread; 76 | start_backup_thread(&thread); 77 | 78 | // create a source file and write at the beginning of the file 79 | char *src = get_src(); 80 | fd = openf(O_CREAT | O_RDWR, 0777, "%s/my.data", src); 81 | check(fd >= 0); 82 | free(src); 83 | result = write(fd, "Hello World\n", 12); 84 | check(result == 12); 85 | 86 | // wait for backup copy phase to copy the source file 87 | while (!backup_done_copying()) { 88 | sched_yield(); 89 | } 90 | 91 | // write at 1M offset 92 | const off_t next_write_offset = 1<<20; 93 | result = lseek(fd, next_write_offset, SEEK_SET); 94 | check(result == next_write_offset); 95 | result = write(fd, "Cruel World\n", 12); 96 | check(result == 12); 97 | 98 | result = close(fd); 99 | check(result == 0); 100 | 101 | // wait for the backup to finish 102 | backup_set_keep_capturing(false); 103 | finish_backup_thread(thread); 104 | 105 | // verify source and backup files 106 | if(verify()) { 107 | fail(); result = 1; 108 | } else { 109 | pass(); result = 0; 110 | } 111 | return result; 112 | } 113 | 114 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 115 | int result = lseek_write_after_copy(); 116 | return result; 117 | } 118 | -------------------------------------------------------------------------------- /backup/tests/no_dest_dir_6317b.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: f04ac4727d5f5dfc814073391f1f3b09dec143ea $" 36 | 37 | #include 38 | #include 39 | #include "backup.h" 40 | #include "backup_test_helpers.h" 41 | 42 | // Test for #6317 (nonexistent destination directory causes segfault) 43 | const int expect_result = ENOENT; 44 | int error_count=0; 45 | bool ok=true; 46 | 47 | static void expect_error(int error_number, const char *error_string, void *error_extra) { 48 | if (error_count!=0) { ok=false; fprintf(stderr, "%s:%d error function called twice\n", __FILE__, __LINE__); } 49 | error_count++; 50 | if (error_number!=expect_result) { ok=false; fprintf(stderr, "%s:%d error_number=%d expected %d\n", __FILE__, __LINE__, error_number, expect_result); } 51 | if (error_string==NULL) { ok=false; fprintf(stderr, "%s:%d expect error_string nonnull\n", __FILE__, __LINE__); } 52 | printf("error_string (expected)=%s\n", error_string); 53 | if (error_extra!=NULL) { ok=false; fprintf(stderr, "%s:%d expect error_extra NULL\n", __FILE__, __LINE__); } 54 | } 55 | 56 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 57 | cleanup_dirs(); // remove destination dir 58 | setup_source(); 59 | setup_dirs(); 60 | // No destination dir 61 | pthread_t thread; 62 | start_backup_thread_with_funs(&thread, get_src(), get_dst(), simple_poll_fun, NULL, expect_error, NULL, expect_result); 63 | finish_backup_thread(thread); 64 | if (ok && error_count!=1) { 65 | ok=false; 66 | fprintf(stderr, "%s:%d expect error_count==1 but it is %d\n", __FILE__, __LINE__, error_count); 67 | } 68 | cleanup_dirs(); 69 | if (ok) { 70 | pass(); 71 | } else { 72 | fail(); 73 | } 74 | printf(": test6317()\n"); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /backup/tests/nondir_dest_dir_6317.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: f4d1465b7ae6d64cb3d2a14d6e8176fe66d3adcd $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "backup.h" 44 | #include "backup_test_helpers.h" 45 | 46 | // Test for #6317 dest dir is not a directory. 47 | const int expect_result = EINVAL; // 48 | int error_count=0; 49 | bool ok=true; 50 | 51 | static void expect_error(int error_number, const char *error_string, void *error_extra) { 52 | if (error_count!=0) { ok=false; fprintf(stderr, "%s:%d error function called twice\n", __FILE__, __LINE__); } 53 | error_count++; 54 | if (error_number!=expect_result) { ok=false; fprintf(stderr, "%s:%d error_number=%d expected %d\n", __FILE__, __LINE__, error_number, expect_result); } 55 | if (error_string==NULL) { ok=false; fprintf(stderr, "%s:%d expect error_string nonnull\n", __FILE__, __LINE__); } 56 | printf("error_string (expected)=%s\n", error_string); 57 | if (error_extra!=NULL) { ok=false; fprintf(stderr, "%s:%d expect error_extra NULL\n", __FILE__, __LINE__); } 58 | } 59 | 60 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 61 | cleanup_dirs(); // remove destination dir 62 | setup_source(); 63 | setup_dirs(); 64 | { 65 | char *dst = get_dst(); 66 | int fd = open(dst, O_CREAT | O_WRONLY | O_EXCL, 0777); 67 | check(fd>=0); 68 | int r = close(fd); 69 | check(r==0); 70 | free(dst); 71 | } 72 | // Dest dir is a file, not a directory 73 | pthread_t thread; 74 | start_backup_thread_with_funs(&thread, get_src(), get_dst(), simple_poll_fun, NULL, expect_error, NULL, expect_result); 75 | finish_backup_thread(thread); 76 | if (ok && error_count!=1) { 77 | ok=false; 78 | fprintf(stderr, "%s:%d expect error_count==1 but it is %d\n", __FILE__, __LINE__, error_count); 79 | } 80 | cleanup_dirs(); 81 | if (ok) { 82 | pass(); 83 | } else { 84 | fail(); 85 | } 86 | printf(": test6317()\n"); 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /backup/tests/null_dest_dir_6317.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 588aaf15ee57cc86ccf1dda493c84a5d43c67ae8 $" 36 | 37 | #include 38 | #include 39 | #include "backup.h" 40 | #include "backup_test_helpers.h" 41 | 42 | // Test for #6317 (nonexistent destination directory causes segfault). This particular test tests for the destination==NULL. 43 | const int expect_result = EINVAL; 44 | int error_count=0; 45 | bool ok=true; 46 | 47 | static void expect_error(int error_number, const char *error_string, void *error_extra) { 48 | if (error_count!=0) { ok=false; fprintf(stderr, "%s:%d error function called twice\n", __FILE__, __LINE__); } 49 | error_count++; 50 | if (error_number!=expect_result) { ok=false; fprintf(stderr, "%s:%d error_number=%d expected %d\n", __FILE__, __LINE__, error_number, expect_result); } 51 | if (error_string==NULL) { ok=false; fprintf(stderr, "%s:%d expect error_string nonnull\n", __FILE__, __LINE__); } 52 | printf("error_string (expected)=%s\n", error_string); 53 | if (error_extra!=NULL) { ok=false; fprintf(stderr, "%s:%d expect error_extra NULL\n", __FILE__, __LINE__); } 54 | } 55 | 56 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 57 | cleanup_dirs(); // remove destination dir 58 | setup_source(); 59 | setup_dirs(); 60 | // No destination dir 61 | pthread_t thread; 62 | start_backup_thread_with_funs(&thread, get_src(), NULL, simple_poll_fun, NULL, expect_error, NULL, expect_result); 63 | finish_backup_thread(thread); 64 | if (ok && error_count!=1) { 65 | ok=false; 66 | fprintf(stderr, "%s:%d expect error_count==1 but it is %d\n", __FILE__, __LINE__, error_count); 67 | } 68 | cleanup_dirs(); 69 | if (ok) { 70 | pass(); 71 | } else { 72 | fail(); 73 | } 74 | printf(": test6317()\n"); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /backup/tests/open_lseek_write.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | // Test that opens, lseeks, and writes are intercepted by backup and executed while backup is 36 | // still capturing. 37 | 38 | #ident "$Id: f2b34987a733bc663f1a6824d114135cc811dc98 $" 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "backup.h" 50 | #include "backup_test_helpers.h" 51 | 52 | static int verify(void) { 53 | char *src = get_src(); 54 | char *dst = get_dst(); 55 | int r = systemf("diff -r %s %s", src, dst); 56 | free(src); 57 | free(dst); 58 | if (!WIFEXITED(r)) return -1; 59 | if (WEXITSTATUS(r)!=0) return -1; 60 | return 0; 61 | } 62 | 63 | int lseek_write_after_copy(void) { 64 | int result = 0; 65 | int fd = 0; 66 | setup_source(); 67 | setup_dirs(); 68 | setup_destination(); 69 | 70 | // keep backup capturing until after the test executes the 71 | // final lseek and write. 72 | backup_set_keep_capturing(true); 73 | 74 | // start backup 75 | pthread_t thread; 76 | start_backup_thread(&thread); 77 | 78 | // wait for backup copy phase to copy the source file 79 | while (!backup_done_copying()) { 80 | sched_yield(); 81 | } 82 | 83 | // create a source file and write at the beginning of the file 84 | char *src = get_src(); 85 | fd = openf(O_CREAT | O_RDWR, 0777, "%s/my.data", src); 86 | check(fd >= 0); 87 | free(src); 88 | result = write(fd, "Hello World\n", 12); 89 | check(result == 12); 90 | 91 | // write at 1M offset 92 | const off_t next_write_offset = 1<<20; 93 | result = lseek(fd, next_write_offset, SEEK_SET); 94 | check(result == next_write_offset); 95 | result = write(fd, "Cruel World\n", 12); 96 | check(result == 12); 97 | 98 | result = close(fd); 99 | check(result == 0); 100 | 101 | // wait for the backup to finish 102 | backup_set_keep_capturing(false); 103 | finish_backup_thread(thread); 104 | 105 | // verify source and backup files 106 | if(verify()) { 107 | fail(); result = 1; 108 | } else { 109 | pass(); result = 0; 110 | } 111 | return result; 112 | } 113 | 114 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 115 | int result = lseek_write_after_copy(); 116 | return result; 117 | } 118 | -------------------------------------------------------------------------------- /backup/tests/open_prepare_race_6610.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: b701db8a15a5e5c660fc4df40700967a51525327 $" 36 | 37 | /* A race between open() and prepare(). */ 38 | 39 | #include 40 | #include 41 | #include 42 | #include "backup_test_helpers.h" 43 | 44 | static char *src; 45 | 46 | static std::atomic_int n_backups_done = {0}; 47 | static const int n_backups_to_do = 4; 48 | 49 | static void* open_close_loop(void * ignore) { 50 | while (n_backups_done < n_backups_to_do) { 51 | int fd = openf(O_RDONLY|O_CREAT, 0777, "%s/file", src); 52 | check(fd>=0); 53 | int r = close(fd); 54 | check(r==0); 55 | } 56 | return ignore; 57 | } 58 | 59 | int test_main(int argc, const char *argv[] __attribute__((__unused__))) { 60 | check(argc==1); 61 | setup_source(); 62 | src = get_src(); 63 | char *dst = get_dst(); 64 | pthread_t th; 65 | char ignore[1]; 66 | { 67 | int r = pthread_create(&th, NULL, open_close_loop, ignore); 68 | check(r==0); 69 | } 70 | for (int i=0; i. 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 8c8a9f0f28f59a6a2dc116a04be90d2952f22f9a $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include "backup_helgrind.h" 45 | #include "backup.h" 46 | #include "backup_test_helpers.h" 47 | 48 | const char * const WRITTEN_STR = "goodbye\n"; 49 | const int WRITTEN_STR_LEN = 8; 50 | 51 | // 52 | static int verify(void) 53 | { 54 | char *dst = get_dst(); 55 | int backup_fd = openf(O_RDONLY, 0, "%s/bar.data", dst); 56 | check(backup_fd >= 0); 57 | free(dst); 58 | char backup_string[30] = {0}; 59 | int r = read(backup_fd, backup_string, WRITTEN_STR_LEN); 60 | check(r == WRITTEN_STR_LEN); 61 | r = strcmp(WRITTEN_STR, backup_string); 62 | return r; 63 | } 64 | 65 | std::atomic_int write_done = {0}; 66 | 67 | static int write_poll(float progress, const char *progress_string, void *extra) { 68 | check(0<=progress && progress<1); 69 | check(extra==NULL); 70 | check(strlen(progress_string)>8); 71 | while (!write_done) { 72 | sched_yield(); 73 | } 74 | return 0; 75 | } 76 | 77 | 78 | // 79 | static void open_write_close(void) { 80 | TOKUBACKUP_VALGRIND_HG_DISABLE_CHECKING(&write_done, sizeof(write_done)); 81 | 82 | setup_source(); 83 | setup_dirs(); 84 | setup_destination(); 85 | pthread_t thread; 86 | start_backup_thread_with_funs(&thread, get_src(), get_dst(), 87 | write_poll, NULL, 88 | dummy_error, NULL, 89 | 0); 90 | 91 | char *src = get_src(); 92 | int fd = openf(O_WRONLY, 0, "%s/bar.data", src); 93 | check(fd >= 0); 94 | free(src); 95 | int result = write(fd, WRITTEN_STR, WRITTEN_STR_LEN); 96 | check(result == 8); 97 | write_done = 1; // let the poll return, so that the backup will not finish before this write took place. 98 | result = close(fd); 99 | check(result == 0); 100 | 101 | finish_backup_thread(thread); 102 | 103 | if(verify()) { 104 | fail(); 105 | } else { 106 | pass(); 107 | } 108 | printf(": open_write_close()\n"); 109 | } 110 | 111 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 112 | open_write_close(); 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /backup/tests/pwrite_during_backup.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | // Test that pwrites are intercepted during backup and executed on the backup 36 | // file. 37 | 38 | #ident "$Id: e232914c6f69633d99c29e865c47a7af77790f82 $" 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "backup.h" 50 | #include "backup_test_helpers.h" 51 | 52 | static int verify(void) { 53 | char *src = get_src(); 54 | char *dst = get_dst(); 55 | int r = systemf("diff -r %s %s", src, dst); 56 | free(src); 57 | free(dst); 58 | if (!WIFEXITED(r)) return -1; 59 | if (WEXITSTATUS(r)!=0) return -1; 60 | return 0; 61 | } 62 | 63 | int lseek_write_after_copy(void) { 64 | int result = 0; 65 | int fd = 0; 66 | setup_source(); 67 | setup_dirs(); 68 | setup_destination(); 69 | 70 | // keep backup capturing until after the test executes the 71 | // final lseek and write. 72 | backup_set_keep_capturing(true); 73 | 74 | // start backup 75 | pthread_t thread; 76 | start_backup_thread(&thread); 77 | 78 | // create a source file and write at the beginning of the file 79 | char *src = get_src(); 80 | fd = openf(O_CREAT | O_RDWR, 0777, "%s/my.data", src); 81 | check(fd >= 0); 82 | free(src); 83 | result = write(fd, "Hello World\n", 12); 84 | check(result == 12); 85 | 86 | // wait for backup copy phase to copy the source file 87 | while (!backup_done_copying()) { 88 | sched_yield(); 89 | } 90 | 91 | // pwrite at 1M offset 92 | const off_t next_write_offset = 1<<20; 93 | result = pwrite(fd, "Cruel World\n", 12, next_write_offset); 94 | check(result == 12); 95 | 96 | result = close(fd); 97 | check(result == 0); 98 | 99 | // wait for the backup to finish 100 | backup_set_keep_capturing(false); 101 | finish_backup_thread(thread); 102 | 103 | // verify source and backup files 104 | if(verify()) { 105 | fail(); result = 1; 106 | } else { 107 | pass(); result = 0; 108 | } 109 | return result; 110 | } 111 | 112 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 113 | int result = lseek_write_after_copy(); 114 | return result; 115 | } 116 | -------------------------------------------------------------------------------- /backup/tests/read_and_seek.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: b11b5b4589fb8bae2a0baf02fd5dd792d83d6664 $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "backup.h" 47 | #include "backup_test_helpers.h" 48 | 49 | static int verify(void) { 50 | char *src = get_src(); 51 | char *dst = get_dst(); 52 | int r = systemf("diff -r %s %s", src, dst); 53 | free(src); 54 | free(dst); 55 | if (!WIFEXITED(r)) return -1; 56 | if (WEXITSTATUS(r)!=0) return -1; 57 | return 0; 58 | } 59 | 60 | void read_and_seek(void) { 61 | int result = 0; 62 | int fd = 0; 63 | setup_source(); 64 | setup_dirs(); 65 | setup_destination(); 66 | pthread_t thread; 67 | start_backup_thread(&thread); 68 | 69 | char *src = get_src(); 70 | fd = openf(O_CREAT | O_RDWR, 0777, "%s/my.data", src); 71 | check(fd >= 0); 72 | free(src); 73 | result = write(fd, "Hello World\n", 12); 74 | char buf[10]; 75 | result = read(fd, buf, 5); 76 | if (result < 0) { 77 | perror("read failed."); 78 | abort(); 79 | } 80 | 81 | result = lseek(fd, 1, SEEK_CUR); 82 | check(result > 0); 83 | result = write(fd, "Cruel World\n", 12); 84 | check(result > 0); 85 | result = close(fd); 86 | check(result == 0); 87 | 88 | finish_backup_thread(thread); 89 | 90 | if(verify()) { 91 | fail(); 92 | } else { 93 | pass(); 94 | } 95 | printf(": read_and_seek()\n"); 96 | } 97 | 98 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 99 | read_and_seek(); 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /backup/tests/readdirfails_dest_dir.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: f93e35a24e31c09e1b8846b71f53f6e70e47f18a $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | 45 | #include "backup.h" 46 | #include "backup_test_helpers.h" 47 | 48 | // Test for #6317 dest dir is not a directory. 49 | const int expect_result = EINVAL; // 50 | int error_count=0; 51 | bool ok=true; 52 | 53 | static void expect_error(int error_number, const char *error_string, void *error_extra) { 54 | if (error_count!=0) { ok=false; fprintf(stderr, "%s:%d error function called twice\n", __FILE__, __LINE__); } 55 | error_count++; 56 | if (error_number!=expect_result) { ok=false; fprintf(stderr, "%s:%d error_number=%d expected %d\n", __FILE__, __LINE__, error_number, expect_result); } 57 | if (error_string==NULL) { ok=false; fprintf(stderr, "%s:%d expect error_string nonnull\n", __FILE__, __LINE__); } 58 | printf("error_string (expected)=%s\n", error_string); 59 | if (error_extra!=NULL) { ok=false; fprintf(stderr, "%s:%d expect error_extra NULL\n", __FILE__, __LINE__); } 60 | } 61 | 62 | struct dirent *readdir(DIR *dirp __attribute__((unused))) { 63 | // use this version of readdir, which won't work, as expecgted 64 | errno = EINVAL; 65 | return NULL; 66 | } 67 | 68 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 69 | cleanup_dirs(); // remove destination dir 70 | setup_source(); 71 | setup_destination(); // set up the dest 72 | setup_dirs(); 73 | // Dest dir is a file, not a directory 74 | pthread_t thread; 75 | start_backup_thread_with_funs(&thread, get_src(), get_dst(), simple_poll_fun, NULL, expect_error, NULL, expect_result); 76 | finish_backup_thread(thread); 77 | if (ok && error_count!=1) { 78 | ok=false; 79 | fprintf(stderr, "%s:%d expect error_count==1 but it is %d\n", __FILE__, __LINE__, error_count); 80 | } 81 | cleanup_dirs(); 82 | if (ok) { 83 | pass(); 84 | } else { 85 | fail(); 86 | } 87 | printf(": test6317()\n"); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /backup/tests/source_no_permissions_10.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: 72cc2d1052d1fb0bdc3fe2433e9ea4dfdcd49273 $" 36 | 37 | // Test to make sure nothing crashes if the backup source directory has unreadable permissions. 38 | 39 | #include 40 | 41 | #include "backup_test_helpers.h" 42 | 43 | volatile bool saw_error = false; 44 | 45 | static void expect_eacces_error_fun(int error_number, const char *error_string, void *backup_extra __attribute__((unused))) { 46 | fprintf(stderr, "EXPECT ERROR %d: %d (%s)\n", EACCES, error_number, error_string); 47 | check(error_number==EACCES); 48 | saw_error = true; 49 | } 50 | 51 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 52 | char *src = get_src(); 53 | char *dst = get_dst(); 54 | { 55 | int r = systemf("chmod ugo+rwx %s 2> /dev/null", src); 56 | ignore(r); 57 | } 58 | setup_source(); 59 | setup_destination(); 60 | setup_dirs(); 61 | { 62 | int r = systemf("chmod ugo-r %s", src); 63 | check(r==0); 64 | } 65 | { 66 | const char *srcs[1] = {src}; 67 | const char *dsts[1] = {dst}; 68 | int r = tokubackup_create_backup(srcs, dsts, 1, 69 | simple_poll_fun, NULL, 70 | expect_eacces_error_fun, NULL, 71 | NULL, NULL); 72 | check(r==EACCES); 73 | check(saw_error); 74 | } 75 | { 76 | int r = systemf("chmod ugo+rwx %s", src); 77 | check(r==0); 78 | } 79 | cleanup_dirs(); 80 | free(src); 81 | free(dst); 82 | return 0; 83 | } 84 | 85 | 86 | -------------------------------------------------------------------------------- /backup/tests/test1.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 | /*====== 4 | This file is part of Percona TokuBackup. 5 | 6 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 7 | 8 | Percona TokuBackup is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License, version 2, 10 | as published by the Free Software Foundation. 11 | 12 | Percona TokuBackup is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Percona TokuBackup. If not, see . 19 | 20 | ---------------------------------------- 21 | 22 | Percona TokuBackup is free software: you can redistribute it and/or modify 23 | it under the terms of the GNU Affero General Public License, version 3, 24 | as published by the Free Software Foundation. 25 | 26 | Percona TokuBackup is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU Affero General Public License for more details. 30 | 31 | You should have received a copy of the GNU Affero General Public License 32 | along with Percona TokuBackup. If not, see . 33 | ======= */ 34 | 35 | #ident "$Id: e3588fbcb87066375b960c20b123d54a6eefa36e $" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "backup.h" 44 | 45 | #define SRC "b2_src" 46 | #define DST "b2_dst" 47 | 48 | // 49 | static void setup_destination() 50 | { 51 | system("rm -rf " DST); 52 | } 53 | 54 | // 55 | static void setup_source() 56 | { 57 | system("rm -rf " SRC); 58 | system("mkdir " SRC); 59 | system("touch " SRC "/foo"); 60 | system("echo hello > " SRC "/bar.data"); 61 | system("mkdir " SRC "/subdir"); 62 | system("echo there > " SRC "/subdir/sub.data"); 63 | } 64 | 65 | // 66 | int main(int argc, char *argv[]) 67 | { 68 | argc = argc; 69 | argv = argv; 70 | int result = 0; 71 | setup_source(); 72 | setup_destination(); 73 | add_directory(SRC, DST); 74 | start_backup(); 75 | 76 | int fd = 0; 77 | fd = open(SRC "/bar.data", O_WRONLY); 78 | check(fd >= 0); 79 | result = write(fd, "goodbye\n", 8); 80 | check(result == 8); 81 | result = close(fd); 82 | check(result == 0); 83 | 84 | stop_backup(); 85 | return result; 86 | } 87 | -------------------------------------------------------------------------------- /backup/tests/test6128.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: b57ab32ccce4d18c4ef08bfaa98a4aa5cc5f41dc $" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "backup.h" 43 | #include "backup_test_helpers.h" 44 | 45 | #define FIRSTBYTES "first bytes\n" 46 | #define MOREBYTES "more bytes\n" 47 | 48 | int test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 49 | cleanup_dirs(); 50 | setup_source(); 51 | setup_destination(); 52 | 53 | char *src = get_src(); 54 | char *dst = get_dst(); 55 | int fd0 = openf(O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO, "%sfile0", src); 56 | check(fd0>=0); 57 | { 58 | ssize_t r = write(fd0, FIRSTBYTES, sizeof(FIRSTBYTES)-1); 59 | check(r==sizeof(FIRSTBYTES)-1); 60 | } 61 | 62 | pthread_t th; 63 | start_backup_thread(&th); 64 | usleep(10000); 65 | { 66 | ssize_t r = write(fd0, MOREBYTES, sizeof(MOREBYTES)-1); 67 | check(r==sizeof(MOREBYTES)-1); 68 | } 69 | finish_backup_thread(th); 70 | { 71 | int status = systemf("diff -r %s %s", src, dst); 72 | check(status!=-1); 73 | check(WIFEXITED(status)); 74 | check(WEXITSTATUS(status)==0); 75 | } 76 | free(src); 77 | free(dst); 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /backup/tests/test6415_enospc_injection.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: fbab9d9e258327d46323c2c8f02f410d409ec407 $" 34 | 35 | /* Inject enospc. */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "backup_test_helpers.h" 44 | #include "backup_internal.h" 45 | #include "real_syscalls.h" 46 | 47 | static pwrite_fun_t original_pwrite; 48 | 49 | static ssize_t my_pwrite(int fd, const void *buf, size_t nbyte, off_t offset) { 50 | fprintf(stderr, "Doing pwrite on fd=%d\n", fd); // ok to do a write, since we aren't further interposing writes in this test. 51 | return original_pwrite(fd, buf, nbyte, offset); 52 | } 53 | 54 | static write_fun_t original_write; 55 | static ssize_t my_write(int fd, const void *buf, size_t nbyte) { 56 | fprintf(stderr, "Doing write(%d, %p, %ld)\n", fd, buf, nbyte); // ok to do a write, since we aren't further interposing writes in this test. 57 | errno = ENOSPC; 58 | return -1; 59 | //return original_write(fd, buf, nbyte); 60 | } 61 | 62 | int ercount=0; 63 | static void my_error_fun(int e, const char *s, void *ignore) { 64 | check(ignore==NULL); 65 | ercount++; 66 | fprintf(stderr, "Got error %d (I expected errno=%d) (%s)\n", e, ENOSPC, s); 67 | } 68 | 69 | 70 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 71 | setup_source(); 72 | setup_dirs(); 73 | setup_destination(); 74 | 75 | char *src = get_src(); 76 | 77 | original_pwrite = register_pwrite(my_pwrite); 78 | original_write = register_write(my_write); 79 | 80 | backup_set_keep_capturing(true); 81 | pthread_t thread; 82 | 83 | int fd = openf(O_RDWR|O_CREAT, 0777, "%s/my.data", src); 84 | check(fd>=0); 85 | fprintf(stderr, "fd=%d\n", fd); 86 | usleep(10000); 87 | { 88 | ssize_t r = pwrite(fd, "hello", 5, 10); 89 | check(r==5); 90 | } 91 | { 92 | int r = close(fd); 93 | check(r==0); 94 | } 95 | 96 | start_backup_thread_with_funs(&thread, 97 | get_src(), get_dst(), 98 | simple_poll_fun, NULL, 99 | my_error_fun, NULL, 100 | ENOSPC); 101 | 102 | backup_set_keep_capturing(false); 103 | finish_backup_thread(thread); 104 | 105 | free(src); 106 | 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /backup/tests/test6431_postcopy.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: f88b59e18db67e7a5db8a173b00abdd8a48246b5 $" 34 | 35 | /* Inject enospc. */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "backup_test_helpers.h" 43 | #include "backup_internal.h" 44 | #include "real_syscalls.h" 45 | 46 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 47 | setup_source(); 48 | setup_dirs(); 49 | setup_destination(); 50 | 51 | char *src = get_src(); 52 | 53 | backup_set_keep_capturing(true); 54 | pthread_t thread; 55 | 56 | const int n_fds = 20; 57 | int fds[n_fds]; 58 | for (int i=0; i=0); 61 | } 62 | 63 | start_backup_thread(&thread); 64 | 65 | backup_set_keep_capturing(false); 66 | usleep(1000); 67 | printf("said to keep capturing\n"); 68 | 69 | int n_fds_left = n_fds; 70 | int count = 0; 71 | while (n_fds_left) { 72 | int idx = random()%n_fds_left; 73 | int fd = fds[idx]; 74 | fds[idx] = fds[n_fds_left-1]; 75 | n_fds_left--; 76 | 77 | char data[100]; 78 | int len = snprintf(data, sizeof(data), "data_order %d\n", count); 79 | { 80 | ssize_t r = write(fd, data, len); 81 | check(r==len); 82 | } 83 | { 84 | int r = close(fd); 85 | check(r==0); 86 | } 87 | count++; 88 | 89 | } 90 | 91 | finish_backup_thread(thread); 92 | 93 | free(src); 94 | 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /backup/tests/test6478_read_injection.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: b6aac09a0705c9011ef06e9c0085acac6f87d347 $" 34 | 35 | /* Inject enospc. */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include "backup_test_helpers.h" 46 | #include "backup_internal.h" 47 | 48 | static char *src, *dst; 49 | 50 | static void testit(void) { 51 | 52 | setup_source(); 53 | setup_dirs(); 54 | setup_destination(); 55 | 56 | pthread_t thread; 57 | 58 | int fd = openf(O_WRONLY|O_CREAT, 0777, "%s/my.data", src); 59 | check(fd>=0); 60 | fprintf(stderr, "fd=%d\n", fd); 61 | 62 | backup_set_keep_capturing(true); 63 | start_backup_thread_with_funs(&thread, 64 | get_src(), get_dst(), 65 | dummy_poll, NULL, 66 | dummy_error, NULL, 67 | 0); 68 | fprintf(stderr, "The backup is supposedly capturing\n"); 69 | while (!backup_is_capturing()) sched_yield(); // wait for capturing to start 70 | while (!backup_done_copying()) sched_yield(); // then wait for copying to finish 71 | // Now capturing is still running. 72 | { 73 | ssize_t r = write(fd, "hello", 5); 74 | check(r==5); 75 | } 76 | { 77 | char buf[20]; 78 | ssize_t r = read(fd, buf, 20); 79 | printf("r=%ld\n", r); 80 | check(r==-1); 81 | } 82 | { 83 | ssize_t r = write(fd, "good", 4); 84 | check(r==4); 85 | } 86 | fprintf(stderr,"About to start copying\n"); 87 | backup_set_keep_capturing(false); 88 | { 89 | int r = close(fd); 90 | check(r==0); 91 | } 92 | 93 | backup_set_keep_capturing(false); 94 | finish_backup_thread(thread); 95 | { 96 | int fd2 = openf(O_RDWR, 0, "%s/my.data", dst); 97 | check(fd2>=0); 98 | { 99 | struct stat buf; 100 | int r = fstat(fd2, &buf); 101 | check(r==0); 102 | if (buf.st_size!=9) fprintf(stderr, "Expect file size = 9, it is %ld\n", buf.st_size); 103 | check(buf.st_size==9); 104 | } 105 | { 106 | int r = close(fd2); 107 | check(r==0); 108 | } 109 | } 110 | } 111 | 112 | 113 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 114 | src = get_src(); 115 | dst = get_dst(); 116 | 117 | testit(); 118 | 119 | free(src); 120 | free(dst); 121 | return 0; 122 | } 123 | -------------------------------------------------------------------------------- /backup/tests/test_dirsum.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #include "backup_test_helpers.h" 34 | #include "raii-malloc.h" 35 | 36 | static int my_poll(float progress, const char *progress_string, void *poll_extra) { 37 | check(poll_extra==NULL); 38 | fprintf(stderr, "progress %2.f%%: %s\n", progress*100, progress_string); 39 | return 0; 40 | } 41 | 42 | static void simple_error(int errnum, const char *error_string, void *error_extra) { 43 | check(error_extra==NULL); 44 | fprintf(stderr, "backup error: errnum=%d (%s)\n", errnum, error_string); 45 | abort(); 46 | } 47 | 48 | int test_main(int argc __attribute__((unused)), const char *argv[] __attribute__((unused))) { 49 | setup_source(); 50 | setup_destination(); 51 | with_object_to_free src(get_src()); 52 | { 53 | long long v = dirsum(src.value); 54 | //printf("dirsum empty dir is %lld\n", v); 55 | check(v==0); 56 | } 57 | 58 | systemf("echo hello > %s/data", src.value); 59 | { 60 | long long v = dirsum(src.value); 61 | //printf("dirsum 1dir is %lld\n", v); 62 | check(v==6); 63 | } 64 | systemf("mkdir %s/dir;echo foo > %s/dir/data", src.value, src.value); 65 | { 66 | long long v = dirsum(src.value); 67 | //printf("dirsum 2dir is %lld\n", v); 68 | check(v==10); 69 | } 70 | pthread_t thread; 71 | start_backup_thread_with_funs(&thread, get_src(), get_dst(), my_poll, NULL, simple_error, NULL, 0); 72 | finish_backup_thread(thread); 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /backup/tests/throttle_6564.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: 8b3fa9e3fbfce9634c5e4565d11a999db3a10f91 $" 34 | 35 | #include "backup_test_helpers.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | static char *src; 43 | static char *dst; 44 | 45 | 46 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 47 | src = get_src(); 48 | dst = get_dst(); 49 | setup_source(); 50 | setup_destination(); 51 | setup_dirs(); 52 | 53 | pthread_t thread; 54 | const int N = 2; 55 | const int BUFSIZE = 1024; 56 | const int NBUFS = 1024; 57 | unsigned char buf[BUFSIZE]; 58 | for (size_t i=0; i=0); 67 | for (int j=0; j= %6.3fs\n", expected_n_seconds); 88 | check(td >= expected_n_seconds); 89 | 90 | free(src); 91 | free(dst); 92 | return 0; 93 | } 94 | 95 | -------------------------------------------------------------------------------- /backup/tests/unlink_during_copy_test6515.cc: -------------------------------------------------------------------------------- 1 | /*====== 2 | This file is part of Percona TokuBackup. 3 | 4 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 5 | 6 | Percona TokuBackup is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License, version 2, 8 | as published by the Free Software Foundation. 9 | 10 | Percona TokuBackup is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Percona TokuBackup. If not, see . 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: 7556aadc92d1c57d6cc3cf8a709ffed9692bb602 $" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "backup_test_helpers.h" 40 | 41 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 42 | char *src = get_src(); 43 | char *dst = get_dst(); 44 | setup_source(); 45 | setup_destination(); 46 | setup_dirs(); 47 | pthread_t thread; 48 | const int N = 2; 49 | char fname[N][1000]; 50 | int fds[N]; 51 | unsigned char buf[1024]; 52 | for (size_t i=0; i=0); 61 | for (int j=0; j<1024; j++) { 62 | ssize_t r = write(fds[i], buf, sizeof(buf)); 63 | check(r==sizeof(buf)); 64 | } 65 | } 66 | tokubackup_throttle_backup(1L<<19); // half a mebibyte per second, so that's 2 seconds. 67 | start_backup_thread(&thread); 68 | for (int i=0; i. 17 | 18 | ---------------------------------------- 19 | 20 | Percona TokuBackup is free software: you can redistribute it and/or modify 21 | it under the terms of the GNU Affero General Public License, version 3, 22 | as published by the Free Software Foundation. 23 | 24 | Percona TokuBackup is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU Affero General Public License for more details. 28 | 29 | You should have received a copy of the GNU Affero General Public License 30 | along with Percona TokuBackup. If not, see . 31 | ======= */ 32 | 33 | #ident "$Id: 4fbbcf7ae5d9b66c5fd85f64ce46fb44028347ac $" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "backup_test_helpers.h" 40 | 41 | static char *src; 42 | static char *dst; 43 | 44 | 45 | int test_main(int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) { 46 | src = get_src(); 47 | dst = get_dst(); 48 | setup_source(); 49 | setup_destination(); 50 | setup_dirs(); 51 | pthread_t thread; 52 | const int N = 2; 53 | char fname[N][1000]; 54 | int fds[N]; 55 | unsigned char buf[1024]; 56 | for (size_t i=0; i=0); 65 | for (int j=0; j<1024; j++) { 66 | ssize_t r = write(fds[i], buf, sizeof(buf)); 67 | check(r==sizeof(buf)); 68 | } 69 | } 70 | for (int i=0; i 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int fd; 15 | int n_threads = 16; 16 | int n_writes_per_thread=5000; 17 | const int blocksize = 4096; 18 | 19 | static void* runwrites(void *whoamip) { 20 | long whoami = *(long*)whoamip; 21 | char *buf; 22 | { 23 | void *vbuf; 24 | int r = posix_memalign(&vbuf, blocksize, blocksize); 25 | assert(r==0); 26 | buf = (char*)vbuf; 27 | } 28 | for (int i=0; i=0); 48 | pthread_t threads[n_threads]; 49 | long whoami[n_threads]; 50 | for (int i=0; i 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int fd; 15 | int n_threads = 16; 16 | int n_writes_per_thread=5000; 17 | const int blocksize = 4096; 18 | 19 | static void* runwrites(void *whoamip) { 20 | //long whoami = *(long*)whoamip; 21 | char *buf; 22 | { 23 | void *vbuf; 24 | int r = posix_memalign(&vbuf, blocksize, blocksize); 25 | assert(r==0); 26 | buf = (char*)vbuf; 27 | } 28 | for (int i=0; i=0); 45 | pthread_t threads[n_threads]; 46 | long whoami[n_threads]; 47 | for (int i=0; i