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:57:48 -04:00
# ident "$Id$"
2013-04-17 00:00:59 -04:00
# ident "Copyright (c) 2007-2012 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"
2013-04-17 00:00:35 -04:00
# include <ft-cachetable-wrappers.h>
# include <ft-flusher.h>
2008-03-05 18:34:32 +00:00
2013-04-16 23:59:40 -04:00
2013-04-17 00:00:35 -04:00
// dummymsn needed to simulate msn because messages are injected at a lower level than toku_ft_root_put_cmd()
2013-04-17 00:00:17 -04:00
# define MIN_DUMMYMSN ((MSN) {(uint64_t)1 << 62})
2013-04-16 23:59:40 -04:00
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-17 00:00:35 -04:00
int toku_testsetup_leaf ( FT_HANDLE brt , BLOCKNUM * blocknum , int n_children , char * * keys , int * keylens ) {
FTNODE node ;
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2013-04-17 00:00:35 -04:00
toku_create_new_ftnode ( brt , & node , 0 , n_children ) ;
2013-04-17 00:00:03 -04:00
int i ;
for ( i = 0 ; i < n_children ; i + + ) {
BP_STATE ( node , i ) = PT_AVAIL ;
}
for ( i = 0 ; i + 1 < n_children ; i + + ) {
2013-04-17 00:00:29 -04:00
toku_fill_dbt ( & node - > childkeys [ i ] , toku_xmemdup ( keys [ i ] , keylens [ i ] ) , keylens [ i ] ) ;
2013-04-17 00:00:03 -04:00
node - > totalchildkeylens + = keylens [ i ] ;
}
2008-04-03 20:24:47 +00:00
2013-04-16 23:57:18 -04:00
* blocknum = node - > thisnodename ;
2013-04-17 00:00:36 -04:00
toku_unpin_ftnode ( brt - > ft , 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-17 00:00:35 -04:00
int toku_testsetup_nonleaf ( FT_HANDLE brt , int height , BLOCKNUM * blocknum , int n_children , BLOCKNUM * children , char * * keys , int * keylens ) {
FTNODE node ;
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2013-04-17 00:00:35 -04:00
assert ( n_children < = FT_FANOUT ) ;
toku_create_new_ftnode ( 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-17 00:00:29 -04:00
toku_fill_dbt ( & node - > childkeys [ i ] , toku_xmemdup ( keys [ i ] , keylens [ i ] ) , keylens [ i ] ) ;
2013-04-16 23:59:54 -04:00
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-17 00:00:36 -04:00
toku_unpin_ftnode ( brt - > ft , node ) ;
2013-04-16 23:59:40 -04:00
return 0 ;
2008-03-05 18:34:32 +00:00
}
2013-04-17 00:00:35 -04:00
int toku_testsetup_root ( FT_HANDLE brt , BLOCKNUM blocknum ) {
2013-04-16 23:59:40 -04:00
assert ( testsetup_initialized ) ;
2013-04-17 00:00:37 -04:00
brt - > ft - > h - > root_blocknum = blocknum ;
2013-04-16 23:57:18 -04:00
return 0 ;
2008-03-05 18:34:32 +00:00
}
2013-04-17 00:00:35 -04:00
int toku_testsetup_get_sersize ( FT_HANDLE 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-17 00:00:35 -04:00
struct ftnode_fetch_extra bfe ;
2013-04-17 00:00:36 -04:00
fill_bfe_for_full_read ( & bfe , brt - > ft ) ;
2013-04-16 23:59:41 -04:00
int r = toku_cachetable_get_and_pin (
2013-04-17 00:00:36 -04:00
brt - > ft - > cf , diskoff ,
toku_cachetable_hash ( brt - > ft - > cf , diskoff ) ,
2013-04-16 23:59:47 -04:00
& node_v ,
2013-04-16 23:59:41 -04:00
NULL ,
2013-04-17 00:00:36 -04:00
get_write_callbacks_for_node ( brt - > ft ) ,
2013-04-17 00:00:35 -04:00
toku_ftnode_fetch_callback ,
toku_ftnode_pf_req_callback ,
toku_ftnode_pf_callback ,
2013-04-17 00:00:13 -04:00
TRUE ,
2013-04-17 00:00:09 -04:00
& bfe
2013-04-16 23:59:41 -04:00
) ;
2008-03-05 18:34:32 +00:00
assert ( r = = 0 ) ;
2013-04-17 00:00:59 -04:00
FTNODE CAST_FROM_VOIDP ( node , node_v ) ;
2013-04-17 00:00:58 -04:00
int size = toku_serialize_ftnode_size ( node ) ;
toku_unpin_ftnode ( brt - > ft , node ) ;
2008-03-05 18:34:32 +00:00
return size ;
}
2013-04-17 00:00:58 -04:00
int toku_testsetup_insert_to_leaf ( FT_HANDLE brt , BLOCKNUM blocknum , const char * key , int keylen , const 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:47 -04:00
2013-04-17 00:00:35 -04:00
struct ftnode_fetch_extra bfe ;
2013-04-17 00:00:36 -04:00
fill_bfe_for_full_read ( & bfe , brt - > ft ) ;
2013-04-16 23:59:41 -04:00
r = toku_cachetable_get_and_pin (
2013-04-17 00:00:36 -04:00
brt - > ft - > cf ,
2013-04-16 23:59:47 -04:00
blocknum ,
2013-04-17 00:00:36 -04:00
toku_cachetable_hash ( brt - > ft - > cf , blocknum ) ,
2013-04-16 23:59:47 -04:00
& node_v ,
2013-04-16 23:59:41 -04:00
NULL ,
2013-04-17 00:00:36 -04:00
get_write_callbacks_for_node ( brt - > ft ) ,
2013-04-17 00:00:35 -04:00
toku_ftnode_fetch_callback ,
toku_ftnode_pf_req_callback ,
toku_ftnode_pf_callback ,
2013-04-17 00:00:13 -04:00
TRUE ,
2013-04-17 00:00:09 -04:00
& bfe
2013-04-16 23:59:41 -04:00
) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
2013-04-17 00:00:59 -04:00
FTNODE CAST_FROM_VOIDP ( 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
2008-04-07 01:30:25 +00:00
DBT keydbt , valdbt ;
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 = { toku_fill_dbt ( & keydbt , key , keylen ) ,
toku_fill_dbt ( & valdbt , val , vallen ) } } } ;
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
2013-04-17 00:00:35 -04:00
toku_ft_node_put_cmd (
2013-04-17 00:00:36 -04:00
brt - > ft - > compare_fun ,
brt - > ft - > update_fun ,
& brt - > ft - > cmp_descriptor ,
2013-04-17 00:00:03 -04:00
node ,
& cmd ,
2013-04-17 00:00:30 -04:00
true ,
NULL
2013-04-17 00:00:03 -04:00
) ;
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-17 00:00:58 -04:00
toku_unpin_ftnode ( brt - > ft , node ) ;
2013-04-16 23:59:40 -04:00
return 0 ;
2008-03-05 18:34:32 +00:00
}
2013-04-16 23:59:48 -04:00
static int
testhelper_string_key_cmp ( DB * UU ( e ) , const DBT * a , const DBT * b )
{
2013-04-17 00:00:59 -04:00
char * CAST_FROM_VOIDP ( s , a - > data ) , * CAST_FROM_VOIDP ( t , b - > data ) ;
2013-04-16 23:59:48 -04:00
return strcmp ( s , t ) ;
}
2013-04-17 00:00:03 -04:00
void
2013-04-17 00:00:35 -04:00
toku_pin_node_with_min_bfe ( FTNODE * node , BLOCKNUM b , FT_HANDLE t )
2013-04-17 00:00:03 -04:00
{
2013-04-17 00:00:35 -04:00
struct ftnode_fetch_extra bfe ;
2013-04-17 00:00:36 -04:00
fill_bfe_for_min_read ( & bfe , t - > ft ) ;
2013-04-17 00:00:35 -04:00
toku_pin_ftnode_off_client_thread (
2013-04-17 00:00:36 -04:00
t - > ft ,
2013-04-17 00:00:03 -04:00
b ,
2013-04-17 00:00:36 -04:00
toku_cachetable_hash ( t - > ft - > cf , b ) ,
2013-04-17 00:00:03 -04:00
& bfe ,
2013-04-17 00:00:13 -04:00
TRUE ,
2013-04-17 00:00:03 -04:00
0 ,
NULL ,
node
) ;
}
2013-04-17 00:00:58 -04:00
int toku_testsetup_insert_to_nonleaf ( FT_HANDLE brt , BLOCKNUM blocknum , enum ft_msg_type cmdtype , const char * key , int keylen , const 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-17 00:00:35 -04:00
struct ftnode_fetch_extra bfe ;
2013-04-17 00:00:36 -04:00
fill_bfe_for_full_read ( & bfe , brt - > ft ) ;
2013-04-16 23:59:41 -04:00
r = toku_cachetable_get_and_pin (
2013-04-17 00:00:36 -04:00
brt - > ft - > cf ,
2013-04-16 23:59:47 -04:00
blocknum ,
2013-04-17 00:00:36 -04:00
toku_cachetable_hash ( brt - > ft - > cf , blocknum ) ,
2013-04-16 23:59:47 -04:00
& node_v ,
2013-04-16 23:59:41 -04:00
NULL ,
2013-04-17 00:00:36 -04:00
get_write_callbacks_for_node ( brt - > ft ) ,
2013-04-17 00:00:35 -04:00
toku_ftnode_fetch_callback ,
toku_ftnode_pf_req_callback ,
toku_ftnode_pf_callback ,
2013-04-17 00:00:13 -04:00
TRUE ,
2013-04-17 00:00:09 -04:00
& bfe
2013-04-16 23:59:50 -04:00
) ;
2008-03-05 18:34:32 +00:00
if ( r ! = 0 ) return r ;
2013-04-17 00:00:59 -04:00
FTNODE CAST_FROM_VOIDP ( node , node_v ) ;
2008-03-05 18:34:32 +00:00
assert ( node - > height > 0 ) ;
2013-04-16 23:59:21 -04:00
DBT k ;
2013-04-17 00:00:35 -04:00
int childnum = toku_ftnode_which_child ( node ,
2013-04-16 23:59:47 -04:00
toku_fill_dbt ( & k , key , keylen ) ,
2013-04-17 00:00:36 -04:00
& brt - > ft - > cmp_descriptor , brt - > ft - > compare_fun ) ;
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 ( ) ;
2013-04-16 23:59:48 -04:00
r = toku_bnc_insert_msg ( BNC ( node , childnum ) , key , keylen , val , vallen , cmdtype , msn , xids_0 , true , NULL , testhelper_string_key_cmp ) ;
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 ;
2008-03-05 18:34:32 +00:00
node - > dirty = 1 ;
2013-04-17 00:00:58 -04:00
toku_unpin_ftnode ( brt - > ft , node ) ;
2013-04-16 23:59:40 -04:00
return 0 ;
2008-03-05 18:34:32 +00:00
}