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 /* The goal of this test. Make sure that inserts stay behind deletes. */
40
41
42 #include "test.h"
43
44 #include <ft-cachetable-wrappers.h>
45
46 static TOKUTXN const null_txn = 0;
47
48 enum { NODESIZE = 1024, KSIZE=NODESIZE-100, TOKU_PSIZE=20 };
49
50 CACHETABLE ct;
51 FT_HANDLE t;
52 const char *fname = TOKU_TEST_FILENAME;
53
54 static void
doit(void)55 doit (void) {
56 BLOCKNUM node_leaf, node_internal, node_root;
57
58 int r;
59
60 toku_cachetable_create(&ct, 500*1024*1024, ZERO_LSN, nullptr);
61 unlink(fname);
62 r = toku_open_ft_handle(fname, 1, &t, NODESIZE, NODESIZE/2, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun);
63 assert(r==0);
64
65 toku_testsetup_initialize(); // must precede any other toku_testsetup calls
66
67 r = toku_testsetup_leaf(t, &node_leaf, 1, NULL, NULL);
68 assert(r==0);
69
70 r = toku_testsetup_nonleaf(t, 1, &node_internal, 1, &node_leaf, 0, 0);
71 assert(r==0);
72
73 r = toku_testsetup_nonleaf(t, 1, &node_root, 1, &node_internal, 0, 0);
74 assert(r==0);
75
76 r = toku_testsetup_root(t, node_root);
77 assert(r==0);
78
79 // make a 1MB val
80 uint32_t big_val_size = 1000000;
81 char* XCALLOC_N(big_val_size, big_val);
82 DBT k,v;
83 memset(&k, 0, sizeof(k));
84 memset(&v, 0, sizeof(v));
85 for (int i = 0; i < 100; i++) {
86 toku_ft_insert(t,
87 toku_fill_dbt(&k, "hello", 6),
88 toku_fill_dbt(&v, big_val, big_val_size),
89 null_txn);
90 }
91 toku_free(big_val);
92
93
94 // at this point, we have inserted 100MB of messages, if bug exists,
95 // then node_internal should be huge
96 // we pin it and verify that it is not
97 FTNODE node;
98 ftnode_fetch_extra bfe;
99 bfe.create_for_full_read(t->ft);
100 toku_pin_ftnode(
101 t->ft,
102 node_internal,
103 toku_cachetable_hash(t->ft->cf, node_internal),
104 &bfe,
105 PL_WRITE_EXPENSIVE,
106 &node,
107 true
108 );
109 assert(node->n_children == 1);
110 // simply assert that the buffer is less than 50MB,
111 // we inserted 100MB of data in there.
112 assert(toku_bnc_nbytesinbuf(BNC(node, 0)) < 50*1000*1000);
113 toku_unpin_ftnode(t->ft, node);
114
115 r = toku_close_ft_handle_nolsn(t, 0); assert(r==0);
116 toku_cachetable_close(&ct);
117 }
118
119 int
test_main(int argc,const char * argv[])120 test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
121 doit();
122 return 0;
123 }
124