MySQL 9.0.0
Source Code Documentation
mdl.h File Reference
#include <assert.h>
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <new>
#include <unordered_map>
#include "my_alloc.h"
#include "my_compiler.h"
#include "strmake.h"
#include "my_inttypes.h"
#include "my_psi_config.h"
#include "my_sys.h"
#include "my_systime.h"
#include "mysql/components/services/bits/mysql_cond_bits.h"
#include "mysql/components/services/bits/mysql_mutex_bits.h"
#include "mysql/components/services/bits/mysql_rwlock_bits.h"
#include "mysql/components/services/bits/psi_mdl_bits.h"
#include "mysql/components/services/bits/psi_stage_bits.h"
#include "mysql/psi/mysql_rwlock.h"
#include "mysql_com.h"
#include "sql/sql_plist.h"
#include "template_utils.h"

Go to the source code of this file.

Classes

class  MDL_context_owner
 An interface to separate the MDL module from the THD, and the rest of the server code. More...
 
struct  MDL_key
 Metadata lock object key. More...
 
class  MDL_request
 A pending metadata lock request. More...
 
class  MDL_wait_for_graph_visitor
 An abstract class for inspection of a connected subgraph of the wait-for graph. More...
 
class  MDL_wait_for_subgraph
 Abstract class representing an edge in the waiters graph to be traversed by deadlock detection algorithm. More...
 
class  MDL_ticket
 A granted metadata lock. More...
 
class  MDL_ticket_store
 Keep track of MDL_ticket for different durations. More...
 
struct  MDL_ticket_store::MDL_ticket_handle
 Utility struct for representing a ticket pointer and its duration. More...
 
struct  MDL_ticket_store::Duration
 
struct  MDL_ticket_store::Hash
 
struct  MDL_ticket_store::Key_equal
 
class  MDL_savepoint
 Savepoint for MDL context. More...
 
class  MDL_wait
 A reliable way to wait on an MDL lock. More...
 
class  MDL_release_locks_visitor
 Base class to find out if the lock represented by a given ticket should be released. More...
 
class  MDL_context_visitor
 Abstract visitor class for inspecting MDL_context. More...
 
class  MDL_context
 Context of the owner of metadata locks. More...
 

Namespaces

namespace  mdl_unittest
 

Macros

#define ENTER_COND(C, M, S, O)    enter_cond(C, M, S, O, __func__, __FILE__, __LINE__)
 Start a wait on a condition. More...
 
#define EXIT_COND(S)   exit_cond(S, __func__, __FILE__, __LINE__)
 End a wait on a condition. More...
 
#define MAX_MDLKEY_LENGTH   (1 + NAME_LEN + 1 + NAME_LEN + 1)
 Maximal length of key for metadata locking subsystem. More...
 
#define MDL_REQUEST_INIT(R, P1, P2, P3, P4, P5)    (*R).init_with_source(P1, P2, P3, P4, P5, __FILE__, __LINE__)
 
#define MDL_REQUEST_INIT_BY_KEY(R, P1, P2, P3)    (*R).init_by_key_with_source(P1, P2, P3, __FILE__, __LINE__)
 
#define MDL_REQUEST_INIT_BY_PART_KEY(R, P1, P2, P3, P4, P5, P6)    (*R).init_by_part_key_with_source(P1, P2, P3, P4, P5, P6, __FILE__, __LINE__)
 

Typedefs

typedef I_P_List< MDL_request, I_P_List_adapter< MDL_request, &MDL_request::next_in_list, &MDL_request::prev_in_list >, I_P_List_counterMDL_request_list
 

Enumerations

enum  enum_mdl_type {
  MDL_INTENTION_EXCLUSIVE = 0 , MDL_SHARED , MDL_SHARED_HIGH_PRIO , MDL_SHARED_READ ,
  MDL_SHARED_WRITE , MDL_SHARED_WRITE_LOW_PRIO , MDL_SHARED_UPGRADABLE , MDL_SHARED_READ_ONLY ,
  MDL_SHARED_NO_WRITE , MDL_SHARED_NO_READ_WRITE , MDL_EXCLUSIVE , MDL_TYPE_END ,
  MDL_INTENTION_EXCLUSIVE = 0 , MDL_SHARED , MDL_SHARED_HIGH_PRIO , MDL_SHARED_READ ,
  MDL_SHARED_WRITE , MDL_SHARED_WRITE_LOW_PRIO , MDL_SHARED_UPGRADABLE , MDL_SHARED_READ_ONLY ,
  MDL_SHARED_NO_WRITE , MDL_SHARED_NO_READ_WRITE , MDL_EXCLUSIVE , MDL_TYPE_END
}
 Type of metadata lock request. More...
 
enum  enum_mdl_duration { MDL_STATEMENT = 0 , MDL_TRANSACTION , MDL_EXPLICIT , MDL_DURATION_END }
 Duration of metadata lock. More...
 

Functions

bool mdl_unittest::test_drive_fix_pins (MDL_context *)
 
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...
 

Variables

mysql_mutex_t LOCK_open
 LOCK_open protects the following variables/objects: More...
 
ulong max_write_lock_count
 
int32 mdl_locks_unused_locks_low_water
 Threshold for number of unused MDL_lock objects. More...
 
const int32 MDL_LOCKS_UNUSED_LOCKS_LOW_WATER_DEFAULT = 1000
 Default value for threshold for number of unused MDL_lock objects after exceeding which we start considering freeing them. More...
 
const double MDL_LOCKS_UNUSED_LOCKS_MIN_RATIO = 0.25
 Ratio of unused/total MDL_lock objects after exceeding which we start trying to free unused MDL_lock objects (assuming that mdl_locks_unused_locks_low_water threshold is passed as well). More...
 

Macro Definition Documentation

◆ ENTER_COND

#define ENTER_COND (   C,
  M,
  S,
 
)     enter_cond(C, M, S, O, __func__, __FILE__, __LINE__)

Start a wait on a condition.

Parameters
Cthe condition to wait on
Mthe associated mutex
Sthe new stage to enter
Othe previous stage
See also
EXIT_COND().

◆ EXIT_COND

#define EXIT_COND (   S)    exit_cond(S, __func__, __FILE__, __LINE__)

End a wait on a condition.

Parameters
Sthe new stage to enter

◆ MAX_MDLKEY_LENGTH

#define MAX_MDLKEY_LENGTH   (1 + NAME_LEN + 1 + NAME_LEN + 1)

Maximal length of key for metadata locking subsystem.

◆ MDL_REQUEST_INIT

#define MDL_REQUEST_INIT (   R,
  P1,
  P2,
  P3,
  P4,
  P5 
)     (*R).init_with_source(P1, P2, P3, P4, P5, __FILE__, __LINE__)

◆ MDL_REQUEST_INIT_BY_KEY

#define MDL_REQUEST_INIT_BY_KEY (   R,
  P1,
  P2,
  P3 
)     (*R).init_by_key_with_source(P1, P2, P3, __FILE__, __LINE__)

◆ MDL_REQUEST_INIT_BY_PART_KEY

#define MDL_REQUEST_INIT_BY_PART_KEY (   R,
  P1,
  P2,
  P3,
  P4,
  P5,
  P6 
)     (*R).init_by_part_key_with_source(P1, P2, P3, P4, P5, P6, __FILE__, __LINE__)

Typedef Documentation

◆ MDL_request_list

Enumeration Type Documentation

◆ enum_mdl_duration

Duration of metadata lock.

Enumerator
MDL_STATEMENT 

Locks with statement duration are automatically released at the end of statement or transaction.

MDL_TRANSACTION 

Locks with transaction duration are automatically released at the end of transaction.

MDL_EXPLICIT 

Locks with explicit duration survive the end of statement and transaction.

They have to be released explicitly by calling MDL_context::release_lock().

MDL_DURATION_END 

◆ enum_mdl_type

Type of metadata lock request.

See also
Comments for MDL_object_lock::can_grant_lock() and MDL_scoped_lock::can_grant_lock() for details.
Enumerator
MDL_INTENTION_EXCLUSIVE 
MDL_SHARED 
MDL_SHARED_HIGH_PRIO 
MDL_SHARED_READ 
MDL_SHARED_WRITE 
MDL_SHARED_WRITE_LOW_PRIO 
MDL_SHARED_UPGRADABLE 
MDL_SHARED_READ_ONLY 
MDL_SHARED_NO_WRITE 
MDL_SHARED_NO_READ_WRITE 
MDL_EXCLUSIVE 
MDL_TYPE_END 
MDL_INTENTION_EXCLUSIVE 
MDL_SHARED 
MDL_SHARED_HIGH_PRIO 
MDL_SHARED_READ 
MDL_SHARED_WRITE 
MDL_SHARED_WRITE_LOW_PRIO 
MDL_SHARED_UPGRADABLE 
MDL_SHARED_READ_ONLY 
MDL_SHARED_NO_WRITE 
MDL_SHARED_NO_READ_WRITE 
MDL_EXCLUSIVE 
MDL_TYPE_END 

Function Documentation

◆ 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.

Variable Documentation

◆ max_write_lock_count

ulong max_write_lock_count
extern

◆ mdl_locks_unused_locks_low_water

int32 mdl_locks_unused_locks_low_water
extern

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.

◆ MDL_LOCKS_UNUSED_LOCKS_LOW_WATER_DEFAULT

const int32 MDL_LOCKS_UNUSED_LOCKS_LOW_WATER_DEFAULT = 1000

Default value for threshold for number of unused MDL_lock objects after exceeding which we start considering freeing them.

Only unit tests use different threshold value.

◆ MDL_LOCKS_UNUSED_LOCKS_MIN_RATIO

const double MDL_LOCKS_UNUSED_LOCKS_MIN_RATIO = 0.25

Ratio of unused/total MDL_lock objects after exceeding which we start trying to free unused MDL_lock objects (assuming that mdl_locks_unused_locks_low_water threshold is passed as well).

Note that this value should be high enough for our algorithm using random dives into hash to work well.