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 // it used to be the case that we copied the left and right keys of a
40 // range to be prelocked but never freed them, this test checks that they
41 // are freed (as of this time, this happens in ftnode_fetch_extra::destroy())
42 
43 #include "test.h"
44 
45 
46 
47 static const char *fname = TOKU_TEST_FILENAME;
48 
49 static TOKUTXN const null_txn = 0;
50 static int const nodesize = 1<<12, basementnodesize = 1<<9;
51 static const enum toku_compression_method compression_method = TOKU_DEFAULT_COMPRESSION_METHOD;
52 static int const count = 1000;
53 
54 static int
string_cmp(DB * UU (db),const DBT * a,const DBT * b)55 string_cmp(DB* UU(db), const DBT *a, const DBT *b)
56 {
57     return strcmp((char*)a->data, (char*)b->data);
58 }
59 
60 static int
found(uint32_t UU (keylen),const void * key,uint32_t UU (vallen),const void * UU (val),void * UU (extra),bool lock_only)61 found(uint32_t UU(keylen), const void *key, uint32_t UU(vallen), const void *UU(val), void *UU(extra), bool lock_only)
62 {
63     assert(key != NULL && !lock_only);
64     return 0;
65 }
66 
67 int
test_main(int argc,const char * argv[])68 test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
69 
70     CACHETABLE ct;
71     FT_HANDLE t;
72 
73     toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr);
74     unlink(fname);
75     int r = toku_open_ft_handle(fname, 1, &t, nodesize, basementnodesize, compression_method, ct, null_txn, string_cmp); assert(r==0);
76 
77     for (int i = 0; i < count; ++i) {
78         char key[100],val[100];
79         DBT k,v;
80         snprintf(key, 100, "hello%d", i);
81         snprintf(val, 100, "there%d", i);
82         toku_ft_insert(t, toku_fill_dbt(&k, key, 1+strlen(key)), toku_fill_dbt(&v, val, 1+strlen(val)), null_txn);
83     }
84     r = toku_close_ft_handle_nolsn(t, 0); assert(r == 0);
85     toku_cachetable_close(&ct);
86 
87     toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr);
88     r = toku_open_ft_handle(fname, 1, &t, nodesize, basementnodesize, compression_method, ct, null_txn, string_cmp); assert(r == 0);
89 
90     for (int n = 0; n < count/100; ++n) {
91         int i = n * 100;
92         FT_CURSOR c;
93         char lkey[100],rkey[100];
94         DBT lk, rk;
95         r = toku_ft_cursor(t, &c, null_txn, false, false); assert(r == 0);
96         snprintf(lkey, 100, "hello%d", i);
97         snprintf(rkey, 100, "hello%d", i + 100);
98         toku_ft_cursor_set_range_lock(c, toku_fill_dbt(&lk, lkey, 1+strlen(lkey)),
99                                        toku_fill_dbt(&rk, rkey, 1+strlen(rkey)),
100                                        false, false, 0);
101         r = toku_ft_cursor_set(c, &lk, found, NULL); assert(r == 0);
102         for (int j = 0; j < 100; ++j) {
103             r = toku_ft_cursor_next(c, found, NULL); assert(r == 0);
104         }
105         toku_ft_cursor_close(c);
106     }
107 
108     r = toku_close_ft_handle_nolsn(t, 0); assert(r == 0);
109     toku_cachetable_close(&ct);
110 
111     return 0;
112 }
113