MySQL 8.4.2
Source Code Documentation
mdl.cc File Reference
#include "sql/mdl.h"
#include <time.h>
#include <algorithm>
#include <atomic>
#include <functional>
#include "lf.h"
#include "my_dbug.h"
#include "my_macros.h"
#include "my_murmur3.h"
#include "my_sharedlib.h"
#include "my_sys.h"
#include "my_systime.h"
#include "my_thread.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/bits/psi_cond_bits.h"
#include "mysql/components/services/bits/psi_memory_bits.h"
#include "mysql/components/services/bits/psi_mutex_bits.h"
#include "mysql/components/services/bits/psi_rwlock_bits.h"
#include "mysql/psi/mysql_cond.h"
#include "mysql/psi/mysql_mdl.h"
#include "mysql/psi/mysql_memory.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_stage.h"
#include "mysql/psi/psi_mdl.h"
#include "mysql/service_thd_wait.h"
#include "mysql/strings/m_ctype.h"
#include "mysqld_error.h"
#include "prealloced_array.h"
#include "sql/debug_sync.h"
#include "sql/thr_malloc.h"

Classes

class  MDL_map
 A collection of all MDL locks. More...
 
class  Deadlock_detection_visitor
 A context of the recursive traversal through all contexts in all sessions in search for deadlock. More...
 
class  MDL_lock
 The lock context. More...
 
class  MDL_lock::Ticket_list
 
struct  MDL_lock::MDL_lock_strategy
 Helper struct which defines how different types of locks are handled for a specific MDL_lock. More...
 
class  MDL_request_cmp
 

Macros

#define MDL_BIT(A)   static_cast<MDL_lock::bitmap_t>(1U << A)
 Get a bit corresponding to enum_mdl_type value in a granted/waiting bitmaps and compatibility matrices. More...
 

Functions

static void init_mdl_psi_keys (void)
 Initialise all the performance schema instrumentation points used by the MDL subsystem. More...
 
static const ucharmdl_locks_key (const uchar *record, size_t *length)
 
void mdl_init ()
 Initialize the metadata locking subsystem. More...
 
void mdl_destroy ()
 Release resources of metadata locking subsystem. More...
 
int32 mdl_get_unused_locks_count ()
 Get number of unused MDL_lock objects in MDL_map cache. More...
 
static void mdl_lock_cons (uchar *arg)
 
static void mdl_lock_dtor (uchar *arg)
 
static void mdl_lock_reinit (uchar *dst_arg, const uchar *src_arg)
 
static uint murmur3_adapter (const LF_HASH *, const uchar *key, size_t length)
 Adapter function which allows to use murmur3 with LF_HASH implementation. More...
 
static int mdl_lock_match_unused (const uchar *arg, void *match_arg)
 Helper function which allows to check if MDL_lock object stored in LF_HASH is unused - i.e. More...
 
bool equivalent (const MDL_ticket *a, const MDL_ticket *b, enum_mdl_duration target_duration)
 

Variables

MYSQL_PLUGIN_IMPORT CHARSET_INFOsystem_charset_info
 
static PSI_memory_key key_memory_MDL_context_acquire_locks
 
static PSI_mutex_key key_MDL_wait_LOCK_wait_status
 
static PSI_mutex_info all_mdl_mutexes []
 
static PSI_rwlock_key key_MDL_lock_rwlock
 
static PSI_rwlock_key key_MDL_context_LOCK_waiting_for
 
static PSI_rwlock_info all_mdl_rwlocks []
 
static PSI_cond_key key_MDL_wait_COND_wait_status
 
static PSI_cond_info all_mdl_conds []
 
static PSI_memory_info all_mdl_memory []
 
static bool mdl_initialized = false
 
int32 mdl_locks_unused_locks_low_water
 Threshold for number of unused MDL_lock objects. More...
 
static MDL_map mdl_locks
 

Macro Definition Documentation

◆ MDL_BIT

#define MDL_BIT (   A)    static_cast<MDL_lock::bitmap_t>(1U << A)

Get a bit corresponding to enum_mdl_type value in a granted/waiting bitmaps and compatibility matrices.

Function Documentation

◆ equivalent()

bool equivalent ( const MDL_ticket a,
const MDL_ticket b,
enum_mdl_duration  target_duration 
)

◆ init_mdl_psi_keys()

static void init_mdl_psi_keys ( void  )
static

Initialise all the performance schema instrumentation points used by the MDL subsystem.

◆ mdl_destroy()

void mdl_destroy ( )

Release resources of metadata locking subsystem.

Destroys the global mutex and the condition variable. Called at server shutdown.

◆ mdl_get_unused_locks_count()

int32 mdl_get_unused_locks_count ( )

Get number of unused MDL_lock objects in MDL_map cache.

Mostly needed for unit-testing.

◆ mdl_init()

void mdl_init ( )

Initialize the metadata locking subsystem.

This function is called at server startup.

In particular, initializes the new global mutex and the associated condition variable: LOCK_mdl and COND_mdl. These locking primitives are implementation details of the MDL subsystem and are private to it.

◆ mdl_lock_cons()

static void mdl_lock_cons ( uchar arg)
static

◆ mdl_lock_dtor()

static void mdl_lock_dtor ( uchar arg)
static

◆ mdl_lock_match_unused()

static int mdl_lock_match_unused ( const uchar arg,
void *  match_arg 
)
static

Helper function which allows to check if MDL_lock object stored in LF_HASH is unused - i.e.

doesn't have any locks on both "fast" and "slow" paths and is not marked as deleted.

◆ mdl_lock_reinit()

static void mdl_lock_reinit ( uchar dst_arg,
const uchar src_arg 
)
static

◆ mdl_locks_key()

static const uchar * mdl_locks_key ( const uchar record,
size_t *  length 
)
static

◆ murmur3_adapter()

static uint murmur3_adapter ( const LF_HASH ,
const uchar key,
size_t  length 
)
static

Adapter function which allows to use murmur3 with LF_HASH implementation.

Variable Documentation

◆ all_mdl_conds

PSI_cond_info all_mdl_conds[]
static
Initial value:
"MDL_context::COND_wait_status", 0, 0,
#define PSI_DOCUMENT_ME
Definition: component_common.h:29
static PSI_cond_key key_MDL_wait_COND_wait_status
Definition: mdl.cc:77

◆ all_mdl_memory

PSI_memory_info all_mdl_memory[]
static
Initial value:
= {
{&key_memory_MDL_context_acquire_locks, "MDL_context::acquire_locks", 0, 0,
"Buffer for sorting lock requests."}}
static PSI_memory_key key_memory_MDL_context_acquire_locks
Definition: mdl.cc:59

◆ all_mdl_mutexes

PSI_mutex_info all_mdl_mutexes[]
static
Initial value:
"MDL_wait::LOCK_wait_status", 0, 0,
static PSI_mutex_key key_MDL_wait_LOCK_wait_status
Definition: mdl.cc:62

◆ all_mdl_rwlocks

PSI_rwlock_info all_mdl_rwlocks[]
static
Initial value:
= {
{&key_MDL_lock_rwlock, "MDL_lock::rwlock", PSI_FLAG_RWLOCK_PR, 0,
{&key_MDL_context_LOCK_waiting_for, "MDL_context::LOCK_waiting_for",
#define PSI_FLAG_RWLOCK_PR
Priority lock flag.
Definition: psi_bits.h:118
static PSI_rwlock_key key_MDL_context_LOCK_waiting_for
Definition: mdl.cc:69
static PSI_rwlock_key key_MDL_lock_rwlock
Definition: mdl.cc:68

◆ key_MDL_context_LOCK_waiting_for

PSI_rwlock_key key_MDL_context_LOCK_waiting_for
static

◆ key_MDL_lock_rwlock

PSI_rwlock_key key_MDL_lock_rwlock
static

◆ key_MDL_wait_COND_wait_status

PSI_cond_key key_MDL_wait_COND_wait_status
static

◆ key_MDL_wait_LOCK_wait_status

PSI_mutex_key key_MDL_wait_LOCK_wait_status
static

◆ key_memory_MDL_context_acquire_locks

PSI_memory_key key_memory_MDL_context_acquire_locks
static

◆ mdl_initialized

bool mdl_initialized = false
static

◆ mdl_locks

MDL_map mdl_locks
static

◆ mdl_locks_unused_locks_low_water

int32 mdl_locks_unused_locks_low_water
Initial value:
=
const int32 MDL_LOCKS_UNUSED_LOCKS_LOW_WATER_DEFAULT
Default value for threshold for number of unused MDL_lock objects after exceeding which we start cons...
Definition: mdl.h:1734

Threshold for number of unused MDL_lock objects.

We will start considering freeing some unused objects only after exceeding this value and if unused/total objects ratio is high enough.

Normally this threshold is constant. It is exposed outside of MDL subsystem as a variable only in order to simplify unit testing.

◆ system_charset_info

MYSQL_PLUGIN_IMPORT CHARSET_INFO* system_charset_info
extern