Commit 2c1ad51c authored by John Esmet's avatar John Esmet Committed by Yoni Fogel

refs #5349 committing txn_manage_lock and unlock wrapper functions to main

git-svn-id: file:///svn/toku/tokudb@46624 c7de825b-a66e-492c-adef-691d508d4ae1
parent 1c7e62ad
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
bool garbage_collection_debug = false; bool garbage_collection_debug = false;
// internal locking functions, should use this instead of accessing lock directly
static void txn_manager_lock(TXN_MANAGER txn_manager);
static void txn_manager_unlock(TXN_MANAGER txn_manager);
static bool is_txnid_live(TXN_MANAGER txn_manager, TXNID txnid) { static bool is_txnid_live(TXN_MANAGER txn_manager, TXNID txnid) {
TOKUTXN result = NULL; TOKUTXN result = NULL;
...@@ -196,7 +199,7 @@ void toku_txn_manager_destroy(TXN_MANAGER txn_manager) { ...@@ -196,7 +199,7 @@ void toku_txn_manager_destroy(TXN_MANAGER txn_manager) {
TXNID TXNID
toku_txn_manager_get_oldest_living_xid(TXN_MANAGER txn_manager) { toku_txn_manager_get_oldest_living_xid(TXN_MANAGER txn_manager) {
TXNID rval = TXNID_NONE_LIVING; TXNID rval = TXNID_NONE_LIVING;
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
if (txn_manager->live_root_txns.size() > 0) { if (txn_manager->live_root_txns.size() > 0) {
// We use live_root_txns because roots are always older than children, // We use live_root_txns because roots are always older than children,
...@@ -204,7 +207,7 @@ toku_txn_manager_get_oldest_living_xid(TXN_MANAGER txn_manager) { ...@@ -204,7 +207,7 @@ toku_txn_manager_get_oldest_living_xid(TXN_MANAGER txn_manager) {
int r = txn_manager->live_root_txns.fetch(0, &rval); int r = txn_manager->live_root_txns.fetch(0, &rval);
invariant_zero(r); invariant_zero(r);
} }
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
return rval; return rval;
} }
...@@ -286,7 +289,7 @@ int toku_txn_manager_start_txn( ...@@ -286,7 +289,7 @@ int toku_txn_manager_start_txn(
// the act of getting a transaction ID and adding the // the act of getting a transaction ID and adding the
// txn to the proper OMTs must be atomic. MVCC depends // txn to the proper OMTs must be atomic. MVCC depends
// on this. // on this.
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
if (garbage_collection_debug) { if (garbage_collection_debug) {
verify_snapshot_system(txn_manager); verify_snapshot_system(txn_manager);
} }
...@@ -376,7 +379,7 @@ int toku_txn_manager_start_txn( ...@@ -376,7 +379,7 @@ int toku_txn_manager_start_txn(
if (garbage_collection_debug) { if (garbage_collection_debug) {
verify_snapshot_system(txn_manager); verify_snapshot_system(txn_manager);
} }
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
*txnp = txn; *txnp = txn;
return 0; return 0;
...@@ -461,7 +464,7 @@ find_xid (const TOKUTXN &txn, const TOKUTXN &txnfind) ...@@ -461,7 +464,7 @@ find_xid (const TOKUTXN &txn, const TOKUTXN &txnfind)
void toku_txn_manager_finish_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { void toku_txn_manager_finish_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
int r; int r;
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
if (garbage_collection_debug) { if (garbage_collection_debug) {
verify_snapshot_system(txn_manager); verify_snapshot_system(txn_manager);
...@@ -529,7 +532,7 @@ void toku_txn_manager_finish_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { ...@@ -529,7 +532,7 @@ void toku_txn_manager_finish_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
if (garbage_collection_debug) { if (garbage_collection_debug) {
verify_snapshot_system(txn_manager); verify_snapshot_system(txn_manager);
} }
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
//Cleanup that does not require the txn_manager lock //Cleanup that does not require the txn_manager lock
if (is_snapshot) { if (is_snapshot) {
...@@ -546,11 +549,11 @@ void toku_txn_manager_clone_state_for_gc( ...@@ -546,11 +549,11 @@ void toku_txn_manager_clone_state_for_gc(
xid_omt_t &live_root_txns xid_omt_t &live_root_txns
) )
{ {
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
snapshot_xids.clone(txn_manager->snapshot_txnids); snapshot_xids.clone(txn_manager->snapshot_txnids);
referenced_xids.clone(txn_manager->referenced_xids); referenced_xids.clone(txn_manager->referenced_xids);
live_root_txns.clone(txn_manager->live_root_txns); live_root_txns.clone(txn_manager->live_root_txns);
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
} }
void toku_txn_manager_id2txn_unlocked(TXN_MANAGER txn_manager, TXNID txnid, TOKUTXN *result) { void toku_txn_manager_id2txn_unlocked(TXN_MANAGER txn_manager, TXNID txnid, TOKUTXN *result) {
...@@ -568,13 +571,13 @@ void toku_txn_manager_id2txn_unlocked(TXN_MANAGER txn_manager, TXNID txnid, TOKU ...@@ -568,13 +571,13 @@ void toku_txn_manager_id2txn_unlocked(TXN_MANAGER txn_manager, TXNID txnid, TOKU
} }
void toku_txn_manager_id2txn(TXN_MANAGER txn_manager, TXNID txnid, TOKUTXN *result) { void toku_txn_manager_id2txn(TXN_MANAGER txn_manager, TXNID txnid, TOKUTXN *result) {
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
toku_txn_manager_id2txn_unlocked(txn_manager, txnid, result); toku_txn_manager_id2txn_unlocked(txn_manager, txnid, result);
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
} }
int toku_txn_manager_get_txn_from_xid (TXN_MANAGER txn_manager, TOKU_XA_XID *xid, DB_TXN **txnp) { int toku_txn_manager_get_txn_from_xid (TXN_MANAGER txn_manager, TOKU_XA_XID *xid, DB_TXN **txnp) {
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
int ret_val = 0; int ret_val = 0;
int num_live_txns = txn_manager->live_txns.size(); int num_live_txns = txn_manager->live_txns.size();
for (int i = 0; i < num_live_txns; i++) { for (int i = 0; i < num_live_txns; i++) {
...@@ -594,24 +597,24 @@ int toku_txn_manager_get_txn_from_xid (TXN_MANAGER txn_manager, TOKU_XA_XID *xid ...@@ -594,24 +597,24 @@ int toku_txn_manager_get_txn_from_xid (TXN_MANAGER txn_manager, TOKU_XA_XID *xid
} }
ret_val = DB_NOTFOUND; ret_val = DB_NOTFOUND;
exit: exit:
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
return ret_val; return ret_val;
} }
uint32_t toku_txn_manager_num_live_txns(TXN_MANAGER txn_manager) { uint32_t toku_txn_manager_num_live_txns(TXN_MANAGER txn_manager) {
int ret_val = 0; int ret_val = 0;
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
ret_val = txn_manager->live_txns.size(); ret_val = txn_manager->live_txns.size();
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
return ret_val; return ret_val;
} }
void toku_txn_manager_add_prepared_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { void toku_txn_manager_add_prepared_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
assert(txn->state==TOKUTXN_LIVE); assert(txn->state==TOKUTXN_LIVE);
txn->state = TOKUTXN_PREPARING; // This state transition must be protected against begin_checkpoint txn->state = TOKUTXN_PREPARING; // This state transition must be protected against begin_checkpoint
toku_list_push(&txn_manager->prepared_txns, &txn->prepared_txns_link); toku_list_push(&txn_manager->prepared_txns, &txn->prepared_txns_link);
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
} }
static void invalidate_xa_xid (TOKU_XA_XID *xid) { static void invalidate_xa_xid (TOKU_XA_XID *xid) {
...@@ -632,7 +635,7 @@ void toku_txn_manager_note_abort_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { ...@@ -632,7 +635,7 @@ void toku_txn_manager_note_abort_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
txn->state = TOKUTXN_ABORTING; txn->state = TOKUTXN_ABORTING;
goto done; goto done;
} }
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
if (txn->state==TOKUTXN_PREPARING) { if (txn->state==TOKUTXN_PREPARING) {
invalidate_xa_xid(&txn->xa_xid); invalidate_xa_xid(&txn->xa_xid);
toku_list_remove(&txn->prepared_txns_link); toku_list_remove(&txn->prepared_txns_link);
...@@ -648,7 +651,7 @@ void toku_txn_manager_note_abort_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { ...@@ -648,7 +651,7 @@ void toku_txn_manager_note_abort_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
); );
} }
txn->state = TOKUTXN_ABORTING; txn->state = TOKUTXN_ABORTING;
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
done: done:
return; return;
} }
...@@ -666,7 +669,7 @@ void toku_txn_manager_note_commit_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { ...@@ -666,7 +669,7 @@ void toku_txn_manager_note_commit_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
txn->state = TOKUTXN_COMMITTING; txn->state = TOKUTXN_COMMITTING;
goto done; goto done;
} }
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
if (txn->state==TOKUTXN_PREPARING) { if (txn->state==TOKUTXN_PREPARING) {
invalidate_xa_xid(&txn->xa_xid); invalidate_xa_xid(&txn->xa_xid);
toku_list_remove(&txn->prepared_txns_link); toku_list_remove(&txn->prepared_txns_link);
...@@ -682,7 +685,7 @@ void toku_txn_manager_note_commit_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { ...@@ -682,7 +685,7 @@ void toku_txn_manager_note_commit_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
); );
} }
txn->state = TOKUTXN_COMMITTING; txn->state = TOKUTXN_COMMITTING;
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
done: done:
return; return;
} }
...@@ -696,7 +699,7 @@ int toku_txn_manager_recover_txn ( ...@@ -696,7 +699,7 @@ int toku_txn_manager_recover_txn (
) )
{ {
int ret_val = 0; int ret_val = 0;
toku_mutex_lock(&txn_manager->txn_manager_lock); txn_manager_lock(txn_manager);
if (flags==DB_FIRST) { if (flags==DB_FIRST) {
// Anything in the returned list goes back on the prepared list. // Anything in the returned list goes back on the prepared list.
while (!toku_list_empty(&txn_manager->prepared_and_returned_txns)) { while (!toku_list_empty(&txn_manager->prepared_and_returned_txns)) {
...@@ -725,7 +728,7 @@ int toku_txn_manager_recover_txn ( ...@@ -725,7 +728,7 @@ int toku_txn_manager_recover_txn (
*retp = i; *retp = i;
ret_val = 0; ret_val = 0;
exit: exit:
toku_mutex_unlock(&txn_manager->txn_manager_lock); txn_manager_unlock(txn_manager);
return ret_val; return ret_val;
} }
...@@ -751,13 +754,22 @@ void toku_txn_manager_unpin_live_txn_unlocked(TXN_MANAGER txn_manager, TOKUTXN t ...@@ -751,13 +754,22 @@ void toku_txn_manager_unpin_live_txn_unlocked(TXN_MANAGER txn_manager, TOKUTXN t
} }
} }
void toku_txn_manager_suspend(TXN_MANAGER txn_manager) { static void txn_manager_lock(TXN_MANAGER txn_manager) {
toku_mutex_lock(&txn_manager->txn_manager_lock); toku_mutex_lock(&txn_manager->txn_manager_lock);
} }
void toku_txn_manager_resume(TXN_MANAGER txn_manager) {
static void txn_manager_unlock(TXN_MANAGER txn_manager) {
toku_mutex_unlock(&txn_manager->txn_manager_lock); toku_mutex_unlock(&txn_manager->txn_manager_lock);
} }
void toku_txn_manager_suspend(TXN_MANAGER txn_manager) {
txn_manager_lock(txn_manager);
}
void toku_txn_manager_resume(TXN_MANAGER txn_manager) {
txn_manager_unlock(txn_manager);
}
void void
toku_txn_manager_set_last_xid_from_logger(TXN_MANAGER txn_manager, TXNID last_xid) { toku_txn_manager_set_last_xid_from_logger(TXN_MANAGER txn_manager, TXNID last_xid) {
invariant(txn_manager->last_xid == TXNID_NONE); invariant(txn_manager->last_xid == TXNID_NONE);
...@@ -771,17 +783,17 @@ toku_txn_manager_set_last_xid_from_recovered_checkpoint(TXN_MANAGER txn_manager, ...@@ -771,17 +783,17 @@ toku_txn_manager_set_last_xid_from_recovered_checkpoint(TXN_MANAGER txn_manager,
TXNID TXNID
toku_txn_manager_get_last_xid(TXN_MANAGER mgr) { toku_txn_manager_get_last_xid(TXN_MANAGER mgr) {
toku_mutex_lock(&mgr->txn_manager_lock); txn_manager_lock(mgr);
TXNID last_xid = mgr->last_xid; TXNID last_xid = mgr->last_xid;
toku_mutex_unlock(&mgr->txn_manager_lock); txn_manager_unlock(mgr);
return last_xid; return last_xid;
} }
// Test-only function // Test-only function
void void
toku_txn_manager_increase_last_xid(TXN_MANAGER mgr, uint64_t increment) { toku_txn_manager_increase_last_xid(TXN_MANAGER mgr, uint64_t increment) {
toku_mutex_lock(&mgr->txn_manager_lock); txn_manager_lock(mgr);
mgr->last_xid += increment; mgr->last_xid += increment;
toku_mutex_unlock(&mgr->txn_manager_lock); txn_manager_unlock(mgr);
} }
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