|
| 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$" |
| 4 | +/*====== |
| 5 | +This file is part of PerconaFT. |
| 6 | +
|
| 7 | +
|
| 8 | +Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. |
| 9 | +
|
| 10 | + PerconaFT is free software: you can redistribute it and/or modify |
| 11 | + it under the terms of the GNU General Public License, version 2, |
| 12 | + as published by the Free Software Foundation. |
| 13 | +
|
| 14 | + PerconaFT is distributed in the hope that it will be useful, |
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + GNU General Public License for more details. |
| 18 | +
|
| 19 | + You should have received a copy of the GNU General Public License |
| 20 | + along with PerconaFT. If not, see <http://www.gnu.org/licenses/>. |
| 21 | +
|
| 22 | +---------------------------------------- |
| 23 | +
|
| 24 | + PerconaFT is free software: you can redistribute it and/or modify |
| 25 | + it under the terms of the GNU Affero General Public License, version 3, |
| 26 | + as published by the Free Software Foundation. |
| 27 | +
|
| 28 | + PerconaFT is distributed in the hope that it will be useful, |
| 29 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 30 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 31 | + GNU Affero General Public License for more details. |
| 32 | +
|
| 33 | + You should have received a copy of the GNU Affero General Public License |
| 34 | + along with PerconaFT. If not, see <http://www.gnu.org/licenses/>. |
| 35 | +======= */ |
| 36 | + |
| 37 | +#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." |
| 38 | + |
| 39 | +#include "test.h" |
| 40 | +#include "cachetable/checkpoint.h" |
| 41 | + |
| 42 | +static TOKUTXN const null_txn = 0; |
| 43 | +static const char *fname = TOKU_TEST_FILENAME; |
| 44 | + |
| 45 | +/* test for_backup in ft_close */ |
| 46 | +static void test_in_backup() { |
| 47 | + int r; |
| 48 | + CACHETABLE ct; |
| 49 | + FT_HANDLE ft; |
| 50 | + unlink(fname); |
| 51 | + |
| 52 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 53 | + // TEST1 : for normal |
| 54 | + r = toku_open_ft_handle(fname, 1, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 55 | + assert_zero(r); |
| 56 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 57 | + assert_zero(r); |
| 58 | + |
| 59 | + r = toku_open_ft_handle(fname, 0, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 60 | + assert_zero(r); |
| 61 | + { |
| 62 | + DBT k,v; |
| 63 | + toku_ft_insert(ft, toku_fill_dbt(&k, "hello", 6), toku_fill_dbt(&v, "there", 6), null_txn); |
| 64 | + } |
| 65 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 66 | + assert_zero(r); |
| 67 | + |
| 68 | + r = toku_open_ft_handle(fname, 0, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 69 | + assert_zero(r); |
| 70 | + ft_lookup_and_check_nodup(ft, "hello", "there"); |
| 71 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 72 | + assert_zero(r); |
| 73 | + toku_cachetable_close(&ct); |
| 74 | + |
| 75 | + // TEST2: in fly without checkpoint test |
| 76 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 77 | + r = toku_open_ft_handle(fname, 0, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 78 | + assert_zero(r); |
| 79 | + |
| 80 | + toku_cachetable_begin_backup(ct); |
| 81 | + // this key/value just in fly since we are in backing up |
| 82 | + { |
| 83 | + DBT k,v; |
| 84 | + toku_ft_insert(ft, toku_fill_dbt(&k, "halou", 6), toku_fill_dbt(&v, "not there", 10), null_txn); |
| 85 | + } |
| 86 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 87 | + assert_zero(r); |
| 88 | + |
| 89 | + r = toku_open_ft_handle(fname, 0, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 90 | + assert_zero(r); |
| 91 | + ft_lookup_and_check_nodup(ft, "halou", "not there"); |
| 92 | + |
| 93 | + // because we are in backup, so the FT header is stale after cachefile&cachetable closed |
| 94 | + // here has a leak for this ft evicts from memroy, but that makes sense |
| 95 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 96 | + assert_zero(r); |
| 97 | + toku_cachetable_close(&ct); |
| 98 | + |
| 99 | + // check the in fly key/value, it shouldn't exist |
| 100 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 101 | + r = toku_open_ft_handle(fname, 0, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 102 | + assert_zero(r); |
| 103 | + ft_lookup_and_fail_nodup(ft, (char*)"halou"); |
| 104 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 105 | + assert_zero(r); |
| 106 | + toku_cachetable_end_backup(ct); |
| 107 | + toku_cachetable_close(&ct); |
| 108 | + |
| 109 | + // TEST3: in fly with checkpoint test |
| 110 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 111 | + r = toku_open_ft_handle(fname, 0, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 112 | + assert_zero(r); |
| 113 | + |
| 114 | + toku_cachetable_begin_backup(ct); |
| 115 | + // this key/value just in fly since we are in backup |
| 116 | + { |
| 117 | + DBT k,v; |
| 118 | + toku_ft_insert(ft, toku_fill_dbt(&k, "halou1", 7), toku_fill_dbt(&v, "not there", 10), null_txn); |
| 119 | + } |
| 120 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 121 | + assert_zero(r); |
| 122 | + |
| 123 | + r = toku_open_ft_handle(fname, 0, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 124 | + assert_zero(r); |
| 125 | + ft_lookup_and_check_nodup(ft, "halou1", "not there"); |
| 126 | + |
| 127 | + // because we are in backup, so the FT header is stale after cachefile&cachetable closed |
| 128 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 129 | + assert_zero(r); |
| 130 | + toku_cachetable_end_backup(ct); |
| 131 | + toku_cachetable_close(&ct); |
| 132 | + |
| 133 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 134 | + r = toku_open_ft_handle(fname, 0, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); |
| 135 | + assert_zero(r); |
| 136 | + ft_lookup_and_check_nodup(ft, "halou1", "not there"); |
| 137 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 138 | + assert_zero(r); |
| 139 | + toku_cachetable_close(&ct); |
| 140 | +} |
| 141 | + |
| 142 | +int |
| 143 | +test_main (int argc , const char *argv[]) { |
| 144 | + default_parse_args(argc, argv); |
| 145 | + test_in_backup(); |
| 146 | + if (verbose) printf("test ok\n"); |
| 147 | + return 0; |
| 148 | +} |
0 commit comments