2013-04-17 00:00:59 -04:00
|
|
|
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
|
2013-04-16 23:59:44 -04:00
|
|
|
#ident "$Id$"
|
2013-04-16 23:59:35 -04:00
|
|
|
#ident "Copyright (c) 2011 Tokutek Inc. All rights reserved."
|
|
|
|
|
|
|
|
// generate a tree with a single leaf node containing unsorted keys
|
|
|
|
// check that brt verify finds them
|
|
|
|
|
|
|
|
#include "includes.h"
|
2013-04-17 00:00:35 -04:00
|
|
|
#include <ft-cachetable-wrappers.h>
|
2013-04-16 23:59:35 -04:00
|
|
|
#include "test.h"
|
|
|
|
|
2013-04-17 00:00:35 -04:00
|
|
|
static FTNODE
|
|
|
|
make_node(FT_HANDLE brt, int height) {
|
|
|
|
FTNODE node = NULL;
|
2013-04-16 23:59:40 -04:00
|
|
|
int n_children = (height == 0) ? 1 : 0;
|
2013-04-17 00:00:35 -04:00
|
|
|
toku_create_new_ftnode(brt, &node, height, n_children);
|
2013-04-16 23:59:41 -04:00
|
|
|
if (n_children) BP_STATE(node,0) = PT_AVAIL;
|
2013-04-16 23:59:35 -04:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-17 00:00:35 -04:00
|
|
|
append_leaf(FTNODE leafnode, void *key, size_t keylen, void *val, size_t vallen) {
|
2013-04-16 23:59:35 -04:00
|
|
|
assert(leafnode->height == 0);
|
|
|
|
|
2013-04-17 00:00:58 -04:00
|
|
|
DBT thekey;
|
|
|
|
toku_fill_dbt(&thekey, key, keylen);
|
|
|
|
DBT theval;
|
|
|
|
toku_fill_dbt(&theval, val, vallen);
|
2013-04-16 23:59:35 -04:00
|
|
|
|
|
|
|
// get an index that we can use to create a new leaf entry
|
2013-04-16 23:59:41 -04:00
|
|
|
uint32_t idx = toku_omt_size(BLB_BUFFER(leafnode, 0));
|
2013-04-16 23:59:35 -04:00
|
|
|
|
|
|
|
// apply an insert to the leaf node
|
2013-04-16 23:59:40 -04:00
|
|
|
MSN msn = next_dummymsn();
|
2013-04-17 00:00:58 -04:00
|
|
|
FT_MSG_S cmd = { FT_INSERT, msn, xids_get_root_xids(), .u={.id = { &thekey, &theval }} };
|
2013-04-17 00:00:35 -04:00
|
|
|
toku_ft_bn_apply_cmd_once(BLB(leafnode, 0), &cmd, idx, NULL, NULL, NULL);
|
2013-04-16 23:59:35 -04:00
|
|
|
|
|
|
|
// dont forget to dirty the node
|
|
|
|
leafnode->dirty = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-17 00:00:35 -04:00
|
|
|
populate_leaf(FTNODE leafnode, int k, int v) {
|
2013-04-16 23:59:35 -04:00
|
|
|
append_leaf(leafnode, &k, sizeof k, &v, sizeof v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_dup_in_leaf(int do_verify) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
// cleanup
|
2013-04-17 00:00:35 -04:00
|
|
|
char fname[]= __SRCFILE__ ".ft_handle";
|
2013-04-16 23:59:35 -04:00
|
|
|
r = unlink(fname);
|
|
|
|
assert(r == 0 || (r == -1 && errno == ENOENT));
|
|
|
|
|
|
|
|
// create a cachetable
|
|
|
|
CACHETABLE ct = NULL;
|
2013-04-17 00:01:08 -04:00
|
|
|
toku_cachetable_create(&ct, 0, ZERO_LSN, NULL_LOGGER);
|
2013-04-16 23:59:35 -04:00
|
|
|
|
|
|
|
// create the brt
|
|
|
|
TOKUTXN null_txn = NULL;
|
2013-04-17 00:00:35 -04:00
|
|
|
FT_HANDLE brt = NULL;
|
|
|
|
r = toku_open_ft_handle(fname, 1, &brt, 1024, 256, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun);
|
2013-04-16 23:59:35 -04:00
|
|
|
assert(r == 0);
|
|
|
|
|
|
|
|
// discard the old root block
|
2013-04-17 00:00:35 -04:00
|
|
|
FTNODE newroot = make_node(brt, 0);
|
2013-04-16 23:59:35 -04:00
|
|
|
populate_leaf(newroot, htonl(2), 1);
|
|
|
|
populate_leaf(newroot, htonl(1), 2);
|
|
|
|
|
|
|
|
// set the new root to point to the new tree
|
2013-04-17 00:00:36 -04:00
|
|
|
toku_ft_set_new_root_blocknum(brt->ft, newroot->thisnodename);
|
2013-04-16 23:59:35 -04:00
|
|
|
|
|
|
|
// unpin the new root
|
2013-04-17 00:00:36 -04:00
|
|
|
toku_unpin_ftnode(brt->ft, newroot);
|
2013-04-16 23:59:35 -04:00
|
|
|
|
|
|
|
if (do_verify) {
|
2013-04-17 00:00:35 -04:00
|
|
|
r = toku_verify_ft(brt);
|
2013-04-16 23:59:35 -04:00
|
|
|
assert(r != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// flush to the file system
|
2013-04-17 00:00:35 -04:00
|
|
|
r = toku_close_ft_handle_nolsn(brt, 0);
|
2013-04-16 23:59:35 -04:00
|
|
|
assert(r == 0);
|
|
|
|
|
|
|
|
// shutdown the cachetable
|
2013-04-17 00:01:08 -04:00
|
|
|
toku_cachetable_close(&ct);
|
2013-04-16 23:59:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
usage(void) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
test_main (int argc , const char *argv[]) {
|
|
|
|
int do_verify = 1;
|
2013-04-17 00:00:17 -04:00
|
|
|
initialize_dummymsn();
|
2013-04-16 23:59:35 -04:00
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
const char *arg = argv[i];
|
|
|
|
if (strcmp(arg, "-v") == 0) {
|
|
|
|
verbose++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(arg, "-q") == 0) {
|
|
|
|
verbose = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(arg, "--verify") == 0 && i+1 < argc) {
|
|
|
|
do_verify = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return usage();
|
|
|
|
}
|
|
|
|
test_dup_in_leaf(do_verify);
|
|
|
|
return 0;
|
|
|
|
}
|