2013-04-16 23:57:48 -04:00
# ident "$Id$"
2013-04-16 23:59:09 -04:00
# ident "Copyright (c) 2007-2010 Tokutek Inc. All rights reserved."
2013-04-16 23:57:48 -04:00
# ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11 / 760379 and to the patents and / or patent applications resulting from it."
2013-04-16 23:57:20 -04:00
# include "includes.h"
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
# include "ule.h"
2008-03-05 18:34:32 +00:00
2013-04-16 23:59:40 -04:00
// dummymsn needed to simulate msn because messages are injected at a lower level than toku_brt_root_put_cmd()
# define MIN_DUMMYMSN ((MSN) {(uint64_t)1<<48})
static MSN dummymsn ;
static int testsetup_initialized = 0 ;
// Must be called before any other test_setup_xxx() functions are called.
void
toku_testsetup_initialize ( void ) {
if ( testsetup_initialized = = 0 ) {
testsetup_initialized = 1 ;
dummymsn = MIN_DUMMYMSN ;
}
}
static MSN
next_dummymsn ( void ) {
+ + ( dummymsn . msn ) ;
return dummymsn ;
}
2013-04-16 23:58:06 -04:00
BOOL ignore_if_was_already_open ;
2013-04-16 23:57:18 -04:00
int toku_testsetup_leaf ( BRT brt , BLOCKNUM * blocknum ) {
2008-03-05 18:34:32 +00:00
BRTNODE node ;
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2013-04-16 23:59:35 -04:00
int r = toku_read_brt_header_and_store_in_cachefile ( brt - > cf , MAX_LSN , & brt - > h , & ignore_if_was_already_open ) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
2013-04-16 23:59:40 -04:00
toku_create_new_brtnode ( brt , & node , 0 , 1 ) ;
2013-04-16 23:59:41 -04:00
BP_STATE ( node , 0 ) = PT_AVAIL ;
2008-04-03 20:24:47 +00:00
2013-04-16 23:57:18 -04:00
* blocknum = node - > thisnodename ;
2013-04-16 23:59:40 -04:00
toku_unpin_brtnode ( brt , node ) ;
2008-03-05 18:34:32 +00:00
return 0 ;
}
// Don't bother to clean up carefully if something goes wrong. (E.g., it's OK to have malloced stuff that hasn't been freed.)
2013-04-16 23:59:37 -04:00
int toku_testsetup_nonleaf ( BRT brt , int height , BLOCKNUM * blocknum , int n_children , BLOCKNUM * children , char * * keys , int * keylens ) {
2008-03-05 18:34:32 +00:00
BRTNODE node ;
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2008-03-05 18:34:32 +00:00
assert ( n_children < = BRT_FANOUT ) ;
2013-04-16 23:59:35 -04:00
int r = toku_read_brt_header_and_store_in_cachefile ( brt - > cf , MAX_LSN , & brt - > h , & ignore_if_was_already_open ) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
2013-04-16 23:59:40 -04:00
toku_create_new_brtnode ( brt , & node , height , n_children ) ;
2008-03-05 18:34:32 +00:00
int i ;
for ( i = 0 ; i < n_children ; i + + ) {
2013-04-16 23:59:41 -04:00
BP_BLOCKNUM ( node , i ) = children [ i ] ;
BP_STATE ( node , i ) = PT_AVAIL ;
2008-03-05 18:34:32 +00:00
}
for ( i = 0 ; i + 1 < n_children ; i + + ) {
2013-04-16 23:59:40 -04:00
node - > childkeys [ i ] = kv_pair_malloc ( keys [ i ] , keylens [ i ] , 0 , 0 ) ;
node - > totalchildkeylens + = keylens [ i ] ;
2008-03-05 18:34:32 +00:00
}
2013-04-16 23:57:18 -04:00
* blocknum = node - > thisnodename ;
2013-04-16 23:59:40 -04:00
toku_unpin_brtnode ( brt , node ) ;
return 0 ;
2008-03-05 18:34:32 +00:00
}
2013-04-16 23:57:18 -04:00
int toku_testsetup_root ( BRT brt , BLOCKNUM blocknum ) {
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2013-04-16 23:59:35 -04:00
int r = toku_read_brt_header_and_store_in_cachefile ( brt - > cf , MAX_LSN , & brt - > h , & ignore_if_was_already_open ) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
2013-04-16 23:57:47 -04:00
brt - > h - > root = blocknum ;
brt - > h - > root_hash . valid = FALSE ;
2013-04-16 23:57:18 -04:00
return 0 ;
2008-03-05 18:34:32 +00:00
}
2013-04-16 23:57:18 -04:00
int toku_testsetup_get_sersize ( BRT brt , BLOCKNUM diskoff ) // Return the size on disk
2008-03-05 18:34:32 +00:00
{
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2008-03-05 18:34:32 +00:00
void * node_v ;
2013-04-16 23:59:41 -04:00
struct brtnode_fetch_extra bfe ;
fill_bfe_for_full_read ( & bfe , brt - > h ) ;
2013-04-16 23:59:41 -04:00
int r = toku_cachetable_get_and_pin (
brt - > cf , diskoff ,
toku_cachetable_hash ( brt - > cf , diskoff ) ,
& node_v ,
NULL ,
toku_brtnode_flush_callback ,
toku_brtnode_fetch_callback ,
toku_brtnode_pe_callback ,
toku_brtnode_pf_req_callback ,
toku_brtnode_pf_callback ,
2013-04-16 23:59:41 -04:00
& bfe ,
2013-04-16 23:59:41 -04:00
brt - > h
) ;
2008-03-05 18:34:32 +00:00
assert ( r = = 0 ) ;
int size = toku_serialize_brtnode_size ( node_v ) ;
2013-04-16 23:59:40 -04:00
toku_unpin_brtnode ( brt , node_v ) ;
2008-03-05 18:34:32 +00:00
return size ;
}
2013-04-16 23:59:37 -04:00
int toku_testsetup_insert_to_leaf ( BRT brt , BLOCKNUM blocknum , char * key , int keylen , char * val , int vallen ) {
2008-03-05 18:34:32 +00:00
void * node_v ;
int r ;
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2013-04-16 23:59:41 -04:00
struct brtnode_fetch_extra bfe ;
fill_bfe_for_full_read ( & bfe , brt - > h ) ;
2013-04-16 23:59:41 -04:00
r = toku_cachetable_get_and_pin (
brt - > cf ,
blocknum ,
toku_cachetable_hash ( brt - > cf , blocknum ) ,
& node_v ,
NULL ,
toku_brtnode_flush_callback ,
toku_brtnode_fetch_callback ,
toku_brtnode_pe_callback ,
toku_brtnode_pf_req_callback ,
toku_brtnode_pf_callback ,
2013-04-16 23:59:41 -04:00
& bfe ,
2013-04-16 23:59:41 -04:00
brt - > h
) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
BRTNODE node = node_v ;
2013-04-16 23:59:37 -04:00
toku_verify_or_set_counts ( node ) ;
2008-03-05 18:34:32 +00:00
assert ( node - > height = = 0 ) ;
2008-04-02 23:40:36 +00:00
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
size_t lesize , disksize ;
2013-04-16 23:57:29 -04:00
LEAFENTRY leafentry ;
2008-04-25 13:45:55 +00:00
OMTVALUE storeddatav ;
2008-04-02 23:40:36 +00:00
u_int32_t idx ;
2008-04-07 01:30:25 +00:00
DBT keydbt , valdbt ;
2013-04-16 23:59:40 -04:00
MSN msn = next_dummymsn ( ) ;
BRT_MSG_S cmd = { BRT_INSERT , msn , xids_get_root_xids ( ) ,
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
. u . id = { toku_fill_dbt ( & keydbt , key , keylen ) ,
toku_fill_dbt ( & valdbt , val , vallen ) } } ;
//Generate a leafentry (committed insert key,val)
r = apply_msg_to_leafentry ( & cmd , NULL , //No old leafentry
& lesize , & disksize , & leafentry ,
2013-04-16 23:59:40 -04:00
NULL , NULL ) ;
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
assert ( r = = 0 ) ;
2013-04-16 23:59:40 -04:00
struct cmd_leafval_heaviside_extra be = { brt , & keydbt } ;
2013-04-16 23:59:41 -04:00
r = toku_omt_find_zero ( BLB_BUFFER ( node , 0 ) , toku_cmd_leafval_heaviside , & be , & storeddatav , & idx , NULL ) ;
2008-04-07 01:30:25 +00:00
2008-04-02 23:40:36 +00:00
if ( r = = 0 ) {
2008-04-25 13:45:55 +00:00
LEAFENTRY storeddata = storeddatav ;
2008-04-02 23:40:36 +00:00
// It's already there. So now we have to remove it and put the new one back in.
2013-04-16 23:59:41 -04:00
BLB_NBYTESINBUF ( node , 0 ) - = OMT_ITEM_OVERHEAD + leafentry_disksize ( storeddata ) ;
2013-04-16 23:59:40 -04:00
toku_free ( storeddata ) ;
2008-04-02 23:40:36 +00:00
// Now put the new kv in.
2013-04-16 23:59:41 -04:00
toku_omt_set_at ( BLB_BUFFER ( node , 0 ) , leafentry , idx ) ;
2008-03-05 18:34:32 +00:00
} else {
2013-04-16 23:59:41 -04:00
r = toku_omt_insert ( BLB_BUFFER ( node , 0 ) , leafentry , toku_cmd_leafval_heaviside , & be , 0 ) ;
2008-04-02 23:40:36 +00:00
assert ( r = = 0 ) ;
2008-03-05 18:34:32 +00:00
}
2013-04-16 23:59:43 -04:00
// hack to get tests passing. These tests should not be directly inserting into buffers
BLB ( node , 0 ) - > max_msn_applied = msn ;
2008-04-02 23:40:36 +00:00
2013-04-16 23:59:41 -04:00
BLB_NBYTESINBUF ( node , 0 ) + = OMT_ITEM_OVERHEAD + disksize ;
2008-04-02 23:40:36 +00:00
2008-03-05 18:34:32 +00:00
node - > dirty = 1 ;
2008-04-04 13:13:51 +00:00
2013-04-16 23:59:37 -04:00
toku_verify_or_set_counts ( node ) ;
2008-04-04 13:13:51 +00:00
2013-04-16 23:59:40 -04:00
toku_unpin_brtnode ( brt , node_v ) ;
return 0 ;
2008-03-05 18:34:32 +00:00
}
2013-04-16 23:59:37 -04:00
int toku_testsetup_insert_to_nonleaf ( BRT brt , BLOCKNUM blocknum , enum brt_msg_type cmdtype , char * key , int keylen , char * val , int vallen ) {
2008-03-05 18:34:32 +00:00
void * node_v ;
int r ;
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2013-04-16 23:59:41 -04:00
struct brtnode_fetch_extra bfe ;
fill_bfe_for_full_read ( & bfe , brt - > h ) ;
2013-04-16 23:59:41 -04:00
r = toku_cachetable_get_and_pin (
brt - > cf ,
blocknum ,
toku_cachetable_hash ( brt - > cf , blocknum ) ,
& node_v ,
NULL ,
toku_brtnode_flush_callback ,
toku_brtnode_fetch_callback ,
toku_brtnode_pe_callback ,
toku_brtnode_pf_req_callback ,
toku_brtnode_pf_callback ,
2013-04-16 23:59:41 -04:00
& bfe ,
2013-04-16 23:59:41 -04:00
brt - > h
) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
BRTNODE node = node_v ;
assert ( node - > height > 0 ) ;
2013-04-16 23:59:21 -04:00
DBT k ;
2008-03-05 18:34:32 +00:00
int childnum = toku_brtnode_which_child ( node ,
toku_fill_dbt ( & k , key , keylen ) ,
brt ) ;
2013-04-16 23:57:41 -04:00
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
XIDS xids_0 = xids_get_root_xids ( ) ;
2013-04-16 23:59:40 -04:00
MSN msn = next_dummymsn ( ) ;
r = toku_fifo_enq ( BNC_BUFFER ( node , childnum ) , key , keylen , val , vallen , cmdtype , msn , xids_0 ) ;
2008-03-05 18:34:32 +00:00
assert ( r = = 0 ) ;
2013-04-16 23:59:43 -04:00
// Hack to get the test working. The problem is that this test
// is directly queueing something in a FIFO instead of
// using brt APIs.
node - > max_msn_applied_to_node_on_disk = msn ;
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
int sizediff = keylen + vallen + KEY_VALUE_OVERHEAD + BRT_CMD_OVERHEAD + xids_get_serialize_size ( xids_0 ) ;
2008-03-05 18:34:32 +00:00
BNC_NBYTESINBUF ( node , childnum ) + = sizediff ;
node - > dirty = 1 ;
2013-04-16 23:59:40 -04:00
toku_unpin_brtnode ( brt , node_v ) ;
return 0 ;
2008-03-05 18:34:32 +00:00
}