2008-01-11 03:09:14 +00:00
/* -*- mode: C; c-basic-offset: 4 -*- */
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."
2008-01-11 03:09:14 +00:00
/* rollback and rollforward routines. */
2013-04-16 23:57:20 -04:00
# include "includes.h"
2013-04-16 23:57:47 -04:00
# include "checkpoint.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 "xids.h"
# include "roll.h"
2008-07-01 19:52:35 +00:00
2013-04-16 23:57:38 -04:00
int
2013-04-16 23:58:04 -04:00
toku_commit_fdelete ( u_int8_t file_was_open ,
2013-04-16 23:59:05 -04:00
FILENUM filenum , // valid if file_was_open
BYTESTRING bs_fname , // cwd/iname
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yield_v ) ,
2013-04-16 23:58:06 -04:00
LSN UU ( oplsn ) ) //oplsn is the lsn of the commit
2013-04-16 23:58:04 -04:00
{
//TODO: #2037 verify the file is (user) closed
//Remove reference to the fd in the cachetable
CACHEFILE cf ;
int r ;
if ( file_was_open ) { // file was open when toku_brt_remove_on_commit() was called
2013-04-16 23:59:05 -04:00
r = toku_cachefile_of_filenum ( txn - > logger - > ct , filenum , & cf ) ;
if ( r = = ENOENT ) { //Missing file on recovered transaction is not an error
assert ( txn - > recovered_from_checkpoint ) ;
r = 0 ;
goto done ;
}
assert ( r = = 0 ) ; // must still be open (toku_brt_remove_on_commit() incremented refcount)
{
( void ) toku_cachefile_get_and_pin_fd ( cf ) ;
assert ( ! toku_cachefile_is_dev_null_unlocked ( cf ) ) ;
struct brt_header * h = toku_cachefile_get_userdata ( cf ) ;
DICTIONARY_ID dict_id = h - > dict_id ;
toku_logger_call_remove_finalize_callback ( txn - > logger , dict_id ) ;
2013-04-16 23:59:02 -04:00
toku_cachefile_unpin_fd ( cf ) ;
2013-04-16 23:59:05 -04:00
}
r = toku_cachefile_redirect_nullfd ( cf ) ;
assert ( r = = 0 ) ;
2013-04-16 23:58:04 -04:00
}
2013-04-16 23:59:03 -04:00
char * fname_in_env = fixup_fname ( & bs_fname ) ;
char * fname_in_cwd = toku_cachetable_get_fname_in_cwd ( txn - > logger - > ct , fname_in_env ) ;
r = unlink ( fname_in_cwd ) ;
assert ( r = = 0 | | errno = = ENOENT ) ;
toku_free ( fname_in_env ) ;
toku_free ( fname_in_cwd ) ;
2013-04-16 23:59:05 -04:00
done :
2013-04-16 23:58:04 -04:00
return 0 ;
}
int
toku_rollback_fdelete ( u_int8_t UU ( file_was_open ) ,
FILENUM UU ( filenum ) ,
2013-04-16 23:59:05 -04:00
BYTESTRING UU ( bs_fname ) ,
TOKUTXN UU ( txn ) ,
YIELDF UU ( yield ) ,
void * UU ( yield_v ) ,
2013-04-16 23:58:06 -04:00
LSN UU ( oplsn ) ) //oplsn is the lsn of the abort
2013-04-16 23:58:04 -04:00
{
2013-04-16 23:58:06 -04:00
//Rolling back an fdelete is an no-op.
return 0 ;
2013-04-16 23:58:04 -04:00
}
int
toku_commit_fcreate ( FILENUM UU ( filenum ) ,
2013-04-16 23:59:05 -04:00
BYTESTRING UU ( bs_fname ) ,
TOKUTXN UU ( txn ) ,
YIELDF UU ( yield ) ,
void * UU ( yield_v ) ,
2013-04-16 23:58:01 -04:00
LSN UU ( oplsn ) )
2013-04-16 23:57:38 -04:00
{
2008-04-07 01:30:25 +00:00
return 0 ;
}
2013-04-16 23:57:38 -04:00
int
2013-04-16 23:58:04 -04:00
toku_rollback_fcreate ( FILENUM filenum ,
2013-04-16 23:59:05 -04:00
BYTESTRING bs_fname , // cwd/iname
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yield_v ) ,
2013-04-16 23:58:01 -04:00
LSN UU ( oplsn ) )
2013-04-16 23:57:38 -04:00
{
2013-04-16 23:58:04 -04:00
//TODO: #2037 verify the file is (user) closed
2013-04-16 23:57:27 -04:00
//Remove reference to the fd in the cachetable
2013-04-16 23:58:06 -04:00
CACHEFILE cf = NULL ;
2013-04-16 23:57:27 -04:00
int r = toku_cachefile_of_filenum ( txn - > logger - > ct , filenum , & cf ) ;
2013-04-16 23:59:05 -04:00
if ( r = = ENOENT ) { //Missing file on recovered transaction is not an error
assert ( txn - > recovered_from_checkpoint ) ;
r = 0 ;
goto done ;
}
2013-04-16 23:58:04 -04:00
assert ( r = = 0 ) ;
{
2013-04-16 23:59:02 -04:00
( void ) toku_cachefile_get_and_pin_fd ( cf ) ;
2013-04-16 23:59:05 -04:00
assert ( ! toku_cachefile_is_dev_null_unlocked ( cf ) ) ;
struct brt_header * h = toku_cachefile_get_userdata ( cf ) ;
DICTIONARY_ID dict_id = h - > dict_id ;
toku_logger_call_remove_finalize_callback ( txn - > logger , dict_id ) ;
2013-04-16 23:59:02 -04:00
toku_cachefile_unpin_fd ( cf ) ;
2013-04-16 23:57:27 -04:00
}
2013-04-16 23:58:04 -04:00
r = toku_cachefile_redirect_nullfd ( cf ) ;
assert ( r = = 0 ) ;
2013-04-16 23:59:03 -04:00
char * fname_in_env = fixup_fname ( & bs_fname ) ;
char * fname_in_cwd = toku_cachetable_get_fname_in_cwd ( txn - > logger - > ct , fname_in_env ) ;
r = unlink ( fname_in_cwd ) ;
assert ( r = = 0 | | errno = = ENOENT ) ;
toku_free ( fname_in_env ) ;
toku_free ( fname_in_cwd ) ;
2013-04-16 23:59:05 -04:00
done :
2008-01-12 12:21:07 +00:00
return 0 ;
}
2008-04-27 12:34:50 +00:00
static int find_brt_from_filenum ( OMTVALUE v , void * filenumvp ) {
FILENUM * filenump = filenumvp ;
BRT brt = v ;
FILENUM thisfnum = toku_cachefile_filenum ( brt - > cf ) ;
if ( thisfnum . fileid < filenump - > fileid ) return - 1 ;
if ( thisfnum . fileid > filenump - > fileid ) return + 1 ;
return 0 ;
}
2013-04-16 23:58:01 -04:00
static int do_insertion ( enum brt_msg_type type , FILENUM filenum , BYTESTRING key , BYTESTRING * data , TOKUTXN txn , LSN oplsn ) {
2008-04-07 01:30:25 +00:00
CACHEFILE cf ;
//printf("%s:%d committing insert %s %s\n", __FILE__, __LINE__, key.data, data.data);
2008-04-09 02:45:27 +00:00
int r = toku_cachefile_of_filenum ( txn - > logger - > ct , filenum , & cf ) ;
2013-04-16 23:59:05 -04:00
if ( r = = ENOENT ) { //Missing file on recovered transaction is not an error
assert ( txn - > recovered_from_checkpoint ) ;
r = 0 ;
goto done ;
}
2008-03-28 20:49:50 +00:00
assert ( r = = 0 ) ;
2008-04-27 12:34:50 +00:00
2013-04-16 23:59:02 -04:00
( void ) toku_cachefile_get_and_pin_fd ( cf ) ;
if ( ! toku_cachefile_is_dev_null_unlocked ( cf ) ) {
2013-04-16 23:58:04 -04:00
OMTVALUE brtv = NULL ;
r = toku_omt_find_zero ( txn - > open_brts , find_brt_from_filenum , & filenum , & brtv , NULL , NULL ) ;
assert ( r = = 0 ) ;
BRT brt = brtv ;
2013-04-16 23:58:01 -04:00
2013-04-16 23:58:04 -04:00
LSN treelsn = toku_brt_checkpoint_lsn ( brt ) ;
2013-04-16 23:59:02 -04:00
if ( oplsn . lsn ! = 0 & & oplsn . lsn < = treelsn . lsn ) {
r = 0 ;
goto cleanup ;
}
2013-04-16 23:58:01 -04:00
2013-04-16 23:58:04 -04:00
DBT key_dbt , data_dbt ;
XIDS xids = toku_txn_get_xids ( txn ) ;
BRT_MSG_S brtcmd = { type , xids ,
. u . id = { toku_fill_dbt ( & key_dbt , key . data , key . len ) ,
data
? toku_fill_dbt ( & data_dbt , data - > data , data - > len )
: toku_init_dbt ( & data_dbt ) } } ;
2008-04-27 12:34:50 +00:00
2013-04-16 23:58:04 -04:00
r = toku_brt_root_put_cmd ( brt , & brtcmd ) ;
}
2013-04-16 23:59:02 -04:00
cleanup :
toku_cachefile_unpin_fd ( cf ) ;
2013-04-16 23:59:05 -04:00
done :
2013-04-16 23:57:50 -04:00
return r ;
2008-04-27 15:12:25 +00:00
}
2013-04-16 23:58:04 -04:00
static int do_nothing_with_filenum ( TOKUTXN UU ( txn ) , FILENUM UU ( filenum ) ) {
return 0 ;
2008-05-03 12:43:25 +00:00
}
2013-04-16 23:58:01 -04:00
int toku_commit_cmdinsert ( FILENUM filenum , BYTESTRING key , TOKUTXN txn , YIELDF UU ( yield ) , void * UU ( yieldv ) , LSN oplsn ) {
2013-04-16 23:57:34 -04:00
# if TOKU_DO_COMMIT_CMD_INSERT
2013-04-16 23:58:02 -04:00
return do_insertion ( BRT_COMMIT_ANY , filenum , key , 0 , txn , oplsn ) ;
2013-04-16 23:57:34 -04:00
# else
2013-04-16 23:58:01 -04:00
key = key ; oplsn = oplsn ;
2013-04-16 23:57:34 -04:00
return do_nothing_with_filenum ( txn , filenum ) ;
# endif
}
2013-04-16 23:57:38 -04:00
int
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
toku_commit_cmdinsertboth ( FILENUM filenum ,
2013-04-16 23:59:05 -04:00
BYTESTRING key ,
BYTESTRING data ,
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yieldv ) ,
2013-04-16 23:58:01 -04:00
LSN oplsn )
2013-04-16 23:57:38 -04:00
{
2008-07-01 19:52:35 +00:00
# if TOKU_DO_COMMIT_CMD_INSERT
2013-04-16 23:58:02 -04:00
return do_insertion ( BRT_COMMIT_BOTH , filenum , key , & data , txn , oplsn ) ;
2008-07-01 19:52:35 +00:00
# else
2013-04-16 23:58:01 -04:00
key = key ; data = data ; oplsn = oplsn ;
2008-07-01 19:52:35 +00:00
return do_nothing_with_filenum ( txn , filenum ) ;
# endif
2008-03-28 20:49:50 +00:00
}
2013-04-16 23:57:38 -04:00
int
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
toku_rollback_cmdinsert ( FILENUM filenum ,
2013-04-16 23:59:05 -04:00
BYTESTRING key ,
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yieldv ) ,
2013-04-16 23:58:01 -04:00
LSN oplsn )
2013-04-16 23:57:38 -04:00
{
2013-04-16 23:58:02 -04:00
return do_insertion ( BRT_ABORT_ANY , filenum , key , 0 , txn , oplsn ) ;
2013-04-16 23:57:34 -04:00
}
2013-04-16 23:57:38 -04:00
int
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
toku_rollback_cmdinsertboth ( FILENUM filenum ,
2013-04-16 23:59:05 -04:00
BYTESTRING key ,
BYTESTRING data ,
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yieldv ) ,
2013-04-16 23:58:01 -04:00
LSN oplsn )
2013-04-16 23:57:38 -04:00
{
2013-04-16 23:58:02 -04:00
return do_insertion ( BRT_ABORT_BOTH , filenum , key , & data , txn , oplsn ) ;
2008-04-07 01:30:25 +00:00
}
2013-04-16 23:57:38 -04:00
int
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
toku_commit_cmddeleteboth ( FILENUM filenum ,
2013-04-16 23:59:05 -04:00
BYTESTRING key ,
BYTESTRING data ,
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yieldv ) ,
2013-04-16 23:58:01 -04:00
LSN oplsn )
2013-04-16 23:57:38 -04:00
{
2008-07-01 19:52:35 +00:00
# if TOKU_DO_COMMIT_CMD_DELETE_BOTH
2013-04-16 23:58:02 -04:00
return do_insertion ( BRT_COMMIT_BOTH , filenum , key , & data , txn , oplsn ) ;
2008-07-01 19:52:35 +00:00
# else
xid = xid ; key = key ; data = data ;
return do_nothing_with_filenum ( txn , filenum ) ;
# endif
2008-04-07 01:30:25 +00:00
}
2013-04-16 23:57:38 -04:00
int
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
toku_rollback_cmddeleteboth ( FILENUM filenum ,
2013-04-16 23:59:05 -04:00
BYTESTRING key ,
BYTESTRING data ,
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yieldv ) ,
2013-04-16 23:58:01 -04:00
LSN oplsn )
2013-04-16 23:57:38 -04:00
{
2013-04-16 23:58:02 -04:00
return do_insertion ( BRT_ABORT_BOTH , filenum , key , & data , txn , oplsn ) ;
2008-01-25 21:50:07 +00:00
}
2013-04-16 23:57:38 -04:00
int
2013-04-16 23:58:01 -04:00
toku_commit_cmddelete ( FILENUM filenum ,
2013-04-16 23:59:05 -04:00
BYTESTRING key ,
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yieldv ) ,
2013-04-16 23:58:01 -04:00
LSN oplsn )
2013-04-16 23:57:38 -04:00
{
2008-07-01 19:52:35 +00:00
# if TOKU_DO_COMMIT_CMD_DELETE
2013-04-16 23:58:02 -04:00
return do_insertion ( BRT_COMMIT_ANY , filenum , key , 0 , txn , oplsn ) ;
2008-07-01 19:52:35 +00:00
# else
xid = xid ; key = key ;
return do_nothing_with_filenum ( txn , filenum ) ;
# endif
2008-02-27 07:14:03 +00:00
}
2008-03-19 19:23:45 +00:00
2013-04-16 23:57:38 -04:00
int
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
toku_rollback_cmddelete ( FILENUM filenum ,
2013-04-16 23:59:05 -04:00
BYTESTRING key ,
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yieldv ) ,
2013-04-16 23:58:01 -04:00
LSN oplsn )
2013-04-16 23:57:38 -04:00
{
2013-04-16 23:58:02 -04:00
return do_insertion ( BRT_ABORT_ANY , filenum , key , 0 , txn , oplsn ) ;
2008-03-19 19:23:45 +00:00
}
2008-04-22 17:09:24 +00:00
2013-04-16 23:59:05 -04:00
static int
toku_apply_rollinclude ( TXNID xid ,
uint64_t num_nodes ,
BLOCKNUM spilled_head ,
uint32_t spilled_head_hash ,
BLOCKNUM spilled_tail ,
uint32_t spilled_tail_hash ,
TOKUTXN txn ,
YIELDF yield ,
void * yieldv ,
LSN oplsn ,
apply_rollback_item func ) {
int r ;
struct roll_entry * item ;
2013-04-16 23:57:38 -04:00
int count = 0 ;
2008-04-22 17:09:24 +00:00
2013-04-16 23:59:05 -04:00
BLOCKNUM next_log = spilled_tail ;
uint32_t next_log_hash = spilled_tail_hash ;
uint64_t last_sequence = num_nodes ;
BOOL found_head = FALSE ;
assert ( next_log . b ! = ROLLBACK_NONE . b ) ;
while ( next_log . b ! = ROLLBACK_NONE . b ) {
ROLLBACK_LOG_NODE log ;
//pin log
r = toku_get_and_pin_rollback_log ( txn , xid , last_sequence - 1 , next_log , next_log_hash , & log ) ;
assert ( r = = 0 ) ;
last_sequence = log - > sequence ;
while ( ( item = log - > newest_logentry ) ) {
log - > newest_logentry = item - > prev ;
r = func ( txn , item , yield , yieldv , oplsn ) ;
if ( r ! = 0 ) return r ;
count + + ;
if ( count % 2 = = 0 ) yield ( NULL , yieldv ) ;
}
if ( next_log . b = = spilled_head . b ) {
assert ( ! found_head ) ;
found_head = TRUE ;
assert ( log - > sequence = = 0 ) ;
}
next_log = log - > older ;
next_log_hash = log - > older_hash ;
{
//Clean up transaction structure to prevent
//toku_txn_close from double-freeing
spilled_tail = next_log ;
spilled_tail_hash = next_log_hash ;
if ( found_head ) {
assert ( next_log . b = = ROLLBACK_NONE . b ) ;
spilled_head = next_log ;
spilled_head_hash = next_log_hash ;
}
}
//Unpins log
r = toku_delete_rollback_log ( txn , log ) ;
assert ( r = = 0 ) ;
2008-04-22 17:09:24 +00:00
}
2008-07-09 12:00:26 +00:00
return r ;
2008-04-22 17:09:24 +00:00
}
2013-04-16 23:57:38 -04:00
int
2013-04-16 23:59:05 -04:00
toku_commit_rollinclude ( TXNID xid ,
uint64_t num_nodes ,
BLOCKNUM spilled_head ,
uint32_t spilled_head_hash ,
BLOCKNUM spilled_tail ,
uint32_t spilled_tail_hash ,
TOKUTXN txn ,
YIELDF yield ,
void * yieldv ,
2013-04-16 23:58:01 -04:00
LSN oplsn ) {
2008-04-22 17:09:24 +00:00
int r ;
2013-04-16 23:59:05 -04:00
r = toku_apply_rollinclude ( xid , num_nodes ,
spilled_head , spilled_head_hash ,
spilled_tail , spilled_tail_hash ,
txn , yield , yieldv , oplsn ,
toku_commit_rollback_item ) ;
return r ;
2008-04-22 17:09:24 +00:00
}
2013-04-16 23:57:38 -04:00
int
2013-04-16 23:59:05 -04:00
toku_rollback_rollinclude ( TXNID xid ,
uint64_t num_nodes ,
BLOCKNUM spilled_head ,
uint32_t spilled_head_hash ,
BLOCKNUM spilled_tail ,
uint32_t spilled_tail_hash ,
TOKUTXN txn ,
YIELDF yield ,
void * yieldv ,
LSN oplsn ) {
2008-04-22 17:09:24 +00:00
int r ;
2013-04-16 23:59:05 -04:00
r = toku_apply_rollinclude ( xid , num_nodes ,
spilled_head , spilled_head_hash ,
spilled_tail , spilled_tail_hash ,
txn , yield , yieldv , oplsn ,
toku_abort_rollback_item ) ;
return r ;
2008-04-22 17:09:24 +00:00
}
2013-04-16 23:57:38 -04:00
int
2013-04-16 23:57:53 -04:00
toku_rollback_tablelock_on_empty_table ( FILENUM filenum ,
TOKUTXN txn ,
2013-04-16 23:58:01 -04:00
YIELDF yield ,
void * yield_v ,
2013-04-16 23:59:05 -04:00
LSN oplsn )
2013-04-16 23:57:38 -04:00
{
2013-04-16 23:58:04 -04:00
//TODO: Replace truncate function with something that doesn't need to mess with checkpoints.
2013-04-16 23:57:38 -04:00
// on rollback we have to make the file be empty, since we locked an empty table, and then may have done things to it.
CACHEFILE cf ;
//printf("%s:%d committing insert %s %s\n", __FILE__, __LINE__, key.data, data.data);
int r = toku_cachefile_of_filenum ( txn - > logger - > ct , filenum , & cf ) ;
2013-04-16 23:59:05 -04:00
if ( r = = ENOENT ) { //Missing file on recovered transaction is not an error
assert ( txn - > recovered_from_checkpoint ) ;
r = 0 ;
goto done ;
}
2013-04-16 23:57:38 -04:00
assert ( r = = 0 ) ;
OMTVALUE brtv = NULL ;
r = toku_omt_find_zero ( txn - > open_brts , find_brt_from_filenum , & filenum , & brtv , NULL , NULL ) ;
2013-04-16 23:59:05 -04:00
assert ( r = = 0 ) ;
BRT brt = brtv ;
{ //Do NOT truncate the file if
//the file already survived the truncate and was checkpointed.
LSN treelsn = toku_brt_checkpoint_lsn ( brt ) ;
if ( oplsn . lsn ! = 0 & & oplsn . lsn < = treelsn . lsn ) {
r = 0 ;
goto done ;
}
2013-04-16 23:57:40 -04:00
}
2013-04-16 23:59:05 -04:00
toku_poll_txn_progress_function ( txn , FALSE , TRUE ) ;
yield ( toku_checkpoint_safe_client_lock , yield_v ) ;
toku_poll_txn_progress_function ( txn , FALSE , FALSE ) ;
r = toku_brt_truncate ( brt ) ;
assert ( r = = 0 ) ;
toku_checkpoint_safe_client_unlock ( ) ;
2013-04-16 23:57:38 -04:00
2013-04-16 23:59:05 -04:00
done :
2013-04-16 23:57:50 -04:00
return r ;
2013-04-16 23:57:38 -04:00
}
int
2013-04-16 23:58:01 -04:00
toku_commit_tablelock_on_empty_table ( FILENUM filenum , TOKUTXN txn , YIELDF UU ( yield ) , void * UU ( yield_v ) , LSN UU ( oplsn ) )
2013-04-16 23:57:38 -04:00
{
return do_nothing_with_filenum ( txn , filenum ) ;
}
2013-04-16 23:58:59 -04:00
int
2013-04-16 23:59:03 -04:00
toku_commit_load ( BYTESTRING old_iname ,
2013-04-16 23:58:59 -04:00
BYTESTRING UU ( new_iname ) ,
2013-04-16 23:59:03 -04:00
TOKUTXN txn ,
2013-04-16 23:58:59 -04:00
YIELDF UU ( yield ) ,
void * UU ( yield_v ) ,
LSN UU ( oplsn ) )
{
2013-04-16 23:59:03 -04:00
CACHEFILE cf ;
int r ;
char * fname_in_env = fixup_fname ( & old_iname ) ; //Delete old file
r = toku_cachefile_of_iname_in_env ( txn - > logger - > ct , fname_in_env , & cf ) ;
if ( r = = 0 ) {
2013-04-16 23:59:05 -04:00
r = toku_cachefile_redirect_nullfd ( cf ) ;
2013-04-16 23:59:03 -04:00
assert ( r = = 0 ) ;
}
else {
assert ( r = = ENOENT ) ;
}
char * fname_in_cwd = toku_cachetable_get_fname_in_cwd ( txn - > logger - > ct , fname_in_env ) ;
r = unlink ( fname_in_cwd ) ;
assert ( r = = 0 | | errno = = ENOENT ) ;
toku_free ( fname_in_env ) ;
toku_free ( fname_in_cwd ) ;
2013-04-16 23:58:59 -04:00
return 0 ;
}
int
toku_rollback_load ( BYTESTRING UU ( old_iname ) ,
2013-04-16 23:59:03 -04:00
BYTESTRING new_iname ,
TOKUTXN txn ,
2013-04-16 23:58:59 -04:00
YIELDF UU ( yield ) ,
void * UU ( yield_v ) ,
LSN UU ( oplsn ) )
{
2013-04-16 23:59:03 -04:00
CACHEFILE cf ;
int r ;
char * fname_in_env = fixup_fname ( & new_iname ) ; //Delete new file
r = toku_cachefile_of_iname_in_env ( txn - > logger - > ct , fname_in_env , & cf ) ;
if ( r = = 0 ) {
2013-04-16 23:59:05 -04:00
r = toku_cachefile_redirect_nullfd ( cf ) ;
2013-04-16 23:59:03 -04:00
assert ( r = = 0 ) ;
}
else {
assert ( r = = ENOENT ) ;
}
char * fname_in_cwd = toku_cachetable_get_fname_in_cwd ( txn - > logger - > ct , fname_in_env ) ;
r = unlink ( fname_in_cwd ) ;
assert ( r = = 0 | | errno = = ENOENT ) ;
toku_free ( fname_in_env ) ;
toku_free ( fname_in_cwd ) ;
2013-04-16 23:58:59 -04:00
return 0 ;
}
2013-04-16 23:59:01 -04:00
int
toku_commit_dictionary_redirect ( FILENUM UU ( old_filenum ) ,
2013-04-16 23:59:05 -04:00
FILENUM UU ( new_filenum ) ,
2013-04-16 23:59:01 -04:00
TOKUTXN UU ( txn ) ,
YIELDF UU ( yield ) ,
void * UU ( yield_v ) ,
LSN UU ( oplsn ) ) //oplsn is the lsn of the commit
{
2013-04-16 23:59:05 -04:00
//Redirect only has meaning during normal operation (NOT during recovery).
if ( ! txn - > recovered_from_checkpoint ) {
//NO-OP
}
2013-04-16 23:59:01 -04:00
return 0 ;
}
int
toku_rollback_dictionary_redirect ( FILENUM old_filenum ,
2013-04-16 23:59:05 -04:00
FILENUM new_filenum ,
2013-04-16 23:59:01 -04:00
TOKUTXN txn ,
YIELDF UU ( yield ) ,
void * UU ( yield_v ) ,
LSN UU ( oplsn ) ) //oplsn is the lsn of the abort
{
int r = 0 ;
2013-04-16 23:59:05 -04:00
//Redirect only has meaning during normal operation (NOT during recovery).
if ( ! txn - > recovered_from_checkpoint ) {
CACHEFILE new_cf = NULL ;
r = toku_cachefile_of_filenum ( txn - > logger - > ct , new_filenum , & new_cf ) ;
assert ( r = = 0 ) ;
struct brt_header * new_h = toku_cachefile_get_userdata ( new_cf ) ;
CACHEFILE old_cf = NULL ;
r = toku_cachefile_of_filenum ( txn - > logger - > ct , old_filenum , & old_cf ) ;
assert ( r = = 0 ) ;
struct brt_header * old_h = toku_cachefile_get_userdata ( old_cf ) ;
//Redirect back from new to old.
r = toku_dictionary_redirect_abort ( old_h , new_h , txn ) ;
assert ( r = = 0 ) ;
}
2013-04-16 23:59:01 -04:00
return r ;
}