MySQL 9.1.0
Source Code Documentation
All_locks_iterator Class Reference

Iterates over all locks in the lock sys in a manner which guarantees that all locks from the same lock queue are processed in a single critical section. More...

#include <lock0iter.h>

Public Member Functions

bool iterate_over_next_batch (const std::function< void(const lock_t &lock)> &f)
 Processes a batch of one or more non-empty lock queues, calling the provided function f for each lock in the queue, making sure that the queue is not being modified during processing it. More...
 

Private Types

enum class  stage_t {
  NOT_STARTED , TABLE_LOCKS , PRDT_PAGE_LOCKS , PRDT_LOCKS ,
  REC_LOCKS , DONE
}
 This iterator moves through the following stages, where the move to next stage occurs when all locks from previous stage were reported. More...
 

Private Member Functions

template<typename F >
bool iterate_over_current_table (F &&f)
 Helper function for TABLE_LOCKS stage. More...
 
template<typename F >
bool iterate_over_current_cell (struct Locks_hashtable &hash_table, F &&f)
 Helper function for PRDT_PAGE_LOCKS, PRDT_LOCKS and REC_LOCKS stages. More...
 

Private Attributes

stage_t m_stage {stage_t::NOT_STARTED}
 The current stage this iterator is in. More...
 
std::vector< table_id_tm_table_ids
 List of ids of all tables found in dict sys which are candidates for inspection in TABLE_LOCKS stage. More...
 
size_t m_bucket_id {0}
 Tracks progress within a single stage: index of table in m_table_ids for the TABLE_LOCKS stage, and cell of the hash_table for record locks. More...
 
uint32_t m_lock_sys_n_resizes_at_the_beginning {0}
 The value of lock_sys->n_resizes is stored in this field at the begging of stages involving iterating over lock sys hash tables so that we can spot if the hash table got resized during our iteration and invalidate the iterator. More...
 

Detailed Description

Iterates over all locks in the lock sys in a manner which guarantees that all locks from the same lock queue are processed in a single critical section.

Member Enumeration Documentation

◆ stage_t

enum class All_locks_iterator::stage_t
strongprivate

This iterator moves through the following stages, where the move to next stage occurs when all locks from previous stage were reported.

Enumerator
NOT_STARTED 

iterator was just created (which does not cost much)

TABLE_LOCKS 

iterating over LOCK_TABLE locks for tables from m_table_ids

PRDT_PAGE_LOCKS 

iterating over LOCK_PRDT_PAGE in lock_sys->prdt_page_hash

PRDT_LOCKS 

iterating over LOCK_PREDICATE locks in lock_sys->prdt_hash

REC_LOCKS 

iterating over other (non-predicate) LOCK_RECORD locks in lock_sys->rec_hash

DONE 

finished iterating, nothing more to see

Member Function Documentation

◆ iterate_over_current_cell()

template<typename F >
bool All_locks_iterator::iterate_over_current_cell ( struct Locks_hashtable hash_table,
F &&  f 
)
private

Helper function for PRDT_PAGE_LOCKS, PRDT_LOCKS and REC_LOCKS stages.

Calls f for all locks associated with hash_table m_bucket_id-th cell.

Parameters
[in]hash_tablehash_table to inspect
[in]ffunction to apply to each lock
Returns
true iff it succeeded

◆ iterate_over_current_table()

template<typename F >
bool All_locks_iterator::iterate_over_current_table ( F &&  f)
private

Helper function for TABLE_LOCKS stage.

Calls f for all locks associated with m_table_ids[m_bucket_id].

Parameters
[in]ffunction to apply to each lock
Returns
true iff it succeeded

◆ iterate_over_next_batch()

bool All_locks_iterator::iterate_over_next_batch ( const std::function< void(const lock_t &lock)> &  f)

Processes a batch of one or more non-empty lock queues, calling the provided function f for each lock in the queue, making sure that the queue is not being modified during processing it.

Please note, that this means that the locks from a single lock queue visited by f() present a consistent snapshot of this queue, however locks which reside in different queues, may be inconsistent with each other, as they are observed at different "times". Also, this iterator does not guarantee reporting all locks in case the lock-sys is being resized in parallel by lock_sys_resize() - resizing causes the iterator to stop processing to avoid double-reporting.

Returns
true iff the iterator is done, and calling it again will not provide any further results

Member Data Documentation

◆ m_bucket_id

size_t All_locks_iterator::m_bucket_id {0}
private

Tracks progress within a single stage: index of table in m_table_ids for the TABLE_LOCKS stage, and cell of the hash_table for record locks.

It is reset to 0 at the beginning of each stage.

◆ m_lock_sys_n_resizes_at_the_beginning

uint32_t All_locks_iterator::m_lock_sys_n_resizes_at_the_beginning {0}
private

The value of lock_sys->n_resizes is stored in this field at the begging of stages involving iterating over lock sys hash tables so that we can spot if the hash table got resized during our iteration and invalidate the iterator.

◆ m_stage

stage_t All_locks_iterator::m_stage {stage_t::NOT_STARTED}
private

The current stage this iterator is in.

◆ m_table_ids

std::vector<table_id_t> All_locks_iterator::m_table_ids
private

List of ids of all tables found in dict sys which are candidates for inspection in TABLE_LOCKS stage.


The documentation for this class was generated from the following files: