2007-11-29 14:18:54 +00:00
|
|
|
/* -*- mode: C; c-basic-offset: 4 -*- */
|
2008-01-24 15:10:32 +00:00
|
|
|
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
|
2007-11-29 14:18:54 +00:00
|
|
|
|
2013-04-16 23:57:32 -04:00
|
|
|
#include "test.h"
|
|
|
|
|
2013-04-16 23:57:20 -04:00
|
|
|
#include "includes.h"
|
2007-07-13 19:37:47 +00:00
|
|
|
|
2013-04-16 23:59:07 -04:00
|
|
|
static void
|
|
|
|
test_serialize_leaf(void) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
int fd = open(__FILE__ ".brt", O_RDWR|O_CREAT|O_BINARY, S_IRWXU|S_IRWXG|S_IRWXO); assert(fd >= 0);
|
|
|
|
|
|
|
|
r = close(fd); assert(r != -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_serialize_nonleaf(void) {
|
2007-08-01 02:37:21 +00:00
|
|
|
// struct brt source_brt;
|
2013-04-16 23:59:07 -04:00
|
|
|
const int nodesize = 1024;
|
2007-08-01 02:37:21 +00:00
|
|
|
struct brtnode sn, *dn;
|
2013-04-16 23:59:07 -04:00
|
|
|
|
|
|
|
int fd = open(__FILE__ ".brt", O_RDWR|O_CREAT|O_BINARY, S_IRWXU|S_IRWXG|S_IRWXO); assert(fd >= 0);
|
|
|
|
|
2007-07-13 19:37:47 +00:00
|
|
|
int r;
|
|
|
|
|
2007-08-01 02:37:21 +00:00
|
|
|
// source_brt.fd=fd;
|
|
|
|
char *hello_string;
|
|
|
|
sn.nodesize = nodesize;
|
2008-06-15 17:09:14 +00:00
|
|
|
sn.ever_been_written = 0;
|
2007-11-27 15:22:56 +00:00
|
|
|
sn.flags = 0x11223344;
|
2013-04-16 23:57:18 -04:00
|
|
|
sn.thisnodename.b = 20;
|
2008-07-27 22:16:49 +00:00
|
|
|
sn.layout_version = BRT_LAYOUT_VERSION;
|
2013-04-16 23:58:01 -04:00
|
|
|
sn.layout_version_original = BRT_LAYOUT_VERSION;
|
2007-07-13 19:37:47 +00:00
|
|
|
sn.height = 1;
|
|
|
|
sn.u.n.n_children = 2;
|
2007-11-27 18:16:45 +00:00
|
|
|
hello_string = toku_strdup("hello");
|
2008-03-06 21:46:57 +00:00
|
|
|
MALLOC_N(2, sn.u.n.childinfos);
|
|
|
|
MALLOC_N(1, sn.u.n.childkeys);
|
2007-11-27 18:16:45 +00:00
|
|
|
sn.u.n.childkeys[0] = kv_pair_malloc(hello_string, 6, 0, 0);
|
2007-07-13 19:37:47 +00:00
|
|
|
sn.u.n.totalchildkeylens = 6;
|
2013-04-16 23:57:18 -04:00
|
|
|
BNC_BLOCKNUM(&sn, 0).b = 30;
|
|
|
|
BNC_BLOCKNUM(&sn, 1).b = 35;
|
2013-04-16 23:57:47 -04:00
|
|
|
BNC_SUBTREE_ESTIMATES(&sn, 0).ndata = random() + (((long long)random())<<32);
|
|
|
|
BNC_SUBTREE_ESTIMATES(&sn, 1).ndata = random() + (((long long)random())<<32);
|
|
|
|
BNC_SUBTREE_ESTIMATES(&sn, 0).nkeys = random() + (((long long)random())<<32);
|
|
|
|
BNC_SUBTREE_ESTIMATES(&sn, 1).nkeys = random() + (((long long)random())<<32);
|
|
|
|
BNC_SUBTREE_ESTIMATES(&sn, 0).dsize = random() + (((long long)random())<<32);
|
|
|
|
BNC_SUBTREE_ESTIMATES(&sn, 1).dsize = random() + (((long long)random())<<32);
|
2013-04-16 23:57:54 -04:00
|
|
|
BNC_SUBTREE_ESTIMATES(&sn, 0).exact = (BOOL)(random()%2 != 0);
|
|
|
|
BNC_SUBTREE_ESTIMATES(&sn, 1).exact = (BOOL)(random()%2 != 0);
|
2008-01-31 22:05:43 +00:00
|
|
|
r = toku_fifo_create(&BNC_BUFFER(&sn,0)); assert(r==0);
|
|
|
|
r = toku_fifo_create(&BNC_BUFFER(&sn,1)); assert(r==0);
|
Addresses #1125 Merged nested transactions from temporary merge branch into main.
Current tests fail (not regressions, they fail as of 13461)
* {{{x1.tdbrun}}}
* {{{test_log(2,3,4,5,6,7,8,9,10).recover}}}
* {{{test-recover(1,2,3).tdbrun}}}
* {{{test1324.tdbrun}}}
ULE_DEBUG disabled (defined to 0) Can be re-enabled for test purposes (set to 1).
refs [t:1125]
Merging into the temp branch (tokudb.main_13461+1125)
{{{svn merge --accept=postpone -r 12527:13461 ../tokudb.1125 ./}}}
Merging into main
{{{svn merge --accept=postpone -r13462:13463 ../tokudb.main_13461+1125/ ./}}}
git-svn-id: file:///svn/toku/tokudb@13464 c7de825b-a66e-492c-adef-691d508d4ae1
2013-04-16 23:57:56 -04:00
|
|
|
//Create XIDS
|
|
|
|
XIDS xids_0 = xids_get_root_xids();
|
|
|
|
XIDS xids_123;
|
|
|
|
XIDS xids_234;
|
|
|
|
r = xids_create_child(xids_0, &xids_123, (TXNID)123);
|
|
|
|
CKERR(r);
|
|
|
|
r = xids_create_child(xids_123, &xids_234, (TXNID)234);
|
|
|
|
CKERR(r);
|
|
|
|
|
2013-04-16 23:59:37 -04:00
|
|
|
r = toku_fifo_enq(BNC_BUFFER(&sn,0), "a", 2, "aval", 5, BRT_NONE, xids_0); assert(r==0);
|
|
|
|
r = toku_fifo_enq(BNC_BUFFER(&sn,0), "b", 2, "bval", 5, BRT_NONE, xids_123); assert(r==0);
|
|
|
|
r = toku_fifo_enq(BNC_BUFFER(&sn,1), "x", 2, "xval", 5, BRT_NONE, xids_234); assert(r==0);
|
Addresses #1125 Merged nested transactions from temporary merge branch into main.
Current tests fail (not regressions, they fail as of 13461)
* {{{x1.tdbrun}}}
* {{{test_log(2,3,4,5,6,7,8,9,10).recover}}}
* {{{test-recover(1,2,3).tdbrun}}}
* {{{test1324.tdbrun}}}
ULE_DEBUG disabled (defined to 0) Can be re-enabled for test purposes (set to 1).
refs [t:1125]
Merging into the temp branch (tokudb.main_13461+1125)
{{{svn merge --accept=postpone -r 12527:13461 ../tokudb.1125 ./}}}
Merging into main
{{{svn merge --accept=postpone -r13462:13463 ../tokudb.main_13461+1125/ ./}}}
git-svn-id: file:///svn/toku/tokudb@13464 c7de825b-a66e-492c-adef-691d508d4ae1
2013-04-16 23:57:56 -04:00
|
|
|
BNC_NBYTESINBUF(&sn, 0) = 2*(BRT_CMD_OVERHEAD+KEY_VALUE_OVERHEAD+2+5) + xids_get_serialize_size(xids_0) + xids_get_serialize_size(xids_123);
|
|
|
|
BNC_NBYTESINBUF(&sn, 1) = 1*(BRT_CMD_OVERHEAD+KEY_VALUE_OVERHEAD+2+5) + xids_get_serialize_size(xids_234);
|
|
|
|
sn.u.n.n_bytes_in_buffers = 3*(BRT_CMD_OVERHEAD+KEY_VALUE_OVERHEAD+2+5) + xids_get_serialize_size(xids_0) + xids_get_serialize_size(xids_123) + xids_get_serialize_size(xids_234);
|
|
|
|
//Cleanup:
|
|
|
|
xids_destroy(&xids_0);
|
|
|
|
xids_destroy(&xids_123);
|
|
|
|
xids_destroy(&xids_234);
|
2007-07-13 19:37:47 +00:00
|
|
|
|
2013-04-16 23:57:18 -04:00
|
|
|
struct brt *XMALLOC(brt);
|
2013-04-16 23:57:48 -04:00
|
|
|
struct brt_header *XCALLOC(brt_h);
|
2013-04-16 23:57:18 -04:00
|
|
|
brt->h = brt_h;
|
2013-04-16 23:57:47 -04:00
|
|
|
brt_h->type = BRTHEADER_CURRENT;
|
2013-04-16 23:57:38 -04:00
|
|
|
brt_h->panic = 0; brt_h->panic_string = 0;
|
2013-04-16 23:57:41 -04:00
|
|
|
toku_blocktable_create_new(&brt_h->blocktable);
|
2013-04-16 23:57:47 -04:00
|
|
|
//Want to use block #20
|
|
|
|
BLOCKNUM b = make_blocknum(0);
|
|
|
|
while (b.b < 20) {
|
|
|
|
toku_allocate_blocknum(brt_h->blocktable, &b, brt_h);
|
|
|
|
}
|
|
|
|
assert(b.b == 20);
|
|
|
|
|
2013-04-16 23:57:18 -04:00
|
|
|
{
|
2013-04-16 23:57:47 -04:00
|
|
|
DISKOFF offset;
|
|
|
|
DISKOFF size;
|
|
|
|
toku_blocknum_realloc_on_disk(brt_h->blocktable, b, 100, &offset, brt_h, FALSE);
|
|
|
|
assert(offset==BLOCK_ALLOCATOR_TOTAL_HEADER_RESERVE);
|
|
|
|
|
|
|
|
toku_translate_blocknum_to_offset_size(brt_h->blocktable, b, &offset, &size);
|
|
|
|
assert(offset == BLOCK_ALLOCATOR_TOTAL_HEADER_RESERVE);
|
|
|
|
assert(size == 100);
|
2013-04-16 23:57:18 -04:00
|
|
|
}
|
|
|
|
|
2013-04-16 23:57:47 -04:00
|
|
|
r = toku_serialize_brtnode_to(fd, make_blocknum(20), &sn, brt->h, 1, 1, FALSE);
|
2013-04-16 23:57:44 -04:00
|
|
|
assert(r==0);
|
2013-04-16 23:57:18 -04:00
|
|
|
|
2013-04-16 23:57:18 -04:00
|
|
|
r = toku_deserialize_brtnode_from(fd, make_blocknum(20), 0/*pass zero for hash*/, &dn, brt_h);
|
2007-11-14 17:58:38 +00:00
|
|
|
assert(r==0);
|
2007-08-01 02:37:21 +00:00
|
|
|
|
2013-04-16 23:57:18 -04:00
|
|
|
assert(dn->thisnodename.b==20);
|
|
|
|
|
2008-07-27 22:16:49 +00:00
|
|
|
assert(dn->layout_version ==BRT_LAYOUT_VERSION);
|
2013-04-16 23:58:01 -04:00
|
|
|
assert(dn->layout_version_original ==BRT_LAYOUT_VERSION);
|
|
|
|
assert(dn->layout_version_read_from_disk ==BRT_LAYOUT_VERSION);
|
2007-07-13 19:37:47 +00:00
|
|
|
assert(dn->height == 1);
|
|
|
|
assert(dn->u.n.n_children==2);
|
2007-11-27 18:16:45 +00:00
|
|
|
assert(strcmp(kv_pair_key(dn->u.n.childkeys[0]), "hello")==0);
|
2013-04-16 23:59:21 -04:00
|
|
|
assert(toku_brt_pivot_key_len(dn->u.n.childkeys[0])==6);
|
2007-07-13 19:37:47 +00:00
|
|
|
assert(dn->u.n.totalchildkeylens==6);
|
2013-04-16 23:57:18 -04:00
|
|
|
assert(BNC_BLOCKNUM(dn,0).b==30);
|
|
|
|
assert(BNC_BLOCKNUM(dn,1).b==35);
|
2007-11-29 15:09:14 +00:00
|
|
|
toku_brtnode_free(&dn);
|
2007-08-01 02:37:21 +00:00
|
|
|
|
2007-11-27 18:16:45 +00:00
|
|
|
kv_pair_free(sn.u.n.childkeys[0]);
|
2007-08-01 02:37:21 +00:00
|
|
|
toku_free(hello_string);
|
2008-01-31 22:05:43 +00:00
|
|
|
toku_fifo_free(&BNC_BUFFER(&sn,0));
|
|
|
|
toku_fifo_free(&BNC_BUFFER(&sn,1));
|
2008-04-02 23:40:36 +00:00
|
|
|
toku_free(sn.u.n.childinfos);
|
|
|
|
toku_free(sn.u.n.childkeys);
|
2013-04-16 23:57:18 -04:00
|
|
|
|
2013-04-16 23:57:47 -04:00
|
|
|
toku_block_free(brt_h->blocktable, BLOCK_ALLOCATOR_TOTAL_HEADER_RESERVE);
|
2013-04-16 23:57:41 -04:00
|
|
|
toku_blocktable_destroy(&brt_h->blocktable);
|
2013-04-16 23:57:18 -04:00
|
|
|
toku_free(brt_h);
|
|
|
|
toku_free(brt);
|
2007-07-13 19:37:47 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 23:57:32 -04:00
|
|
|
int
|
|
|
|
test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
|
2007-11-29 15:34:49 +00:00
|
|
|
toku_memory_check = 1;
|
2013-04-16 23:59:07 -04:00
|
|
|
test_serialize_leaf();
|
|
|
|
test_serialize_nonleaf();
|
2007-07-13 19:37:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|