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
41
42 // create a ft and put n rows into it
43 // write the ft to the file
44 // verify the rows in the ft
test_sub_block(int n)45 static void test_sub_block(int n) {
46 if (verbose) printf("%s:%d %d\n", __FUNCTION__, __LINE__, n);
47
48 const char *fname = TOKU_TEST_FILENAME;
49 const int nodesize = 4*1024*1024;
50 const int basementnodesize = 128*1024;
51 const enum toku_compression_method compression_method = TOKU_DEFAULT_COMPRESSION_METHOD;
52
53 TOKUTXN const null_txn = 0;
54
55 int error;
56 CACHETABLE ct;
57 FT_HANDLE ft;
58 int i;
59
60 unlink(fname);
61
62 toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr);
63
64 error = toku_open_ft_handle(fname, true, &ft, nodesize, basementnodesize, compression_method, ct, null_txn, toku_builtin_compare_fun);
65 assert(error == 0);
66
67 // insert keys 0, 1, 2, .. (n-1)
68 for (i=0; i<n; i++) {
69 int k = toku_htonl(i);
70 int v = i;
71 DBT key, val;
72 toku_fill_dbt(&key, &k, sizeof k);
73 toku_fill_dbt(&val, &v, sizeof v);
74 toku_ft_insert(ft, &key, &val, 0);
75 assert(error == 0);
76 }
77
78 // write to the file
79 error = toku_close_ft_handle_nolsn(ft, 0);
80 assert(error == 0);
81
82 // verify the ft by walking a cursor through the rows
83 error = toku_open_ft_handle(fname, false, &ft, nodesize, basementnodesize, compression_method, ct, null_txn, toku_builtin_compare_fun);
84 assert(error == 0);
85
86 FT_CURSOR cursor;
87 error = toku_ft_cursor(ft, &cursor, NULL, false, false);
88 assert(error == 0);
89
90 for (i=0; ; i++) {
91 int k = htonl(i);
92 int v = i;
93 struct check_pair pair = {sizeof k, &k, sizeof v, &v, 0};
94 error = toku_ft_cursor_get(cursor, NULL, lookup_checkf, &pair, DB_NEXT);
95 if (error != 0) {
96 assert(pair.call_count==0);
97 break;
98 }
99 assert(pair.call_count==1);
100 }
101 assert(i == n);
102
103 toku_ft_cursor_close(cursor);
104
105 error = toku_close_ft_handle_nolsn(ft, 0);
106 assert(error == 0);
107
108 toku_cachetable_close(&ct);
109 }
110
test_main(int argc,const char * argv[])111 int test_main (int argc , const char *argv[]) {
112 default_parse_args(argc, argv);
113
114 const int meg = 1024*1024;
115 const int row = 32;
116 const int rowspermeg = meg/row;
117
118 test_sub_block(1);
119 test_sub_block(rowspermeg-1);
120 int i;
121 for (i=1; i<8; i++)
122 test_sub_block(rowspermeg*i);
123
124 if (verbose) printf("test ok\n");
125 return 0;
126 }
127