![]() |
MySQL 8.4.3
Source Code Documentation
|
Classes | |
struct | Conflicting |
class | Global_exclusive_latch_guard |
A RAII helper which latches global_latch in exclusive mode during constructor, and unlatches it during destruction, preventing any other threads from activity within lock_sys for it's entire scope. More... | |
class | Global_exclusive_try_latch |
A RAII helper which tries to exclusively latch the global_lach in constructor and unlatches it, if needed, during destruction, preventing any other threads from activity within lock_sys for it's entire scope, if owns_lock(). More... | |
class | Global_shared_latch_guard |
A RAII helper which latches global_latch in shared mode during constructor, and unlatches it during destruction, preventing any other thread from acquiring exclusive latch. More... | |
class | Latches |
The class which handles the logic of latching of lock_sys queues themselves. More... | |
class | Shard_latch_guard |
A RAII wrapper class which combines Global_shared_latch_guard and Shard_naked_latch_guard to s-latch the global lock_sys latch and latch the mutex protecting the specified shard for the duration of its scope. More... | |
class | Shard_latches_guard |
A RAII wrapper class which s-latches the global lock_sys shard, and mutexes protecting specified shards for the duration of its scope. More... | |
class | Shard_naked_latch_guard |
A RAII helper which latches the mutex protecting given shard during constructor, and unlatches it during destruction. More... | |
class | Shard_naked_latches_guard |
A RAII helper which latches the mutexes protecting specified shards for the duration of its scope. More... | |
class | Trx_locks_cache |
An object which can be passed to consecutive calls to rec_lock_has_to_wait(trx, mode, lock, is_supremum, trx_locks_cache) for the same trx and heap_no (which is implicitly the bit common to all lock objects passed) which can be used by this function to cache some partial results. More... | |
class | Unsafe_global_latch_manipulator |
Enumerations | |
enum class | Conflict { HAS_TO_WAIT , NO_CONFLICT , CAN_BYPASS } |
Functions | |
const lock_t * | find_blockers (const lock_t &wait_lock, std::function< bool(const lock_t &)> visitor) |
Calls visitor for each lock_t object which is a reason that wait_lock has to wait. More... | |
bool | has_to_wait (const lock_t *lock1, const lock_t *lock2, Trx_locks_cache &lock1_cache) |
Checks if a lock request lock1 has to wait for request lock2. More... | |
bool | owns_exclusive_global_latch () |
Tests if lock_sys latch is exclusively owned by the current thread. More... | |
bool | owns_shared_global_latch () |
Tests if lock_sys latch is owned in shared mode by the current thread. More... | |
bool | owns_page_shard (const page_id_t &page_id) |
Tests if given page shard can be safely accessed by the current thread. More... | |
bool | owns_table_shard (const dict_table_t &table) |
Test if given table shard can be safely accessed by the current thread. More... | |
bool | owns_lock_shard (const lock_t *lock) |
Checks if shard which contains lock is latched (or that an exclusive latch on whole lock_sys is held) by current thread. More... | |
template<typename F > | |
auto | latch_peeked_shard_and_do (const lock_t *peeked_lock, F &&f) |
Temporarily releases trx->mutex, latches the lock-sys shard containing peeked_lock and latches trx->mutex again and calls f under protection of both latches. More... | |
template<typename F > | |
void | run_if_waiting (const TrxVersion trx_version, F &&f) |
Given a pointer to trx (which the caller guarantees will not be freed) and the expected value of trx->version, will call the provided function f, only if the trx is still in expected version and waiting for a lock, within a critical section which holds latches on the trx, and the shard containing the waiting lock. More... | |
static Conflict | rec_lock_check_conflict (const trx_t *trx, ulint type_mode, const lock_t *lock2, bool lock_is_on_supremum, Trx_locks_cache &trx_locks_cache) |
Checks if a new request for a record lock has to wait for existing request. More... | |
static bool | rec_lock_has_to_wait (const lock_t *lock1, const lock_t *lock2, Trx_locks_cache &lock1_cache) |
Checks if a record lock request lock1 has to wait for request lock2. More... | |
static void | add_to_trx_locks (lock_t *lock) |
Adds the lock to the list of trx's locks. More... | |
static void | remove_from_trx_locks (lock_t *lock) |
Removes the lock from the list of trx's locks. More... | |
template<typename F > | |
static bool | try_relatch_trx_and_shard_and_do (const lock_t *lock, F &&f) |
A helper function which solves a chicken-and-egg problem occurring when one needs to iterate over trx's locks and perform some actions on them. More... | |
static bool | try_release_read_locks_in_s_mode (trx_t *trx, bool only_gap) |
Tries to release read locks of a transaction without latching the whole lock sys. More... | |
static bool | try_release_read_locks_in_x_mode (trx_t *trx, bool only_gap) |
Release read locks of a transaction latching the whole lock-sys in exclusive mode, which is a bit too expensive to do by default. More... | |
static bool | try_release_all_locks (trx_t *trx) |
Releases transaction locks, and releases possible other transactions waiting because of these locks. More... | |
static void | rec_queue_validate_latched (const buf_block_t *block, const rec_t *rec, const dict_index_t *index, const ulint *offsets) |
Validates the lock queue on a single record. More... | |
static void | rec_queue_latch_and_validate (const buf_block_t *block, const rec_t *rec, const dict_index_t *index, const ulint *offsets) |
Validates the lock queue on a single record. More... | |
static void | rec_queue_latch_and_validate (const buf_block_t *block, const rec_t *rec, const dict_index_t *index) |
Validates the lock queue on a single record. More... | |
Variables | |
constexpr auto | MAX_CS_DURATION = std::chrono::seconds{1} |
We don't want to hold the Global latch for too long, even in S mode, not to starve threads waiting for X-latch on it such as lock_wait_timeout_thread(). More... | |
|
strong |
|
static |
Adds the lock to the list of trx's locks.
Requires lock->trx to be already set. Bumps the trx_lock_version.
[in,out] | lock | The lock that we want to add to lock->trx->lock.trx_locks |
const lock_t * locksys::find_blockers | ( | const lock_t & | wait_lock, |
std::function< bool(const lock_t &)> | visitor | ||
) |
Calls visitor for each lock_t object which is a reason that wait_lock has to wait.
It is assumed that the wait_lock is waiting, and the caller has latched the shard which contains the wait_lock
[in] | wait_lock | the waiting lock |
[in] | visitor | a function to be called for each lock, s.t. locksys::has_to_wait(wait_lock, lock) is true. To stop iteration the visitor can return true, in which case the lock for which it happened will be returned. |
bool locksys::has_to_wait | ( | const lock_t * | lock1, |
const lock_t * | lock2, | ||
Trx_locks_cache & | lock1_cache | ||
) |
Checks if a lock request lock1 has to wait for request lock2.
It returns the same result as
[in] | lock1 | A waiting lock |
[in] | lock2 | Another lock; NOTE that it is assumed that this has a lock bit set on the same record as in lock1 if the locks are record locks. |
[in] | lock1_cache | An object which can be passed to consecutive calls to this function for the same lock1 which can be used by this function to cache some partial results. |
auto locksys::latch_peeked_shard_and_do | ( | const lock_t * | peeked_lock, |
F && | f | ||
) |
Temporarily releases trx->mutex, latches the lock-sys shard containing peeked_lock and latches trx->mutex again and calls f under protection of both latches.
The latch on lock-sys shard will be released immediately after f returns. It is a responsibility of the caller to handle shared lock-sys latch, trx->mutex and verify inside f that the trx has not been finished, and the lock was not released meanwhile.
[in] | peeked_lock | A lock of the trx. (While trx->mutex is held it can't be freed, but can be released). It is used to determine the lock-sys shard to latch. |
[in] | f | The callback to call once the lock-sys shard is latched and trx->mutex is relatched. |
bool locksys::owns_exclusive_global_latch | ( | ) |
Tests if lock_sys latch is exclusively owned by the current thread.
bool locksys::owns_lock_shard | ( | const lock_t * | lock | ) |
Checks if shard which contains lock is latched (or that an exclusive latch on whole lock_sys is held) by current thread.
[in] | lock | lock which belongs to a shard we want to check |
bool locksys::owns_page_shard | ( | const page_id_t & | page_id | ) |
Tests if given page shard can be safely accessed by the current thread.
page_id | specifies the page |
bool locksys::owns_shared_global_latch | ( | ) |
Tests if lock_sys latch is owned in shared mode by the current thread.
bool locksys::owns_table_shard | ( | const dict_table_t & | table | ) |
Test if given table shard can be safely accessed by the current thread.
table | the table |
|
inlinestatic |
Checks if a new request for a record lock has to wait for existing request.
[in] | trx | The trx requesting the new lock |
[in] | type_mode | precise mode of the new lock to set: LOCK_S or LOCK_X, possibly ORed to LOCK_GAP or LOCK_REC_NOT_GAP, LOCK_INSERT_INTENTION |
[in] | lock2 | another record lock; NOTE that it is assumed that this has a lock bit set on the same record as in the new lock we are setting |
[in] | lock_is_on_supremum | true if we are setting the lock on the 'supremum' record of an index page: we know then that the lock request is really for a 'gap' type lock |
[in] | trx_locks_cache | An object which can be passed to consecutive calls to this function for the same trx and heap_no (which is implicitly the bit common to all lock2 objects passed) which can be used by this function to cache some partial results. |
NO_CONFLICT | the trx does not have to wait for lock2 |
CAN_BYPASS | the trx does not have to wait for lock2, as it can bypass it |
HAS_TO_WAIT | the trx has to wait for lock2 |
|
inlinestatic |
Checks if a record lock request lock1 has to wait for request lock2.
[in] | lock1 | waiting record lock |
[in] | lock2 | another record lock; NOTE that it is assumed that this has a lock bit set on the same record as in lock1 |
[in] | lock1_cache | Cached info gathered during calls with lock1 |
|
static |
Validates the lock queue on a single record.
[in] | block | buffer block containing rec |
[in] | rec | record to look at |
[in] | index | index, or NULL if not known |
|
static |
Validates the lock queue on a single record.
[in] | block | buffer block containing rec |
[in] | rec | record to look at |
[in] | index | index, or NULL if not known |
[in] | offsets | rec_get_offsets(rec, index) |
|
static |
Validates the lock queue on a single record.
[in] | block | buffer block containing rec |
[in] | rec | record to look at |
[in] | index | index, or NULL if not known |
[in] | offsets | rec_get_offsets(rec, index) |
|
static |
Removes the lock from the list of trx's locks.
Bumps the trx_lock_version.
[in,out] | lock | The lock that we want to remove from lock->trx->lock.trx_locks |
void locksys::run_if_waiting | ( | const TrxVersion | trx_version, |
F && | f | ||
) |
Given a pointer to trx (which the caller guarantees will not be freed) and the expected value of trx->version, will call the provided function f, only if the trx is still in expected version and waiting for a lock, within a critical section which holds latches on the trx, and the shard containing the waiting lock.
If the transaction has meanwhile finished waiting for a lock, or committed or rolled back etc. the f will not be called. It may happen that the lock for which the trx is waiting during exectuion of f is not the same as the lock it was waiting at the moment of invocation.
[in] | trx_version | The version of the trx that we intend to wake up |
[in] | f | The callback to call if trx is still waiting for a lock and is still in version trx_version |
|
static |
A helper function which solves a chicken-and-egg problem occurring when one needs to iterate over trx's locks and perform some actions on them.
Iterating over this list requires trx->mutex (or exclusive global lock_sys latch), and operating on a lock requires lock_sys latches, yet the latching order requires lock_sys latches to be taken before trx->mutex. One way around it is to use exclusive global lock_sys latch, which heavily deteriorates concurrency. Another is to try to reacquire the latches in needed order, veryfing that the list wasn't modified meanwhile. This function performs following steps:
[in] | lock | the lock we are interested in |
[in] | f | the function to execute when the shard is latched |
|
static |
Releases transaction locks, and releases possible other transactions waiting because of these locks.
[in,out] | trx | transaction |
|
static |
Tries to release read locks of a transaction without latching the whole lock sys.
This may fail, if there are many concurrent threads editing the list of locks of this transaction (for example due to B-tree pages being merged or split, or due to implicit-to-explicit conversion). It is called during XA prepare to release locks early.
[in,out] | trx | transaction |
[in] | only_gap | release only GAP locks |
|
static |
Release read locks of a transaction latching the whole lock-sys in exclusive mode, which is a bit too expensive to do by default.
It is called during XA prepare to release locks early.
[in,out] | trx | transaction |
[in] | only_gap | release only GAP locks |
|
constexpr |
We don't want to hold the Global latch for too long, even in S mode, not to starve threads waiting for X-latch on it such as lock_wait_timeout_thread().
This defines the longest allowed critical section duration.