2013-04-16 23:57:48 -04:00
# ident "$Id$"
2013-04-16 23:57:48 -04:00
# ident "Copyright (c) 2007, 2008, 2009 Tokutek Inc. All rights reserved."
# 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: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:57:18 -04:00
int r = toku_read_brt_header_and_store_in_cachefile ( brt - > cf , & brt - > h ) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
2013-04-16 23:57:54 -04:00
toku_create_new_brtnode ( brt , & node , 0 , 0 ) ;
2008-04-03 20:24:47 +00:00
2013-04-16 23:57:18 -04:00
* blocknum = node - > thisnodename ;
2008-03-05 18:34:32 +00:00
r = toku_unpin_brtnode ( brt , node ) ;
if ( r ! = 0 ) return r ;
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:57:18 -04:00
int toku_testsetup_nonleaf ( BRT brt , int height , BLOCKNUM * blocknum , int n_children , BLOCKNUM * children , u_int32_t * subtree_fingerprints , char * * keys , int * keylens ) {
2008-03-05 18:34:32 +00:00
BRTNODE node ;
assert ( n_children < = BRT_FANOUT ) ;
2013-04-16 23:57:18 -04:00
int r = toku_read_brt_header_and_store_in_cachefile ( brt - > cf , & brt - > h ) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
2013-04-16 23:57:54 -04:00
toku_create_new_brtnode ( brt , & node , height , 0 ) ;
2008-03-05 18:34:32 +00:00
node - > u . n . n_children = n_children ;
2008-04-03 20:24:47 +00:00
MALLOC_N ( n_children + 1 , node - > u . n . childinfos ) ;
MALLOC_N ( n_children , node - > u . n . childkeys ) ;
2008-03-05 18:34:32 +00:00
node - > u . n . totalchildkeylens = 0 ;
node - > u . n . n_bytes_in_buffers = 0 ;
int i ;
for ( i = 0 ; i < n_children ; i + + ) {
node - > u . n . childinfos [ i ] = ( struct brtnode_nonleaf_childinfo ) { . subtree_fingerprint = subtree_fingerprints [ i ] ,
2013-04-16 23:57:47 -04:00
. subtree_estimates = zero_estimates ,
2013-04-16 23:57:18 -04:00
. blocknum = children [ i ] ,
2008-03-05 18:34:32 +00:00
. n_bytes_in_buffer = 0 } ;
r = toku_fifo_create ( & BNC_BUFFER ( node , i ) ) ; if ( r ! = 0 ) return r ;
}
for ( i = 0 ; i + 1 < n_children ; i + + ) {
node - > u . n . childkeys [ i ] = kv_pair_malloc ( keys [ i ] , keylens [ i ] , 0 , 0 ) ;
node - > u . n . totalchildkeylens + = keylens [ i ] ;
}
2013-04-16 23:57:18 -04:00
* blocknum = node - > thisnodename ;
2013-04-16 23:57:18 -04:00
return toku_unpin_brtnode ( brt , node ) ;
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:57:18 -04:00
int r = toku_read_brt_header_and_store_in_cachefile ( brt - > cf , & brt - > h ) ;
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
{
void * node_v ;
2008-06-17 17:05:19 +00:00
int r = toku_cachetable_get_and_pin ( brt - > cf , diskoff , toku_cachetable_hash ( brt - > cf , diskoff ) , & node_v , NULL ,
2008-03-05 18:34:32 +00:00
toku_brtnode_flush_callback , toku_brtnode_fetch_callback , brt ) ;
assert ( r = = 0 ) ;
int size = toku_serialize_brtnode_size ( node_v ) ;
r = toku_unpin_brtnode ( brt , node_v ) ;
assert ( r = = 0 ) ;
return size ;
}
2013-04-16 23:57:18 -04:00
int toku_testsetup_insert_to_leaf ( BRT brt , BLOCKNUM blocknum , char * key , int keylen , char * val , int vallen , u_int32_t * subtree_fingerprint ) {
2008-03-05 18:34:32 +00:00
void * node_v ;
int r ;
2013-04-16 23:57:18 -04:00
r = toku_cachetable_get_and_pin ( brt - > cf , blocknum , toku_cachetable_hash ( brt - > cf , blocknum ) , & node_v , NULL ,
2008-03-05 18:34:32 +00:00
toku_brtnode_flush_callback , toku_brtnode_fetch_callback , brt ) ;
if ( r ! = 0 ) return r ;
BRTNODE node = node_v ;
2008-04-04 13:13:51 +00:00
toku_verify_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:58:00 -04:00
BRT_MSG_S cmd = { BRT_INSERT , 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 ,
node - > u . l . buffer , & node - > u . l . buffer_mempool , 0 ) ;
assert ( r = = 0 ) ;
2013-04-16 23:57:24 -04:00
struct cmd_leafval_heaviside_extra be = { brt , & cmd , node - > flags & TOKU_DB_DUPSORT } ;
r = toku_omt_find_zero ( node - > u . l . buffer , 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.
2008-04-22 20:39:50 +00:00
node - > u . l . n_bytes_in_buffer - = OMT_ITEM_OVERHEAD + leafentry_disksize ( storeddata ) ;
2008-04-07 01:30:25 +00:00
node - > local_fingerprint - = node - > rand4fingerprint * toku_le_crc ( storeddata ) ;
2008-04-22 20:39:50 +00:00
toku_mempool_mfree ( & node - > u . l . buffer_mempool , storeddata , leafentry_memsize ( storeddata ) ) ;
2008-04-02 23:40:36 +00:00
// Now put the new kv in.
2008-04-22 20:39:50 +00:00
toku_omt_set_at ( node - > u . l . buffer , leafentry , idx ) ;
2008-03-05 18:34:32 +00:00
} else {
2013-04-16 23:57:24 -04:00
r = toku_omt_insert ( node - > u . l . buffer , 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
}
2008-04-02 23:40:36 +00:00
2008-04-22 20:39:50 +00:00
node - > u . l . n_bytes_in_buffer + = OMT_ITEM_OVERHEAD + disksize ;
2008-04-07 01:30:25 +00:00
node - > local_fingerprint + = node - > rand4fingerprint * toku_le_crc ( leafentry ) ;
2008-04-02 23:40:36 +00:00
2008-03-05 18:34:32 +00:00
node - > dirty = 1 ;
* subtree_fingerprint = node - > local_fingerprint ;
2008-04-04 13:13:51 +00:00
toku_verify_counts ( node ) ;
2008-03-05 18:34:32 +00:00
r = toku_unpin_brtnode ( brt , node_v ) ;
return r ;
}
2013-04-16 23:58:00 -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 , u_int32_t * subtree_fingerprint ) {
2008-03-05 18:34:32 +00:00
void * node_v ;
int r ;
2013-04-16 23:57:18 -04:00
r = toku_cachetable_get_and_pin ( brt - > cf , blocknum , toku_cachetable_hash ( brt - > cf , blocknum ) , & node_v , NULL ,
2008-03-05 18:34:32 +00:00
toku_brtnode_flush_callback , toku_brtnode_fetch_callback , brt ) ;
if ( r ! = 0 ) return r ;
BRTNODE node = node_v ;
assert ( node - > height > 0 ) ;
DBT k , v ;
int childnum = toku_brtnode_which_child ( node ,
toku_fill_dbt ( & k , key , keylen ) ,
toku_fill_dbt ( & v , val , vallen ) ,
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 ( ) ;
r = toku_fifo_enq ( BNC_BUFFER ( node , childnum ) , key , keylen , val , vallen , cmdtype , xids_0 ) ;
2008-03-05 18:34:32 +00:00
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
u_int32_t fdelta = node - > rand4fingerprint * toku_calc_fingerprint_cmd ( cmdtype , xids_0 , key , keylen , val , vallen ) ;
2008-03-05 18:34:32 +00:00
node - > local_fingerprint + = fdelta ;
* subtree_fingerprint + = fdelta ;
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
node - > u . n . n_bytes_in_buffers + = sizediff ;
BNC_NBYTESINBUF ( node , childnum ) + = sizediff ;
node - > dirty = 1 ;
r = toku_unpin_brtnode ( brt , node_v ) ;
return r ;
}