|
| 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 \ |
| 38 | + "Copyright (c) 2006, 2017, Percona and/or its affiliates. All rights reserved." |
| 39 | + |
| 40 | +#include "cachetable/checkpoint.h" |
| 41 | +#include "test.h" |
| 42 | + |
| 43 | +static TOKUTXN const null_txn = 0; |
| 44 | +static const char *fname = TOKU_TEST_FILENAME; |
| 45 | + |
| 46 | +/* test for_backup in ft_close */ |
| 47 | +static void test_in_backup() { |
| 48 | + int r; |
| 49 | + CACHETABLE ct; |
| 50 | + FT_HANDLE ft; |
| 51 | + unlink(fname); |
| 52 | + |
| 53 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 54 | + // TEST1 : for normal |
| 55 | + r = toku_open_ft_handle(fname, 1, &ft, 1 << 12, 1 << 9, |
| 56 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 57 | + toku_builtin_compare_fun); |
| 58 | + assert_zero(r); |
| 59 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 60 | + assert_zero(r); |
| 61 | + |
| 62 | + r = toku_open_ft_handle(fname, 0, &ft, 1 << 12, 1 << 9, |
| 63 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 64 | + toku_builtin_compare_fun); |
| 65 | + assert_zero(r); |
| 66 | + { |
| 67 | + DBT k, v; |
| 68 | + toku_ft_insert(ft, toku_fill_dbt(&k, "hello", 6), |
| 69 | + toku_fill_dbt(&v, "there", 6), null_txn); |
| 70 | + } |
| 71 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 72 | + assert_zero(r); |
| 73 | + |
| 74 | + r = toku_open_ft_handle(fname, 0, &ft, 1 << 12, 1 << 9, |
| 75 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 76 | + toku_builtin_compare_fun); |
| 77 | + assert_zero(r); |
| 78 | + ft_lookup_and_check_nodup(ft, "hello", "there"); |
| 79 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 80 | + assert_zero(r); |
| 81 | + toku_cachetable_close(&ct); |
| 82 | + |
| 83 | + // TEST2: in fly without checkpoint test |
| 84 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 85 | + r = toku_open_ft_handle(fname, 0, &ft, 1 << 12, 1 << 9, |
| 86 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 87 | + toku_builtin_compare_fun); |
| 88 | + assert_zero(r); |
| 89 | + |
| 90 | + toku_cachetable_begin_backup(ct); |
| 91 | + // this key/value just in fly since we are in backing up |
| 92 | + { |
| 93 | + DBT k, v; |
| 94 | + toku_ft_insert(ft, toku_fill_dbt(&k, "halou", 6), |
| 95 | + toku_fill_dbt(&v, "not there", 10), null_txn); |
| 96 | + } |
| 97 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 98 | + assert_zero(r); |
| 99 | + |
| 100 | + r = toku_open_ft_handle(fname, 0, &ft, 1 << 12, 1 << 9, |
| 101 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 102 | + toku_builtin_compare_fun); |
| 103 | + assert_zero(r); |
| 104 | + ft_lookup_and_check_nodup(ft, "halou", "not there"); |
| 105 | + |
| 106 | + // because we are in backup, so the FT header is stale after |
| 107 | + // cachefile&cachetable closed |
| 108 | + // here has a leak for this ft evicts from memroy, but that makes sense |
| 109 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 110 | + assert_zero(r); |
| 111 | + toku_cachetable_close(&ct); |
| 112 | + |
| 113 | + // check the in fly key/value, it shouldn't exist |
| 114 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 115 | + r = toku_open_ft_handle(fname, 0, &ft, 1 << 12, 1 << 9, |
| 116 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 117 | + toku_builtin_compare_fun); |
| 118 | + assert_zero(r); |
| 119 | + ft_lookup_and_fail_nodup(ft, (char *)"halou"); |
| 120 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 121 | + assert_zero(r); |
| 122 | + toku_cachetable_end_backup(ct); |
| 123 | + toku_cachetable_close(&ct); |
| 124 | + |
| 125 | + // TEST3: in fly with checkpoint test |
| 126 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 127 | + r = toku_open_ft_handle(fname, 0, &ft, 1 << 12, 1 << 9, |
| 128 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 129 | + toku_builtin_compare_fun); |
| 130 | + assert_zero(r); |
| 131 | + |
| 132 | + toku_cachetable_begin_backup(ct); |
| 133 | + // this key/value just in fly since we are in backup |
| 134 | + { |
| 135 | + DBT k, v; |
| 136 | + toku_ft_insert(ft, toku_fill_dbt(&k, "halou1", 7), |
| 137 | + toku_fill_dbt(&v, "not there", 10), null_txn); |
| 138 | + } |
| 139 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 140 | + assert_zero(r); |
| 141 | + |
| 142 | + r = toku_open_ft_handle(fname, 0, &ft, 1 << 12, 1 << 9, |
| 143 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 144 | + toku_builtin_compare_fun); |
| 145 | + assert_zero(r); |
| 146 | + ft_lookup_and_check_nodup(ft, "halou1", "not there"); |
| 147 | + |
| 148 | + // because we are in backup, so the FT header is stale after |
| 149 | + // cachefile&cachetable closed |
| 150 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 151 | + assert_zero(r); |
| 152 | + toku_cachetable_end_backup(ct); |
| 153 | + toku_cachetable_close(&ct); |
| 154 | + |
| 155 | + toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr); |
| 156 | + r = toku_open_ft_handle(fname, 0, &ft, 1 << 12, 1 << 9, |
| 157 | + TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, |
| 158 | + toku_builtin_compare_fun); |
| 159 | + assert_zero(r); |
| 160 | + ft_lookup_and_check_nodup(ft, "halou1", "not there"); |
| 161 | + r = toku_close_ft_handle_nolsn(ft, 0); |
| 162 | + assert_zero(r); |
| 163 | + toku_cachetable_close(&ct); |
| 164 | +} |
| 165 | + |
| 166 | +int test_main(int argc, const char *argv[]) { |
| 167 | + default_parse_args(argc, argv); |
| 168 | + test_in_backup(); |
| 169 | + if (verbose) |
| 170 | + printf("test ok\n"); |
| 171 | + return 0; |
| 172 | +} |
0 commit comments