Commit 5eb05636 authored by Rich Prohaska's avatar Rich Prohaska

FT-308 support deferred XA recovery with txn discard and dirty environment shutdown

parent 72218964
...@@ -291,6 +291,7 @@ static void print_defines (void) { ...@@ -291,6 +291,7 @@ static void print_defines (void) {
printf("#define DB_IS_HOT_INDEX 0x00100000\n"); // private tokudb printf("#define DB_IS_HOT_INDEX 0x00100000\n"); // private tokudb
printf("#define DBC_DISABLE_PREFETCHING 0x20000000\n"); // private tokudb printf("#define DBC_DISABLE_PREFETCHING 0x20000000\n"); // private tokudb
printf("#define DB_UPDATE_CMP_DESCRIPTOR 0x40000000\n"); // private tokudb printf("#define DB_UPDATE_CMP_DESCRIPTOR 0x40000000\n"); // private tokudb
printf("#define TOKUFT_DIRTY_SHUTDOWN %x\n", 1<<31);
{ {
//dbt flags //dbt flags
...@@ -572,6 +573,7 @@ static void print_db_txn_struct (void) { ...@@ -572,6 +573,7 @@ static void print_db_txn_struct (void) {
STRUCT_SETUP(DB_TXN, api_internal,"void *%s"); STRUCT_SETUP(DB_TXN, api_internal,"void *%s");
STRUCT_SETUP(DB_TXN, commit, "int (*%s) (DB_TXN*, uint32_t)"); STRUCT_SETUP(DB_TXN, commit, "int (*%s) (DB_TXN*, uint32_t)");
STRUCT_SETUP(DB_TXN, prepare, "int (*%s) (DB_TXN*, uint8_t gid[DB_GID_SIZE])"); STRUCT_SETUP(DB_TXN, prepare, "int (*%s) (DB_TXN*, uint8_t gid[DB_GID_SIZE])");
STRUCT_SETUP(DB_TXN, discard, "int (*%s) (DB_TXN*, uint32_t)");
STRUCT_SETUP(DB_TXN, id, "uint32_t (*%s) (DB_TXN *)"); STRUCT_SETUP(DB_TXN, id, "uint32_t (*%s) (DB_TXN *)");
STRUCT_SETUP(DB_TXN, mgrp, "DB_ENV *%s /*In TokuDB, mgrp is a DB_ENV not a DB_TXNMGR*/"); STRUCT_SETUP(DB_TXN, mgrp, "DB_ENV *%s /*In TokuDB, mgrp is a DB_ENV not a DB_TXNMGR*/");
STRUCT_SETUP(DB_TXN, parent, "DB_TXN *%s"); STRUCT_SETUP(DB_TXN, parent, "DB_TXN *%s");
......
...@@ -313,15 +313,17 @@ static void ft_close(CACHEFILE cachefile, int fd, void *header_v, bool oplsn_val ...@@ -313,15 +313,17 @@ static void ft_close(CACHEFILE cachefile, int fd, void *header_v, bool oplsn_val
} }
} }
if (ft->h->dirty) { // this is the only place this bit is tested (in currentheader) if (ft->h->dirty) { // this is the only place this bit is tested (in currentheader)
if (logger) { //Rollback cachefile MUST NOT BE CLOSED DIRTY bool do_checkpoint = true;
//It can be checkpointed only via 'checkpoint' if (logger && logger->rollback_cachefile == cachefile) {
assert(logger->rollback_cachefile != cachefile); do_checkpoint = false;
} }
if (do_checkpoint) {
ft_begin_checkpoint(lsn, header_v); ft_begin_checkpoint(lsn, header_v);
ft_checkpoint(cachefile, fd, ft); ft_checkpoint(cachefile, fd, ft);
ft_end_checkpoint(cachefile, fd, header_v); ft_end_checkpoint(cachefile, fd, header_v);
assert(!ft->h->dirty); // dirty bit should be cleared by begin_checkpoint and never set again (because we're closing the dictionary) assert(!ft->h->dirty); // dirty bit should be cleared by begin_checkpoint and never set again (because we're closing the dictionary)
} }
}
} }
// maps to cf->free_userdata // maps to cf->free_userdata
......
...@@ -304,27 +304,31 @@ toku_logger_open_rollback(TOKULOGGER logger, CACHETABLE cachetable, bool create) ...@@ -304,27 +304,31 @@ toku_logger_open_rollback(TOKULOGGER logger, CACHETABLE cachetable, bool create)
// so it will always be clean (!h->dirty) when about to be closed. // so it will always be clean (!h->dirty) when about to be closed.
// Rollback log can only be closed when there are no open transactions, // Rollback log can only be closed when there are no open transactions,
// so it will always be empty (no data blocks) when about to be closed. // so it will always be empty (no data blocks) when about to be closed.
void toku_logger_close_rollback(TOKULOGGER logger) { void toku_logger_close_rollback_check_empty(TOKULOGGER logger, bool clean_shutdown) {
CACHEFILE cf = logger->rollback_cachefile; // stored in logger at rollback cachefile open CACHEFILE cf = logger->rollback_cachefile; // stored in logger at rollback cachefile open
if (cf) { if (cf) {
FT_HANDLE ft_to_close; FT_HANDLE ft_to_close;
{ //Find "ft_to_close" { //Find "ft_to_close"
logger->rollback_cache.destroy(); logger->rollback_cache.destroy();
FT CAST_FROM_VOIDP(ft, toku_cachefile_get_userdata(cf)); FT CAST_FROM_VOIDP(ft, toku_cachefile_get_userdata(cf));
if (clean_shutdown) {
//Verify it is safe to close it. //Verify it is safe to close it.
assert(!ft->h->dirty); //Must not be dirty. assert(!ft->h->dirty); //Must not be dirty.
toku_free_unused_blocknums(ft->blocktable, ft->h->root_blocknum); toku_free_unused_blocknums(ft->blocktable, ft->h->root_blocknum);
//Must have no data blocks (rollback logs or otherwise). //Must have no data blocks (rollback logs or otherwise).
toku_block_verify_no_data_blocks_except_root(ft->blocktable, ft->h->root_blocknum); toku_block_verify_no_data_blocks_except_root(ft->blocktable, ft->h->root_blocknum);
assert(!ft->h->dirty); assert(!ft->h->dirty);
} else {
ft->h->dirty = 0;
}
ft_to_close = toku_ft_get_only_existing_ft_handle(ft); ft_to_close = toku_ft_get_only_existing_ft_handle(ft);
{ if (clean_shutdown) {
bool is_empty; bool is_empty;
is_empty = toku_ft_is_empty_fast(ft_to_close); is_empty = toku_ft_is_empty_fast(ft_to_close);
assert(is_empty); assert(is_empty);
}
assert(!ft->h->dirty); // it should not have been dirtied by the toku_ft_is_empty test. assert(!ft->h->dirty); // it should not have been dirtied by the toku_ft_is_empty test.
} }
}
toku_ft_handle_close(ft_to_close); toku_ft_handle_close(ft_to_close);
//Set as dealt with already. //Set as dealt with already.
...@@ -332,6 +336,10 @@ void toku_logger_close_rollback(TOKULOGGER logger) { ...@@ -332,6 +336,10 @@ void toku_logger_close_rollback(TOKULOGGER logger) {
} }
} }
void toku_logger_close_rollback(TOKULOGGER logger) {
toku_logger_close_rollback_check_empty(logger, true);
}
// No locks held on entry // No locks held on entry
// No locks held on exit. // No locks held on exit.
// No locks are needed, since you cannot legally close the log concurrently with doing anything else. // No locks are needed, since you cannot legally close the log concurrently with doing anything else.
......
...@@ -115,6 +115,7 @@ int toku_logger_close(TOKULOGGER *loggerp); ...@@ -115,6 +115,7 @@ int toku_logger_close(TOKULOGGER *loggerp);
void toku_logger_initialize_rollback_cache(TOKULOGGER logger, struct ft *ft); void toku_logger_initialize_rollback_cache(TOKULOGGER logger, struct ft *ft);
int toku_logger_open_rollback(TOKULOGGER logger, struct cachetable *ct, bool create); int toku_logger_open_rollback(TOKULOGGER logger, struct cachetable *ct, bool create);
void toku_logger_close_rollback(TOKULOGGER logger); void toku_logger_close_rollback(TOKULOGGER logger);
void toku_logger_close_rollback_check_empty(TOKULOGGER logger, bool clean_shutdown);
bool toku_logger_rollback_is_open (TOKULOGGER); // return true iff the rollback is open. bool toku_logger_rollback_is_open (TOKULOGGER); // return true iff the rollback is open.
void toku_logger_fsync (TOKULOGGER logger); void toku_logger_fsync (TOKULOGGER logger);
......
...@@ -92,8 +92,7 @@ PATENT RIGHTS GRANT: ...@@ -92,8 +92,7 @@ PATENT RIGHTS GRANT:
#include "ft/logger/log-internal.h" #include "ft/logger/log-internal.h"
#include "ft/txn/rollback-apply.h" #include "ft/txn/rollback-apply.h"
static void static void poll_txn_progress_function(TOKUTXN txn, uint8_t is_commit, uint8_t stall_for_checkpoint) {
poll_txn_progress_function(TOKUTXN txn, uint8_t is_commit, uint8_t stall_for_checkpoint) {
if (txn->progress_poll_fun) { if (txn->progress_poll_fun) {
TOKU_TXN_PROGRESS_S progress = { TOKU_TXN_PROGRESS_S progress = {
.entries_total = txn->roll_info.num_rollentries, .entries_total = txn->roll_info.num_rollentries,
...@@ -124,17 +123,14 @@ int toku_abort_rollback_item (TOKUTXN txn, struct roll_entry *item, LSN lsn) { ...@@ -124,17 +123,14 @@ int toku_abort_rollback_item (TOKUTXN txn, struct roll_entry *item, LSN lsn) {
return r; return r;
} }
int int note_ft_used_in_txns_parent(const FT &ft, uint32_t UU(index), TOKUTXN const child);
note_ft_used_in_txns_parent(const FT &ft, uint32_t UU(index), TOKUTXN const child); int note_ft_used_in_txns_parent(const FT &ft, uint32_t UU(index), TOKUTXN const child) {
int
note_ft_used_in_txns_parent(const FT &ft, uint32_t UU(index), TOKUTXN const child) {
TOKUTXN parent = child->parent; TOKUTXN parent = child->parent;
toku_txn_maybe_note_ft(parent, ft); toku_txn_maybe_note_ft(parent, ft);
return 0; return 0;
} }
static int static int apply_txn(TOKUTXN txn, LSN lsn, apply_rollback_item func) {
apply_txn(TOKUTXN txn, LSN lsn, apply_rollback_item func) {
int r = 0; int r = 0;
// do the commit/abort calls and free everything // do the commit/abort calls and free everything
// we do the commit/abort calls in reverse order too. // we do the commit/abort calls in reverse order too.
...@@ -302,3 +298,9 @@ int toku_rollback_abort(TOKUTXN txn, LSN lsn) { ...@@ -302,3 +298,9 @@ int toku_rollback_abort(TOKUTXN txn, LSN lsn) {
assert(r==0); assert(r==0);
return r; return r;
} }
int toku_rollback_discard(TOKUTXN txn) {
txn->roll_info.current_rollback = ROLLBACK_NONE;
return 0;
}
...@@ -98,3 +98,4 @@ int toku_abort_rollback_item (TOKUTXN txn, struct roll_entry *item, LSN lsn); ...@@ -98,3 +98,4 @@ int toku_abort_rollback_item (TOKUTXN txn, struct roll_entry *item, LSN lsn);
int toku_rollback_commit(TOKUTXN txn, LSN lsn); int toku_rollback_commit(TOKUTXN txn, LSN lsn);
int toku_rollback_abort(TOKUTXN txn, LSN lsn); int toku_rollback_abort(TOKUTXN txn, LSN lsn);
int toku_rollback_discard(TOKUTXN txn);
...@@ -627,7 +627,7 @@ void toku_txn_complete_txn(TOKUTXN txn) { ...@@ -627,7 +627,7 @@ void toku_txn_complete_txn(TOKUTXN txn) {
assert(txn->roll_info.spilled_rollback_tail.b == ROLLBACK_NONE.b); assert(txn->roll_info.spilled_rollback_tail.b == ROLLBACK_NONE.b);
assert(txn->roll_info.current_rollback.b == ROLLBACK_NONE.b); assert(txn->roll_info.current_rollback.b == ROLLBACK_NONE.b);
assert(txn->num_pin == 0); assert(txn->num_pin == 0);
assert(txn->state == TOKUTXN_COMMITTING || txn->state == TOKUTXN_ABORTING); assert(txn->state == TOKUTXN_COMMITTING || txn->state == TOKUTXN_ABORTING || txn->state == TOKUTXN_PREPARING);
if (txn->parent) { if (txn->parent) {
toku_txn_manager_handle_snapshot_destroy_for_child_txn( toku_txn_manager_handle_snapshot_destroy_for_child_txn(
txn, txn,
...@@ -800,6 +800,11 @@ int toku_txn_reads_txnid(TXNID txnid, TOKUTXN txn) { ...@@ -800,6 +800,11 @@ int toku_txn_reads_txnid(TXNID txnid, TOKUTXN txn) {
return r; return r;
} }
int toku_txn_discard_txn(TOKUTXN txn) {
int r = toku_rollback_discard(txn);
return r;
}
#include <toku_race_tools.h> #include <toku_race_tools.h>
void __attribute__((__constructor__)) toku_txn_status_helgrind_ignore(void); void __attribute__((__constructor__)) toku_txn_status_helgrind_ignore(void);
void toku_txn_status_helgrind_ignore(void) { void toku_txn_status_helgrind_ignore(void) {
......
...@@ -300,6 +300,8 @@ int toku_txn_abort_txn(struct tokutxn *txn, ...@@ -300,6 +300,8 @@ int toku_txn_abort_txn(struct tokutxn *txn,
int toku_txn_abort_with_lsn(struct tokutxn *txn, LSN oplsn, int toku_txn_abort_with_lsn(struct tokutxn *txn, LSN oplsn,
TXN_PROGRESS_POLL_FUNCTION poll, void *poll_extra); TXN_PROGRESS_POLL_FUNCTION poll, void *poll_extra);
int toku_txn_discard_txn(struct tokutxn *txn);
void toku_txn_prepare_txn (struct tokutxn *txn, TOKU_XA_XID *xid); void toku_txn_prepare_txn (struct tokutxn *txn, TOKU_XA_XID *xid);
// Effect: Do the internal work of preparing a transaction (does not log the prepare record). // Effect: Do the internal work of preparing a transaction (does not log the prepare record).
......
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
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.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
This software is covered by US Patent No. 8,489,638.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 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."
#include "test.h"
// Verify that a commit of a prepared txn in recovery retains a db that was created by it.
// The rollback file is dirty when the environment is closed.
static void create_foo(DB_ENV *env, DB_TXN *txn) {
int r;
DB *db;
r = db_create(&db, env, 0);
CKERR(r);
r = db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
r = db->close(db, 0);
CKERR(r);
}
static void check_foo(DB_ENV *env) {
int r;
DB *db;
r = db_create(&db, env, 0);
CKERR(r);
r = db->open(db, nullptr, "foo.db", 0, DB_BTREE, 0, 0);
CKERR(r);
r = db->close(db, 0);
CKERR(r);
}
static void create_prepared_txn(void) {
int r;
DB_ENV *env = nullptr;
r = db_env_create(&env, 0);
CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME,
DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE,
S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
DB_TXN *txn = nullptr;
r = env->txn_begin(env, nullptr, &txn, 0);
CKERR(r);
create_foo(env, txn);
TOKU_XA_XID xid = { 0x1234, 8, 9 };
for (int i = 0; i < 8+9; i++) {
xid.data[i] = i;
}
r = txn->xa_prepare(txn, &xid);
CKERR(r);
// discard the txn so that we can close the env and run xa recovery later
r = txn->discard(txn, 0);
CKERR(r);
r = env->close(env, TOKUFT_DIRTY_SHUTDOWN);
CKERR(r);
}
static void run_xa_recovery(void) {
int r;
DB_ENV *env;
r = db_env_create(&env, 0);
CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME,
DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE | DB_RECOVER,
S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
// get prepared xid
long count;
TOKU_XA_XID xid;
r = env->txn_xa_recover(env, &xid, 1, &count, DB_FIRST);
CKERR(r);
// commit it
DB_TXN *txn = nullptr;
r = env->get_txn_from_xid(env, &xid, &txn);
CKERR(r);
r = txn->commit(txn, 0);
CKERR(r);
check_foo(env);
r = env->close(env, 0);
CKERR(r);
}
int test_main (int argc, char *const argv[]) {
default_parse_args(argc, argv);
// init the env directory
toku_os_recursive_delete(TOKU_TEST_FILENAME);
int r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
// run the test
create_prepared_txn();
run_xa_recovery();
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
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.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
This software is covered by US Patent No. 8,489,638.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 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."
#include "test.h"
// Verify that an abort of a prepared txn in recovery deletes a db created by it.
// The rollback file is dirty when the environment is closed.
static void create_foo(DB_ENV *env, DB_TXN *txn) {
int r;
DB *db;
r = db_create(&db, env, 0);
CKERR(r);
r = db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
r = db->close(db, 0);
CKERR(r);
}
static void check_foo(DB_ENV *env) {
int r;
DB *db;
r = db_create(&db, env, 0);
CKERR(r);
r = db->open(db, nullptr, "foo.db", 0, DB_BTREE, 0, 0);
CKERR2(r, ENOENT);
r = db->close(db, 0);
CKERR(r);
}
static void create_prepared_txn(void) {
int r;
DB_ENV *env = nullptr;
r = db_env_create(&env, 0);
CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME,
DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE,
S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
DB_TXN *txn = nullptr;
r = env->txn_begin(env, nullptr, &txn, 0);
CKERR(r);
create_foo(env, txn);
TOKU_XA_XID xid = { 0x1234, 8, 9 };
for (int i = 0; i < 8+9; i++) {
xid.data[i] = i;
}
r = txn->xa_prepare(txn, &xid);
CKERR(r);
// discard the txn so that we can close the env and run xa recovery later
r = txn->discard(txn, 0);
CKERR(r);
r = env->close(env, TOKUFT_DIRTY_SHUTDOWN);
CKERR(r);
}
static void run_xa_recovery(void) {
int r;
DB_ENV *env;
r = db_env_create(&env, 0);
CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME,
DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE | DB_RECOVER,
S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
// get prepared xid
long count;
TOKU_XA_XID xid;
r = env->txn_xa_recover(env, &xid, 1, &count, DB_FIRST);
CKERR(r);
// abort it
DB_TXN *txn = nullptr;
r = env->get_txn_from_xid(env, &xid, &txn);
CKERR(r);
r = txn->abort(txn);
CKERR(r);
check_foo(env);
r = env->close(env, 0);
CKERR(r);
}
int test_main (int argc, char *const argv[]) {
default_parse_args(argc, argv);
// init the env directory
toku_os_recursive_delete(TOKU_TEST_FILENAME);
int r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
// run the test
create_prepared_txn();
run_xa_recovery();
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
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.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
This software is covered by US Patent No. 8,489,638.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 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."
#include "test.h"
// Verify that an abort of a prepared txn in recovery removes a db created by it.
// A checkpoint is taken between the db creation and the txn prepare.
static void create_foo(DB_ENV *env, DB_TXN *txn) {
int r;
DB *db;
r = db_create(&db, env, 0);
CKERR(r);
r = db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
r = db->close(db, 0);
CKERR(r);
}
static void check_foo(DB_ENV *env) {
int r;
DB *db;
r = db_create(&db, env, 0);
CKERR(r);
r = db->open(db, nullptr, "foo.db", 0, DB_BTREE, 0, 0);
CKERR2(r, ENOENT);
r = db->close(db, 0);
CKERR(r);
}
static void create_prepared_txn(void) {
int r;
DB_ENV *env = nullptr;
r = db_env_create(&env, 0);
CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME,
DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE,
S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
DB_TXN *txn = nullptr;
r = env->txn_begin(env, nullptr, &txn, 0);
CKERR(r);
create_foo(env, txn);
r = env->txn_checkpoint(env, 0, 0, 0);
CKERR(r);
TOKU_XA_XID xid = { 0x1234, 8, 9 };
for (int i = 0; i < 8+9; i++) {
xid.data[i] = i;
}
r = txn->xa_prepare(txn, &xid);
CKERR(r);
// discard the txn so that we can close the env and run xa recovery later
r = txn->discard(txn, 0);
CKERR(r);
r = env->close(env, TOKUFT_DIRTY_SHUTDOWN);
CKERR(r);
}
static void run_xa_recovery(void) {
int r;
DB_ENV *env;
r = db_env_create(&env, 0);
CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME,
DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE | DB_RECOVER,
S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
// get prepared xid
long count;
TOKU_XA_XID xid;
r = env->txn_xa_recover(env, &xid, 1, &count, DB_FIRST);
CKERR(r);
// abort it
DB_TXN *txn = nullptr;
r = env->get_txn_from_xid(env, &xid, &txn);
CKERR(r);
r = txn->abort(txn);
CKERR(r);
check_foo(env);
r = env->close(env, 0);
CKERR(r);
}
int test_main (int argc, char *const argv[]) {
default_parse_args(argc, argv);
// init the env directory
toku_os_recursive_delete(TOKU_TEST_FILENAME);
int r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
// run the test
create_prepared_txn();
run_xa_recovery();
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
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.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
This software is covered by US Patent No. 8,489,638.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 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."
#include "test.h"
// Verify that a commit of a prepared txn in recovery retains a db created by it.
// A checkpoint is taken between the db creation and the txn prepare.
static void create_foo(DB_ENV *env, DB_TXN *txn) {
int r;
DB *db;
r = db_create(&db, env, 0);
CKERR(r);
r = db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
r = db->close(db, 0);
CKERR(r);
}
static void check_foo(DB_ENV *env) {
int r;
DB *db;
r = db_create(&db, env, 0);
CKERR(r);
r = db->open(db, nullptr, "foo.db", 0, DB_BTREE, 0, 0);
CKERR(r);
r = db->close(db, 0);
CKERR(r);
}
static void create_prepared_txn(void) {
int r;
DB_ENV *env = nullptr;
r = db_env_create(&env, 0);
CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME,
DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE,
S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
DB_TXN *txn = nullptr;
r = env->txn_begin(env, nullptr, &txn, 0);
CKERR(r);
create_foo(env, txn);
r = env->txn_checkpoint(env, 0, 0, 0);
CKERR(r);
TOKU_XA_XID xid = { 0x1234, 8, 9 };
for (int i = 0; i < 8+9; i++) {
xid.data[i] = i;
}
r = txn->xa_prepare(txn, &xid);
CKERR(r);
// discard the txn so that we can close the env and run xa recovery later
r = txn->discard(txn, 0);
CKERR(r);
r = env->close(env, TOKUFT_DIRTY_SHUTDOWN);
CKERR(r);
}
static void run_xa_recovery(void) {
int r;
DB_ENV *env;
r = db_env_create(&env, 0);
CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME,
DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE | DB_RECOVER,
S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
// get prepared xid
long count;
TOKU_XA_XID xid;
r = env->txn_xa_recover(env, &xid, 1, &count, DB_FIRST);
CKERR(r);
// commit it
DB_TXN *txn = nullptr;
r = env->get_txn_from_xid(env, &xid, &txn);
CKERR(r);
r = txn->commit(txn, 0);
CKERR(r);
check_foo(env);
r = env->close(env, 0);
CKERR(r);
}
int test_main (int argc, char *const argv[]) {
default_parse_args(argc, argv);
// init the env directory
toku_os_recursive_delete(TOKU_TEST_FILENAME);
int r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
// run the test
create_prepared_txn();
run_xa_recovery();
return 0;
}
...@@ -1092,6 +1092,12 @@ static int ...@@ -1092,6 +1092,12 @@ static int
env_close(DB_ENV * env, uint32_t flags) { env_close(DB_ENV * env, uint32_t flags) {
int r = 0; int r = 0;
const char * err_msg = NULL; const char * err_msg = NULL;
bool clean_shutdown = true;
if (flags & TOKUFT_DIRTY_SHUTDOWN) {
clean_shutdown = false;
flags &= ~TOKUFT_DIRTY_SHUTDOWN;
}
most_recent_env = NULL; // Set most_recent_env to NULL so that we don't have a dangling pointer (and if there's an error, the toku assert code would try to look at the env.) most_recent_env = NULL; // Set most_recent_env to NULL so that we don't have a dangling pointer (and if there's an error, the toku assert code would try to look at the env.)
...@@ -1132,14 +1138,18 @@ env_close(DB_ENV * env, uint32_t flags) { ...@@ -1132,14 +1138,18 @@ env_close(DB_ENV * env, uint32_t flags) {
if (env->i->cachetable) { if (env->i->cachetable) {
toku_cachetable_minicron_shutdown(env->i->cachetable); toku_cachetable_minicron_shutdown(env->i->cachetable);
if (env->i->logger) { if (env->i->logger) {
CHECKPOINTER cp = toku_cachetable_get_checkpointer(env->i->cachetable); CHECKPOINTER cp = nullptr;
if (clean_shutdown) {
cp = toku_cachetable_get_checkpointer(env->i->cachetable);
r = toku_checkpoint(cp, env->i->logger, NULL, NULL, NULL, NULL, SHUTDOWN_CHECKPOINT); r = toku_checkpoint(cp, env->i->logger, NULL, NULL, NULL, NULL, SHUTDOWN_CHECKPOINT);
if (r) { if (r) {
err_msg = "Cannot close environment (error during checkpoint)\n"; err_msg = "Cannot close environment (error during checkpoint)\n";
toku_ydb_do_error(env, r, "%s", err_msg); toku_ydb_do_error(env, r, "%s", err_msg);
goto panic_and_quit_early; goto panic_and_quit_early;
} }
toku_logger_close_rollback(env->i->logger); }
toku_logger_close_rollback_check_empty(env->i->logger, clean_shutdown);
if (clean_shutdown) {
//Do a second checkpoint now that the rollback cachefile is closed. //Do a second checkpoint now that the rollback cachefile is closed.
r = toku_checkpoint(cp, env->i->logger, NULL, NULL, NULL, NULL, SHUTDOWN_CHECKPOINT); r = toku_checkpoint(cp, env->i->logger, NULL, NULL, NULL, NULL, SHUTDOWN_CHECKPOINT);
if (r) { if (r) {
...@@ -1149,6 +1159,7 @@ env_close(DB_ENV * env, uint32_t flags) { ...@@ -1149,6 +1159,7 @@ env_close(DB_ENV * env, uint32_t flags) {
} }
toku_logger_shutdown(env->i->logger); toku_logger_shutdown(env->i->logger);
} }
}
toku_cachetable_close(&env->i->cachetable); toku_cachetable_close(&env->i->cachetable);
} }
if (env->i->logger) { if (env->i->logger) {
......
...@@ -207,12 +207,6 @@ static int toku_txn_commit(DB_TXN * txn, uint32_t flags, ...@@ -207,12 +207,6 @@ static int toku_txn_commit(DB_TXN * txn, uint32_t flags,
return r; return r;
} }
static uint32_t toku_txn_id(DB_TXN * txn) {
HANDLE_PANICKED_ENV(txn->mgrp);
abort();
return (uint32_t) -1;
}
static int toku_txn_abort(DB_TXN * txn, static int toku_txn_abort(DB_TXN * txn,
TXN_PROGRESS_POLL_FUNCTION poll, void *poll_extra) { TXN_PROGRESS_POLL_FUNCTION poll, void *poll_extra) {
HANDLE_PANICKED_ENV(txn->mgrp); HANDLE_PANICKED_ENV(txn->mgrp);
...@@ -389,6 +383,44 @@ static uint64_t locked_txn_get_client_id(DB_TXN *txn) { ...@@ -389,6 +383,44 @@ static uint64_t locked_txn_get_client_id(DB_TXN *txn) {
return toku_txn_get_client_id(db_txn_struct_i(txn)->tokutxn); return toku_txn_get_client_id(db_txn_struct_i(txn)->tokutxn);
} }
static int toku_txn_discard(DB_TXN *txn, uint32_t flags) {
// check parameters
if (flags != 0)
return EINVAL;
TOKUTXN ttxn = db_txn_struct_i(txn)->tokutxn;
if (toku_txn_get_state(ttxn) != TOKUTXN_PREPARING)
return EINVAL;
bool low_priority;
if (toku_is_big_tokutxn(ttxn)) {
low_priority = true;
toku_low_priority_multi_operation_client_lock();
} else {
low_priority = false;
toku_multi_operation_client_lock();
}
// discard
toku_txn_discard_txn(ttxn);
// complete
toku_txn_complete_txn(ttxn);
// release locks
toku_txn_release_locks(txn);
if (low_priority) {
toku_low_priority_multi_operation_client_unlock();
} else {
toku_multi_operation_client_unlock();
}
// destroy
toku_txn_destroy(txn);
return 0;
}
static inline void txn_func_init(DB_TXN *txn) { static inline void txn_func_init(DB_TXN *txn) {
#define STXN(name) txn->name = locked_txn_ ## name #define STXN(name) txn->name = locked_txn_ ## name
STXN(abort); STXN(abort);
...@@ -402,8 +434,8 @@ static inline void txn_func_init(DB_TXN *txn) { ...@@ -402,8 +434,8 @@ static inline void txn_func_init(DB_TXN *txn) {
#define SUTXN(name) txn->name = toku_txn_ ## name #define SUTXN(name) txn->name = toku_txn_ ## name
SUTXN(prepare); SUTXN(prepare);
SUTXN(xa_prepare); SUTXN(xa_prepare);
SUTXN(discard);
#undef SUTXN #undef SUTXN
txn->id = toku_txn_id;
txn->id64 = toku_txn_id64; txn->id64 = toku_txn_id64;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment