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 // Test toku_ft_handle_stat64 to make sure it works even if the comparison function won't allow an arbitrary prefix of the key to work.
40 
41 
42 #include "test.h"
43 
44 #include <unistd.h>
45 
46 static TOKUTXN const null_txn = 0;
47 
48 const char *fname = TOKU_TEST_FILENAME;
49 CACHETABLE ct;
50 FT_HANDLE t;
51 int keysize = 9;
52 
dont_allow_prefix(DB * db,const DBT * a,const DBT * b)53 static int dont_allow_prefix (DB *db __attribute__((__unused__)), const DBT *a, const DBT *b) {
54     assert(a->size==9 && b->size==9);
55     return toku_keycompare(a->data, a->size, b->data, b->size);
56 }
57 
close_ft_and_ct(void)58 static void close_ft_and_ct (void) {
59     int r;
60     r = toku_close_ft_handle_nolsn(t, 0);          assert(r==0);
61     toku_cachetable_close(&ct);
62 }
63 
open_ft_and_ct(bool unlink_old)64 static void open_ft_and_ct (bool unlink_old) {
65     int r;
66     if (unlink_old) unlink(fname);
67     toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr);
68     r = toku_open_ft_handle(fname, 1, &t, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun);   assert(r==0);
69     toku_ft_set_bt_compare(t, dont_allow_prefix);
70 }
71 
test_4115(void)72 static void test_4115 (void) {
73     uint64_t limit=30000;
74     open_ft_and_ct(true);
75     for (uint64_t i=0; i<limit; i++) {
76 	char key[100],val[100];
77 	snprintf(key, 100, "%08llu", (unsigned long long)2*i+1);
78 	snprintf(val, 100, "%08llu", (unsigned long long)2*i+1);
79 	DBT k,v;
80 	toku_ft_insert(t, toku_fill_dbt(&k, key, 1+strlen(key)), toku_fill_dbt(&v,val, 1+strlen(val)), null_txn);
81     }
82     struct ftstat64_s s;
83     toku_ft_handle_stat64(t, NULL, &s);
84     assert(s.nkeys>0);
85     assert(s.dsize>0);
86     close_ft_and_ct();
87 }
88 
89 int
test_main(int argc,const char * argv[])90 test_main (int argc , const char *argv[]) {
91     default_parse_args(argc, argv);
92 
93     test_4115();
94 
95     if (verbose) printf("test ok\n");
96     return 0;
97 }
98 
99