1
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
5
COPYING CONDITIONS NOTICE:
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of version 2 of the GNU General Public License as
9
published by the Free Software Foundation, and provided that the
10
following conditions are met:
12
* Redistributions of source code must retain this COPYING
13
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
14
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
15
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
18
* Redistributions in binary form must reproduce this COPYING
19
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
20
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
21
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
22
GRANT (below) in the documentation and/or other materials
23
provided with the distribution.
25
You should have received a copy of the GNU General Public License
26
along with this program; if not, write to the Free Software
27
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32
TokuDB, Tokutek Fractal Tree Indexing Library.
33
Copyright (C) 2007-2013 Tokutek, Inc.
37
This program is distributed in the hope that it will be useful, but
38
WITHOUT ANY WARRANTY; without even the implied warranty of
39
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40
General Public License for more details.
42
UNIVERSITY PATENT NOTICE:
44
The technology is licensed by the Massachusetts Institute of
45
Technology, Rutgers State University of New Jersey, and the Research
46
Foundation of State University of New York at Stony Brook under
47
United States of America Serial No. 11/760379 and to the patents
48
and/or patent applications resulting from it.
50
PATENT MARKING NOTICE:
52
This software is covered by US Patent No. 8,185,551.
53
This software is covered by US Patent No. 8,489,638.
57
"THIS IMPLEMENTATION" means the copyrightable works distributed by
58
Tokutek as part of the Fractal Tree project.
60
"PATENT CLAIMS" means the claims of patents that are owned or
61
licensable by Tokutek, both currently or in the future; and that in
62
the absence of this license would be infringed by THIS
63
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
65
"PATENT CHALLENGE" shall mean a challenge to the validity,
66
patentability, enforceability and/or non-infringement of any of the
67
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
69
Tokutek hereby grants to you, for the term and geographical scope of
70
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
71
irrevocable (except as stated in this section) patent license to
72
make, have made, use, offer to sell, sell, import, transfer, and
73
otherwise run, modify, and propagate the contents of THIS
74
IMPLEMENTATION, where such license applies only to the PATENT
75
CLAIMS. This grant does not include claims that would be infringed
76
only as a consequence of further modifications of THIS
77
IMPLEMENTATION. If you or your agent or licensee institute or order
78
or agree to the institution of patent litigation against any entity
79
(including a cross-claim or counterclaim in a lawsuit) alleging that
80
THIS IMPLEMENTATION constitutes direct or contributory patent
81
infringement, or inducement of patent infringement, then any rights
82
granted to you under this License shall terminate as of the date
83
such litigation is filed. If you or your agent or exclusive
84
licensee institute or order or agree to the institution of a PATENT
85
CHALLENGE, then Tokutek may terminate any rights granted to you
89
#ident "Copyright (c) 2011-2013 Tokutek Inc. All rights reserved."
91
// generate fractal trees with a given height, fanout, and number of leaf elements per leaf.
92
// jam the child buffers with inserts.
93
// this code can be used as a template to build broken trees
95
// This program (copied from make-tree.c) creates a tree with bad msns by commenting out
96
// the setting of the msn:
98
// To correctly set msn per node:
99
// - set in each non-leaf when message is injected into node (see insert_into_child_buffer())
100
// - set in each leaf node (see append_leaf())
101
// - set in root node (set test_make_tree())
105
#include <ft-cachetable-wrappers.h>
109
make_node(FT_HANDLE brt, int height) {
111
int n_children = (height == 0) ? 1 : 0;
112
toku_create_new_ftnode(brt, &node, height, n_children);
113
if (n_children) BP_STATE(node,0) = PT_AVAIL;
118
append_leaf(FTNODE leafnode, void *key, size_t keylen, void *val, size_t vallen) {
119
assert(leafnode->height == 0);
121
DBT thekey; toku_fill_dbt(&thekey, key, keylen);
122
DBT theval; toku_fill_dbt(&theval, val, vallen);
124
// get an index that we can use to create a new leaf entry
125
uint32_t idx = BLB_DATA(leafnode, 0)->omt_size();
127
MSN msn = next_dummymsn();
129
// apply an insert to the leaf node
130
FT_MSG_S cmd = { FT_INSERT, msn, xids_get_root_xids(), .u={.id = { &thekey, &theval }} };
131
toku_ft_bn_apply_cmd_once(BLB(leafnode, 0), &cmd, idx, NULL, TXNID_NONE, make_gc_info(false), NULL, NULL);
133
// Create bad tree (don't do following):
134
// leafnode->max_msn_applied_to_node = msn;
136
// dont forget to dirty the node
141
populate_leaf(FTNODE leafnode, int seq, int n, int *minkey, int *maxkey) {
142
for (int i = 0; i < n; i++) {
143
int k = htonl(seq + i);
145
append_leaf(leafnode, &k, sizeof k, &v, sizeof v);
147
*minkey = htonl(seq);
148
*maxkey = htonl(seq + n - 1);
152
insert_into_child_buffer(FT_HANDLE brt, FTNODE node, int childnum, int minkey, int maxkey) {
153
for (unsigned int val = htonl(minkey); val <= htonl(maxkey); val++) {
154
MSN msn = next_dummymsn();
155
unsigned int key = htonl(val);
156
DBT thekey; toku_fill_dbt(&thekey, &key, sizeof key);
157
DBT theval; toku_fill_dbt(&theval, &val, sizeof val);
158
toku_ft_append_to_child_buffer(brt->ft->compare_fun, NULL, node, childnum, FT_INSERT, msn, xids_get_root_xids(), true, &thekey, &theval);
160
// Create bad tree (don't do following):
161
// node->max_msn_applied_to_node = msn;
166
make_tree(FT_HANDLE brt, int height, int fanout, int nperleaf, int *seq, int *minkey, int *maxkey) {
169
node = make_node(brt, 0);
170
populate_leaf(node, *seq, nperleaf, minkey, maxkey);
173
node = make_node(brt, height);
174
int minkeys[fanout], maxkeys[fanout];
175
for (int childnum = 0; childnum < fanout; childnum++) {
176
FTNODE child = make_tree(brt, height-1, fanout, nperleaf, seq, &minkeys[childnum], &maxkeys[childnum]);
178
toku_ft_nonleaf_append_child(node, child, NULL);
180
int k = maxkeys[childnum-1]; // use the max of the left tree
182
toku_ft_nonleaf_append_child(node, child, toku_fill_dbt(&pivotkey, &k, sizeof k));
184
toku_unpin_ftnode(brt->ft, child);
185
insert_into_child_buffer(brt, node, childnum, minkeys[childnum], maxkeys[childnum]);
187
*minkey = minkeys[0];
188
*maxkey = maxkeys[0];
189
for (int i = 1; i < fanout; i++) {
190
if (memcmp(minkey, &minkeys[i], sizeof minkeys[i]) > 0)
191
*minkey = minkeys[i];
192
if (memcmp(maxkey, &maxkeys[i], sizeof maxkeys[i]) < 0)
193
*maxkey = maxkeys[i];
200
deleted_row(UU() DB *db, UU() DBT *key, UU() DBT *val) {
204
test_make_tree(int height, int fanout, int nperleaf, int do_verify) {
208
const char *fname = TOKU_TEST_FILENAME;
210
assert(r == 0 || (r == -1 && errno == ENOENT));
212
// create a cachetable
213
CACHETABLE ct = NULL;
214
toku_cachetable_create(&ct, 0, ZERO_LSN, NULL_LOGGER);
217
TOKUTXN null_txn = NULL;
218
FT_HANDLE brt = NULL;
219
r = toku_open_ft_handle(fname, 1, &brt, 1024, 256, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun);
223
int seq = 0, minkey, maxkey;
224
FTNODE newroot = make_tree(brt, height, fanout, nperleaf, &seq, &minkey, &maxkey);
226
// set the new root to point to the new tree
227
toku_ft_set_new_root_blocknum(brt->ft, newroot->thisnodename);
229
// Create bad tree (don't do following):
230
// newroot->max_msn_applied_to_node = last_dummymsn(); // capture msn of last message injected into tree
232
// unpin the new root
233
toku_unpin_ftnode(brt->ft, newroot);
236
r = toku_verify_ft(brt);
240
// flush to the file system
241
r = toku_close_ft_handle_nolsn(brt, 0);
244
// shutdown the cachetable
245
toku_cachetable_close(&ct);
254
test_main (int argc , const char *argv[]) {
255
initialize_dummymsn();
260
for (int i = 1; i < argc; i++) {
261
const char *arg = argv[i];
262
if (strcmp(arg, "-v") == 0) {
266
if (strcmp(arg, "-q") == 0) {
270
if (strcmp(arg, "--height") == 0 && i+1 < argc) {
271
height = atoi(argv[++i]);
274
if (strcmp(arg, "--fanout") == 0 && i+1 < argc) {
275
fanout = atoi(argv[++i]);
278
if (strcmp(arg, "--nperleaf") == 0 && i+1 < argc) {
279
nperleaf = atoi(argv[++i]);
282
if (strcmp(arg, "--verify") == 0 && i+1 < argc) {
283
do_verify = atoi(argv[++i]);
288
test_make_tree(height, fanout, nperleaf, do_verify);