Commit d9ec343b authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#4455 add txn create and start to the tokutxn API. this allows a txn to be...

#4455 add txn create and start to the tokutxn API.  this allows a txn to be created without holding any locks refs[t:4455]

git-svn-id: file:///svn/toku/tokudb@40438 c7de825b-a66e-492c-adef-691d508d4ae1
parent 6aa2c88f
...@@ -474,7 +474,7 @@ recover_transaction(TOKUTXN *txnp, TXNID xid, TXNID parentxid, TOKULOGGER logger ...@@ -474,7 +474,7 @@ recover_transaction(TOKUTXN *txnp, TXNID xid, TXNID parentxid, TOKULOGGER logger
assert(r == 0); assert(r == 0);
assert(txn==NULL); assert(txn==NULL);
} }
r = toku_txn_begin_with_xid(parent, &txn, logger, xid, TXN_SNAPSHOT_NONE); r = toku_txn_begin_with_xid(parent, &txn, logger, xid, TXN_SNAPSHOT_NONE, NULL);
assert(r == 0); assert(r == 0);
if (txnp) *txnp = txn; if (txnp) *txnp = txn;
return 0; return 0;
......
...@@ -24,7 +24,7 @@ test_main(int argc, const char *argv[]) { ...@@ -24,7 +24,7 @@ test_main(int argc, const char *argv[]) {
int r; int r;
r = toku_txn_ignore_init(txn); CKERR(r); toku_txn_ignore_init(txn);
FILENUM f1 = {1}; FILENUM f1 = {1};
FILENUM f2 = {2}; FILENUM f2 = {2};
......
This diff is collapsed.
...@@ -26,9 +26,16 @@ int toku_txn_begin_with_xid ( ...@@ -26,9 +26,16 @@ int toku_txn_begin_with_xid (
TOKUTXN *tokutxn, TOKUTXN *tokutxn,
TOKULOGGER logger, TOKULOGGER logger,
TXNID xid, TXNID xid,
TXN_SNAPSHOT_TYPE snapshot_type TXN_SNAPSHOT_TYPE snapshot_type,
DB_TXN *container_db_txn
); );
// Allocate and initialize a txn
int toku_txn_create_txn(TOKUTXN *txn_ptr, TOKUTXN parent, TOKULOGGER logger, TXNID xid, TXN_SNAPSHOT_TYPE snapshot_type, DB_TXN *container_db_txn);
// Assign a txnid. Log the txn begin in the recovery log. Initialize the txn live lists.
int toku_txn_start_txn(TOKUTXN txn);
int toku_txn_load_txninfo (TOKUTXN txn, TXNINFO info); int toku_txn_load_txninfo (TOKUTXN txn, TXNINFO info);
int toku_txn_commit_txn (TOKUTXN txn, int nosync, YIELDF yield, void *yieldv, int toku_txn_commit_txn (TOKUTXN txn, int nosync, YIELDF yield, void *yieldv,
...@@ -50,11 +57,11 @@ int toku_txn_maybe_fsync_log(TOKULOGGER logger, LSN do_fsync_lsn, BOOL do_fsync, ...@@ -50,11 +57,11 @@ int toku_txn_maybe_fsync_log(TOKULOGGER logger, LSN do_fsync_lsn, BOOL do_fsync,
void toku_txn_get_fsync_info(TOKUTXN ttxn, BOOL* do_fsync, LSN* do_fsync_lsn); void toku_txn_get_fsync_info(TOKUTXN ttxn, BOOL* do_fsync, LSN* do_fsync_lsn);
// Rollback and destroy a txn // Complete and destroy a txn
void toku_txn_close_txn(TOKUTXN txn); void toku_txn_close_txn(TOKUTXN txn);
// Remove the txn from any live txn lists // Remove a txn from any live txn lists
void toku_txn_rollback_txn(TOKUTXN txn); void toku_txn_complete_txn(TOKUTXN txn);
// Free the memory of a txn // Free the memory of a txn
void toku_txn_destroy_txn(TOKUTXN txn); void toku_txn_destroy_txn(TOKUTXN txn);
...@@ -73,7 +80,6 @@ BOOL toku_txnid_newer(TXNID a, TXNID b); ...@@ -73,7 +80,6 @@ BOOL toku_txnid_newer(TXNID a, TXNID b);
// Force fsync on commit // Force fsync on commit
void toku_txn_force_fsync_on_commit(TOKUTXN txn); void toku_txn_force_fsync_on_commit(TOKUTXN txn);
typedef enum { typedef enum {
TXN_BEGIN, // total number of transactions begun (does not include recovered txns) TXN_BEGIN, // total number of transactions begun (does not include recovered txns)
TXN_COMMIT, // successful commits TXN_COMMIT, // successful commits
...@@ -108,7 +114,7 @@ typedef struct tokutxn_filenum_ignore_errors { ...@@ -108,7 +114,7 @@ typedef struct tokutxn_filenum_ignore_errors {
FILENUMS filenums; FILENUMS filenums;
} TXN_IGNORE_S, *TXN_IGNORE; } TXN_IGNORE_S, *TXN_IGNORE;
int toku_txn_ignore_init(TOKUTXN txn); void toku_txn_ignore_init(TOKUTXN txn);
void toku_txn_ignore_free(TOKUTXN txn); void toku_txn_ignore_free(TOKUTXN txn);
int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum); int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum);
int toku_txn_ignore_remove(TOKUTXN txn, FILENUM filenum); int toku_txn_ignore_remove(TOKUTXN txn, FILENUM filenum);
......
...@@ -939,7 +939,7 @@ toku_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mode) { ...@@ -939,7 +939,7 @@ toku_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mode) {
DB_TXN *txn=NULL; DB_TXN *txn=NULL;
if (using_txns) { if (using_txns) {
r = toku_txn_begin_internal(env, 0, &txn, 0, 1, true); r = toku_txn_begin(env, 0, &txn, 0, 1, true);
assert_zero(r); assert_zero(r);
} }
...@@ -2380,7 +2380,7 @@ toku_env_create(DB_ENV ** envp, u_int32_t flags) { ...@@ -2380,7 +2380,7 @@ toku_env_create(DB_ENV ** envp, u_int32_t flags) {
result->set_errcall = toku_env_set_errcall; result->set_errcall = toku_env_set_errcall;
result->set_errfile = toku_env_set_errfile; result->set_errfile = toku_env_set_errfile;
result->set_errpfx = toku_env_set_errpfx; result->set_errpfx = toku_env_set_errpfx;
result->txn_begin = toku_txn_begin; result->txn_begin = locked_txn_begin;
MALLOC(result->i); MALLOC(result->i);
if (result->i == 0) { r = ENOMEM; goto cleanup; } if (result->i == 0) { r = ENOMEM; goto cleanup; }
...@@ -2653,7 +2653,7 @@ toku_env_dbremove(DB_ENV * env, DB_TXN *txn, const char *fname, const char *dbna ...@@ -2653,7 +2653,7 @@ toku_env_dbremove(DB_ENV * env, DB_TXN *txn, const char *fname, const char *dbna
DB_TXN *child = NULL; DB_TXN *child = NULL;
// begin child (unless transactionless) // begin child (unless transactionless)
if (using_txns) { if (using_txns) {
r = toku_txn_begin_internal(env, txn, &child, DB_TXN_NOSYNC, 1, true); r = toku_txn_begin(env, txn, &child, DB_TXN_NOSYNC, 1, true);
assert_zero(r); assert_zero(r);
} }
...@@ -2757,7 +2757,7 @@ toku_env_dbrename(DB_ENV *env, DB_TXN *txn, const char *fname, const char *dbnam ...@@ -2757,7 +2757,7 @@ toku_env_dbrename(DB_ENV *env, DB_TXN *txn, const char *fname, const char *dbnam
DB_TXN *child = NULL; DB_TXN *child = NULL;
// begin child (unless transactionless) // begin child (unless transactionless)
if (using_txns) { if (using_txns) {
r = toku_txn_begin_internal(env, txn, &child, DB_TXN_NOSYNC, 1, true); r = toku_txn_begin(env, txn, &child, DB_TXN_NOSYNC, 1, true);
assert_zero(r); assert_zero(r);
} }
......
...@@ -305,7 +305,7 @@ toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname, DBTYP ...@@ -305,7 +305,7 @@ toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname, DBTYP
DB_TXN *child = NULL; DB_TXN *child = NULL;
// begin child (unless transactionless) // begin child (unless transactionless)
if (using_txns) { if (using_txns) {
r = toku_txn_begin_internal(db->dbenv, txn, &child, DB_TXN_NOSYNC, 1, true); r = toku_txn_begin(db->dbenv, txn, &child, DB_TXN_NOSYNC, 1, true);
assert(r==0); assert(r==0);
} }
...@@ -641,7 +641,7 @@ toku_db_pre_acquire_table_lock(DB *db, DB_TXN *txn, BOOL UU(just_lock)) { ...@@ -641,7 +641,7 @@ toku_db_pre_acquire_table_lock(DB *db, DB_TXN *txn, BOOL UU(just_lock)) {
{ {
// begin child // begin child
int rt = toku_txn_begin_internal(env, txn, &child, DB_TXN_NOSYNC, 1, true); int rt = toku_txn_begin(env, txn, &child, DB_TXN_NOSYNC, 1, true);
assert(rt==0); assert(rt==0);
} }
...@@ -1090,7 +1090,7 @@ ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_iname ...@@ -1090,7 +1090,7 @@ ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_iname
// begin child (unless transactionless) // begin child (unless transactionless)
if (using_txns) { if (using_txns) {
rval = toku_txn_begin_internal(env, txn, &child, DB_TXN_NOSYNC, 1, true); rval = toku_txn_begin(env, txn, &child, DB_TXN_NOSYNC, 1, true);
assert(rval == 0); assert(rval == 0);
xid = toku_txn_get_txnid(db_txn_struct_i(child)->tokutxn); xid = toku_txn_get_txnid(db_txn_struct_i(child)->tokutxn);
} }
......
...@@ -57,7 +57,7 @@ toku_db_construct_autotxn(DB* db, DB_TXN **txn, BOOL* changed, BOOL force_auto_c ...@@ -57,7 +57,7 @@ toku_db_construct_autotxn(DB* db, DB_TXN **txn, BOOL* changed, BOOL force_auto_c
} }
BOOL nosync = (BOOL)(!force_auto_commit && !(env->i->open_flags & DB_AUTO_COMMIT)); BOOL nosync = (BOOL)(!force_auto_commit && !(env->i->open_flags & DB_AUTO_COMMIT));
u_int32_t txn_flags = DB_TXN_NOWAIT | (nosync ? DB_TXN_NOSYNC : 0); u_int32_t txn_flags = DB_TXN_NOWAIT | (nosync ? DB_TXN_NOSYNC : 0);
int r = toku_txn_begin_internal(env, NULL, txn, txn_flags, 1, holds_ydb_lock); int r = toku_txn_begin(env, NULL, txn, txn_flags, 1, holds_ydb_lock);
if (r!=0) return r; if (r!=0) return r;
*changed = TRUE; *changed = TRUE;
return 0; return 0;
......
...@@ -139,7 +139,7 @@ toku_txn_commit_only(DB_TXN * txn, u_int32_t flags, ...@@ -139,7 +139,7 @@ toku_txn_commit_only(DB_TXN * txn, u_int32_t flags,
// in the test_stress tests. // in the test_stress tests.
// //
toku_txn_get_fsync_info(ttxn, &do_fsync, &do_fsync_lsn); toku_txn_get_fsync_info(ttxn, &do_fsync, &do_fsync_lsn);
toku_txn_rollback_txn(ttxn); toku_txn_complete_txn(ttxn);
toku_txn_maybe_fsync_log(logger, do_fsync_lsn, do_fsync, ydb_yield, NULL); toku_txn_maybe_fsync_log(logger, do_fsync_lsn, do_fsync, ydb_yield, NULL);
//Promote list to parent (dbs that must close before abort) //Promote list to parent (dbs that must close before abort)
...@@ -210,7 +210,7 @@ toku_txn_abort_only(DB_TXN * txn, ...@@ -210,7 +210,7 @@ toku_txn_abort_only(DB_TXN * txn,
HANDLE_PANICKED_ENV(txn->mgrp); HANDLE_PANICKED_ENV(txn->mgrp);
assert_zero(r); assert_zero(r);
r = toku_txn_release_locks(txn); r = toku_txn_release_locks(txn);
toku_txn_rollback_txn(db_txn_struct_i(txn)->tokutxn); toku_txn_complete_txn(db_txn_struct_i(txn)->tokutxn);
return r; return r;
} }
...@@ -226,8 +226,8 @@ toku_txn_abort(DB_TXN * txn, ...@@ -226,8 +226,8 @@ toku_txn_abort(DB_TXN * txn,
// Create a new transaction. // Create a new transaction.
// Called without holding the ydb lock. // Called without holding the ydb lock.
int int
toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags) { locked_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags) {
int r = toku_txn_begin_internal(env, stxn, txn, flags, 0, false); int r = toku_txn_begin(env, stxn, txn, flags, 0, false);
return r; return r;
} }
...@@ -306,13 +306,16 @@ locked_txn_abort(DB_TXN *txn) { ...@@ -306,13 +306,16 @@ locked_txn_abort(DB_TXN *txn) {
} }
int int
toku_txn_begin_internal(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags, bool internal, bool holds_ydb_lock) { toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags, bool internal, bool holds_ydb_lock) {
HANDLE_PANICKED_ENV(env); HANDLE_PANICKED_ENV(env);
HANDLE_ILLEGAL_WORKING_PARENT_TXN(env, stxn); //Cannot create child while child already exists. HANDLE_ILLEGAL_WORKING_PARENT_TXN(env, stxn); //Cannot create child while child already exists.
if (!toku_logger_is_open(env->i->logger)) return toku_ydb_do_error(env, EINVAL, "Environment does not have logging enabled\n"); if (!toku_logger_is_open(env->i->logger))
if (!(env->i->open_flags & DB_INIT_TXN)) return toku_ydb_do_error(env, EINVAL, "Environment does not have transactions enabled\n"); return toku_ydb_do_error(env, EINVAL, "Environment does not have logging enabled\n");
if (!(env->i->open_flags & DB_INIT_TXN))
return toku_ydb_do_error(env, EINVAL, "Environment does not have transactions enabled\n");
u_int32_t txn_flags = 0; u_int32_t txn_flags = 0;
txn_flags |= DB_TXN_NOWAIT; //We do not support blocking locks. txn_flags |= DB_TXN_NOWAIT; //We do not support blocking locks. RFP remove this?
TOKU_ISOLATION child_isolation = TOKU_ISO_SERIALIZABLE; TOKU_ISOLATION child_isolation = TOKU_ISO_SERIALIZABLE;
u_int32_t iso_flags = flags & DB_ISOLATION_FLAGS; u_int32_t iso_flags = flags & DB_ISOLATION_FLAGS;
if (!(iso_flags == 0 || if (!(iso_flags == 0 ||
...@@ -420,7 +423,6 @@ toku_txn_begin_internal(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t fla ...@@ -420,7 +423,6 @@ toku_txn_begin_internal(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t fla
// created. // created.
int r = 0; int r = 0;
//r = toku_logger_txn_begin(stxn ? db_txn_struct_i(stxn)->tokutxn : 0, &db_txn_struct_i(result)->tokutxn, env->i->logger);
TXN_SNAPSHOT_TYPE snapshot_type; TXN_SNAPSHOT_TYPE snapshot_type;
switch(db_txn_struct_i(result)->iso){ switch(db_txn_struct_i(result)->iso){
case(TOKU_ISO_SNAPSHOT): case(TOKU_ISO_SNAPSHOT):
...@@ -439,14 +441,20 @@ toku_txn_begin_internal(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t fla ...@@ -439,14 +441,20 @@ toku_txn_begin_internal(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t fla
break; break;
} }
} }
if (!holds_ydb_lock) toku_ydb_lock(); r = toku_txn_create_txn(&db_txn_struct_i(result)->tokutxn,
r = toku_txn_begin_txn(result, stxn ? db_txn_struct_i(stxn)->tokutxn : 0,
stxn ? db_txn_struct_i(stxn)->tokutxn : 0, env->i->logger,
&db_txn_struct_i(result)->tokutxn, TXNID_NONE,
env->i->logger, snapshot_type,
snapshot_type result
); );
if (!holds_ydb_lock) toku_ydb_unlock(); if (r != 0)
return r;
if (!holds_ydb_lock)
toku_ydb_lock();
r = toku_txn_start_txn(db_txn_struct_i(result)->tokutxn);
if (!holds_ydb_lock)
toku_ydb_unlock();
if (r != 0) if (r != 0)
return r; return r;
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
extern "C" { extern "C" {
#endif #endif
int toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags); int locked_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags);
int toku_txn_begin_internal(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags, bool internal, bool holds_ydb_lock); int toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags, bool internal, bool holds_ydb_lock);
int toku_txn_commit(DB_TXN * txn, u_int32_t flags, TXN_PROGRESS_POLL_FUNCTION, void*, bool release_multi_operation_client_lock); int toku_txn_commit(DB_TXN * txn, u_int32_t flags, TXN_PROGRESS_POLL_FUNCTION, void*, bool release_multi_operation_client_lock);
int toku_txn_abort(DB_TXN * txn, TXN_PROGRESS_POLL_FUNCTION, void*, bool release_multi_operation_client_lock); int toku_txn_abort(DB_TXN * txn, TXN_PROGRESS_POLL_FUNCTION, void*, bool release_multi_operation_client_lock);
int locked_txn_commit(DB_TXN *txn, u_int32_t flags); int locked_txn_commit(DB_TXN *txn, u_int32_t flags);
......
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