Commit 6ddd159a authored by Yoni Fogel's avatar Yoni Fogel

refs #5117 Add documentation for txn optimizations

Use wrapper function toku_txn_is_read_only whenever it doesn't make sense to access variable directly

git-svn-id: file:///svn/toku/tokudb@45209 c7de825b-a66e-492c-adef-691d508d4ae1
parent ee27f373
...@@ -3068,8 +3068,7 @@ log_open_txn (OMTVALUE txnv, u_int32_t UU(index), void *extra) { ...@@ -3068,8 +3068,7 @@ log_open_txn (OMTVALUE txnv, u_int32_t UU(index), void *extra) {
FILENUMS open_filenums; FILENUMS open_filenums;
uint32_t num_filenums = toku_omt_size(txn->open_fts); uint32_t num_filenums = toku_omt_size(txn->open_fts);
FILENUM array[num_filenums]; FILENUM array[num_filenums];
if (!txn->begin_was_logged) { if (toku_txn_is_read_only(txn)) {
invariant(num_filenums == 0);
goto cleanup; goto cleanup;
} }
else { else {
......
...@@ -349,7 +349,10 @@ static void copy_xid (TOKU_XA_XID *dest, TOKU_XA_XID *source) { ...@@ -349,7 +349,10 @@ static void copy_xid (TOKU_XA_XID *dest, TOKU_XA_XID *source) {
int toku_txn_prepare_txn (TOKUTXN txn, TOKU_XA_XID *xa_xid) { int toku_txn_prepare_txn (TOKUTXN txn, TOKU_XA_XID *xa_xid) {
int r = 0; int r = 0;
if (txn->parent || toku_txn_is_read_only(txn)) { if (txn->parent || toku_txn_is_read_only(txn)) {
// nothing to do if there's a parent, or if it's read-only // We do not prepare children.
//
// Readonly transactions do the same if they commit or abort, so
// XA guarantees are free. No need to pay for overhead of prepare.
goto cleanup; goto cleanup;
} }
toku_txn_manager_add_prepared_txn(txn->logger->txn_manager, txn); toku_txn_manager_add_prepared_txn(txn->logger->txn_manager, txn);
......
...@@ -551,7 +551,7 @@ void toku_txn_manager_finish_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { ...@@ -551,7 +551,7 @@ void toku_txn_manager_finish_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
r = toku_omt_delete_at(txn_manager->live_root_txns, idx); r = toku_omt_delete_at(txn_manager->live_root_txns, idx);
invariant_zero(r); invariant_zero(r);
if (txn->begin_was_logged || garbage_collection_debug) { if (!toku_txn_is_read_only(txn) || garbage_collection_debug) {
if (!is_snapshot) { if (!is_snapshot) {
// If it's a snapshot, we already calculated index_in_snapshot_txnids. // If it's a snapshot, we already calculated index_in_snapshot_txnids.
// Otherwise, calculate it now. // Otherwise, calculate it now.
...@@ -693,7 +693,14 @@ static void invalidate_xa_xid (TOKU_XA_XID *xid) { ...@@ -693,7 +693,14 @@ static void invalidate_xa_xid (TOKU_XA_XID *xid) {
} }
void toku_txn_manager_note_abort_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { void toku_txn_manager_note_abort_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
// Purpose:
// Delay until any indexer is done pinning this transaction.
// Update status of a transaction from live->aborting (or prepared->aborting)
// Do so in a thread-safe manner that does not conflict with hot indexing or
// begin checkpoint.
if (toku_txn_is_read_only(txn)) { if (toku_txn_is_read_only(txn)) {
// Neither hot indexing nor checkpoint do any work with readonly txns,
// so we can skip taking the txn_manager lock here.
invariant(txn->state==TOKUTXN_LIVE); invariant(txn->state==TOKUTXN_LIVE);
txn->state = TOKUTXN_ABORTING; txn->state = TOKUTXN_ABORTING;
goto done; goto done;
...@@ -720,7 +727,14 @@ done: ...@@ -720,7 +727,14 @@ done:
} }
void toku_txn_manager_note_commit_txn(TXN_MANAGER txn_manager, TOKUTXN txn) { void toku_txn_manager_note_commit_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
// Purpose:
// Delay until any indexer is done pinning this transaction.
// Update status of a transaction from live->committing (or prepared->committing)
// Do so in a thread-safe manner that does not conflict with hot indexing or
// begin checkpoint.
if (toku_txn_is_read_only(txn)) { if (toku_txn_is_read_only(txn)) {
// Neither hot indexing nor checkpoint do any work with readonly txns,
// so we can skip taking the txn_manager lock here.
invariant(txn->state==TOKUTXN_LIVE); invariant(txn->state==TOKUTXN_LIVE);
txn->state = TOKUTXN_COMMITTING; txn->state = TOKUTXN_COMMITTING;
goto done; goto done;
......
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