Collaboration diagram for Transactions, Locking and Logging:
![]() |
A very few storage manager operations, such as formatting a volume, are called outside the scope of a transaction and the storage manager begins its own transaction to do the work.
Operations that fail return an error indication and the storage manager assumes that the server will thereafter abort the transaction in which the error occurred, when abort is indicated. Abort is indicated when eUSERABORT or eDEADLOCK is returned and when the erver chooses to abort rather than to work around the problem (whatever it might be, such as eRETRY).
The storage manager does not enforce the aborting of any erroneous transactions except, possibly, those that are in danger of running out of log space. (This is done with the destructor of the prologue used on each call to the storage manager, see next paragraph).
It is always the server's responsibility to abort. When the storage manager encounters a eLOGSPACEWARN condition (the log hasn't enough space at this moment to abort the running transaction, assuming a 1:1 ration of rollback-logging overhead to forward-processing logging overhead), it does one of two things:
Key-value locking is normally used for B+-Trees. (See [MOH1].) R*-Trees normally use coarse-granularity locking. The locking protocol used with an index is determined when the index is created. A transaction may acquire coarse (index-level) locks with explicit calls to the lock manager, but by default, the granularity/level/protocol associated with the index is used. See smlevel_0::concurrency_t.
To reduce the cost (particularly in logging) of loading databases, the storage manager provides for unlogged loading of stores. See Stores.
All work performed on behalf of a transaction must occur while that transaction is "attached" to the thread that performs the work. Creating a transaction attaches it to the thread that creates the transaction. The thread may detach from the transaction and attach to another. Multiple threads may attach to a single transaction and do work in certain circumstances. See Multi-threaded Transactions
Modules | |
Locking | |
Partial Rollback: Savepoints | |
Early Lock Release: Quarks | |
Distributed Transactions: Two-Phase Commit | |
Multi-threaded Transactions | |
Running Out of Log Space | |
How Log Sequence Numbers are Used | |
Functions | |
static rc_t | ss_m::begin_xct (timeout_in_ms timeout=WAIT_SPECIFIED_BY_THREAD) |
Begin a transaction. | |
static rc_t | ss_m::begin_xct (sm_stats_info_t *stats, timeout_in_ms timeout=WAIT_SPECIFIED_BY_THREAD) |
Begin an instrumented transaction. | |
static rc_t | ss_m::begin_xct (tid_t &tid, timeout_in_ms timeout=WAIT_SPECIFIED_BY_THREAD) |
Begin a transaction and return the transaction id. | |
static rc_t | ss_m::commit_xct (bool lazy=false, lsn_t *plastlsn=NULL) |
Commit a transaction. | |
static rc_t | ss_m::commit_xct (sm_stats_info_t *&stats, bool lazy=false, lsn_t *plastlsn=NULL) |
Commit an instrumented transaction and get its statistics. | |
static rc_t | ss_m::chain_xct (sm_stats_info_t *&stats, bool lazy=false) |
Commit an instrumented transaction and start a new one. | |
static rc_t | ss_m::chain_xct (bool lazy=false) |
Commit a transaction and start a new one, inheriting locks. | |
static rc_t | ss_m::abort_xct (sm_stats_info_t *&stats) |
Abort an instrumented transaction and get its statistics. | |
static rc_t | ss_m::abort_xct () |
Abort a transaction. | |
static w_base_t::uint4_t | ss_m::num_active_xcts () |
Return the number of transactions in active state. | |
static void | ss_m::attach_xct (xct_t *x) |
Attach the given transaction to the currently-running smthread_t. | |
static void | ss_m::detach_xct () |
Detach any attached from the currently-running smthread_t. | |
static xct_t * | ss_m::tid_to_xct (const tid_t &tid) |
Get the transaction structure for a given a transaction id. | |
static tid_t | ss_m::xct_to_tid (const xct_t *x) |
Get the transaction ID for a given a transaction structure. | |
static xct_state_t | ss_m::state_xct (const xct_t *x) |
Get the transaction state for a given transaction (structure). | |
static smlevel_0::fileoff_t | ss_m::xct_log_space_needed () |
Return the amount of log this transaction would consume if it rolled back.
If a transaction aborts with eOUTOFLOGSPACE this function can be used in conjunction with xct_reserve_log_space to pre-allocate the needed amount of log space before retrying. | |
static rc_t | ss_m::xct_reserve_log_space (fileoff_t amt) |
Require the specified amount of log space to be available for this transaction before continuing.
If a transaction risks running out of log space it can pre-request some or all of the needed amount before starting in order to improve its chances of success. Other new transactions will be unable to acquire log space before this request is granted (existing ones will be able to commit, unless they also run out of space, because that tends to free up log space and avoids wasting work). | |
static rc_t | ss_m::gather_xct_stats (sm_stats_info_t &stats, bool reset=false) |
Get a copy of the statistics from an attached instrumented transaction. |
static rc_t ss_m::begin_xct | ( | timeout_in_ms | timeout = WAIT_SPECIFIED_BY_THREAD |
) | [static, inherited] |
Begin a transaction.
[in] | timeout | Optional, controls blocking behavior. |
Storage manager methods that must block (e.g., to acquire a lock) will use the timeout given. The default timeout is the one associated with this thread.
static rc_t ss_m::begin_xct | ( | sm_stats_info_t * | stats, | |
timeout_in_ms | timeout = WAIT_SPECIFIED_BY_THREAD | |||
) | [static, inherited] |
Begin an instrumented transaction.
[in] | stats | Pointer to an allocated statistics-holding structure. |
[in] | timeout | Optional, controls blocking behavior. |
The transaction will be instrumented. This structure is updated by the storage manager whenever a thread detaches from this transaction. The activity recorded during the time the thread is attached to the transcation will be stored in the per-transaction statistics.
static rc_t ss_m::begin_xct | ( | tid_t & | tid, | |
timeout_in_ms | timeout = WAIT_SPECIFIED_BY_THREAD | |||
) | [static, inherited] |
Begin a transaction and return the transaction id.
[out] | tid | Transaction id of new transaction. |
[in] | timeout | Optional, controls blocking behavior. |
Storage manager methods that must block (e.g., to acquire a lock) will use the timeout given. The default timeout is the one associated with this thread.
Commit a transaction.
[in] | lazy | Optional, controls flushing of log. |
[out] | plastlsn | If non-null, this is a pointer to a log sequence number into which the storage manager writes the that of the last log record inserted for this transaction. |
static rc_t ss_m::commit_xct | ( | sm_stats_info_t *& | stats, | |
bool | lazy = false , |
|||
lsn_t * | plastlsn = NULL | |||
) | [static, inherited] |
Commit an instrumented transaction and get its statistics.
[out] | stats | Get a copy of the statistics for this transaction. |
[in] | lazy | Optional, controls flushing of log. |
[out] | plastlsn | If non-null, this is a pointer to a log sequence number into which the storage manager writes the that of the last log record inserted for this transaction. |
static rc_t ss_m::chain_xct | ( | sm_stats_info_t *& | stats, | |
bool | lazy = false | |||
) | [static, inherited] |
Commit an instrumented transaction and start a new one.
[out] | stats | Get a copy of the statistics for the first transaction. |
[in] | lazy | Optional, controls flushing of log. |
static rc_t ss_m::chain_xct | ( | bool | lazy = false |
) | [static, inherited] |
Commit a transaction and start a new one, inheriting locks.
[in] | lazy | Optional, controls flushing of log. |
static rc_t ss_m::abort_xct | ( | sm_stats_info_t *& | stats | ) | [static, inherited] |
Abort an instrumented transaction and get its statistics.
[out] | stats | Get a copy of the statistics for this transaction. |
static rc_t ss_m::abort_xct | ( | ) | [static, inherited] |
Abort a transaction.
Abort the attached transaction and detach it, destroy it.
static w_base_t::uint4_t ss_m::num_active_xcts | ( | ) | [static, inherited] |
Return the number of transactions in active state.
While this is thread-safe, the moment a value is returned, it could be out of date. Useful only for debugging.
static void ss_m::attach_xct | ( | xct_t * | x | ) | [inline, static, inherited] |
Attach the given transaction to the currently-running smthread_t.
It is assumed that the currently running thread is an smthread_t.
static void ss_m::detach_xct | ( | ) | [inline, static, inherited] |
Detach any attached from the currently-running smthread_t.
Sever the connection between the running thread and the transaction. This allow the running thread to attach a different transaction and to perform work in its behalf.
Get the transaction structure for a given a transaction id.
[in] | tid | Transaction ID. |
Get the transaction ID for a given a transaction structure.
[in] | x | Pointer to transaction structure. |
static xct_state_t ss_m::state_xct | ( | const xct_t * | x | ) | [static, inherited] |
Get the transaction state for a given transaction (structure).
[in] | x | Pointer to transaction structure. |
static rc_t ss_m::gather_xct_stats | ( | sm_stats_info_t & | stats, | |
bool | reset = false | |||
) | [static, inherited] |
Get a copy of the statistics from an attached instrumented transaction.
[out] | stats | Returns a copy of the statistics for this transaction. |
[in] | reset | If true, the statistics for this transaction will be zeroed. |