MySQL 8.0.39
Source Code Documentation
MDL_map Class Reference

A collection of all MDL locks. More...

Public Member Functions

void init ()
 Initialize the container for all MDL locks. More...
 
void destroy ()
 Destroy the container for all MDL locks. More...
 
MDL_lockfind (LF_PINS *pins, const MDL_key *key, bool *pinned)
 Find MDL_lock object corresponding to the key. More...
 
MDL_lockfind_or_insert (LF_PINS *pins, const MDL_key *key, bool *pinned)
 Find MDL_lock object corresponding to the key, create it if it does not exist. More...
 
void lock_object_used ()
 Decrement unused MDL_lock objects counter. More...
 
void lock_object_unused (MDL_context *ctx, LF_PINS *pins)
 Increment unused MDL_lock objects counter. More...
 
int32 get_unused_locks_count () const
 Get number of unused MDL_lock objects in MDL_map cache. More...
 
LF_PINSget_pins ()
 Allocate pins which are necessary for MDL_context/thread to be able to work with MDL_map container. More...
 
bool is_lock_object_singleton (const MDL_key *mdl_key) const
 Check if MDL_lock object corresponding to the key is going to be singleton. More...
 

Private Member Functions

void remove_random_unused (MDL_context *ctx, LF_PINS *pins, int32 *unused_locks)
 Try to find random MDL_lock object in MDL_map for which there are no "fast" path nor "slow" path locks. More...
 

Private Attributes

LF_HASH m_locks
 LF_HASH with all locks in the server. More...
 
MDL_lockm_global_lock
 Pre-allocated MDL_lock object for GLOBAL namespace. More...
 
MDL_lockm_commit_lock
 Pre-allocated MDL_lock object for COMMIT namespace. More...
 
MDL_lockm_acl_cache_lock
 Pre-allocated MDL_lock object for ACL_CACHE namespace. More...
 
MDL_lockm_backup_lock
 Pre-allocated MDL_lock object for BACKUP_LOCK namespace. More...
 
std::atomic< int32m_unused_lock_objects
 Number of unused MDL_lock objects in the server. More...
 

Detailed Description

A collection of all MDL locks.

A singleton, there is only one instance of the map in the server.

Member Function Documentation

◆ destroy()

void MDL_map::destroy ( )

Destroy the container for all MDL locks.

Precondition
It must be empty.

◆ find()

MDL_lock * MDL_map::find ( LF_PINS pins,
const MDL_key mdl_key,
bool *  pinned 
)
inline

Find MDL_lock object corresponding to the key.

Parameters
[in,out]pinsLF_PINS to be used for pinning pointers during look-up and returned MDL_lock object.
[in]mdl_keyKey for which MDL_lock object needs to be found.
[out]pinnedtrue - if MDL_lock object is pinned, false - if MDL_lock object doesn't require pinning (i.e. it is an object for GLOBAL, COMMIT or ACL_CACHE namespaces).
Return values
MY_LF_ERRPTR- Failure (OOM)
other-non-NULL- MDL_lock object found.
NULL- Object not found.

◆ find_or_insert()

MDL_lock * MDL_map::find_or_insert ( LF_PINS pins,
const MDL_key mdl_key,
bool *  pinned 
)
inline

Find MDL_lock object corresponding to the key, create it if it does not exist.

Parameters
[in,out]pinsLF_PINS to be used for pinning pointers during look-up and returned MDL_lock object.
[in]mdl_keyKey for which MDL_lock object needs to be found.
[out]pinnedtrue - if MDL_lock object is pinned, false - if MDL_lock object doesn't require pinning (i.e. it is an object for GLOBAL, COMMIT or ACL_CACHE namespaces).
Return values
non-NULL- Success. MDL_lock instance for the key with locked MDL_lock::m_rwlock.
NULL- Failure (OOM).

◆ get_pins()

LF_PINS * MDL_map::get_pins ( )
inline

Allocate pins which are necessary for MDL_context/thread to be able to work with MDL_map container.

◆ get_unused_locks_count()

int32 MDL_map::get_unused_locks_count ( ) const
inline

Get number of unused MDL_lock objects in MDL_map cache.

Note
Does non-atomic read so can return stale results. This is OK since this method is used only in unit-tests. The latter employ means of thread synchronization which are external to MDL and prevent memory reordering/ensure that thread calling this method have up-to-date view on the memory.
See also
m_unused_lock_objects.

◆ init()

void MDL_map::init ( )

Initialize the container for all MDL locks.

◆ is_lock_object_singleton()

bool MDL_map::is_lock_object_singleton ( const MDL_key mdl_key) const
inline

Check if MDL_lock object corresponding to the key is going to be singleton.

◆ lock_object_unused()

void MDL_map::lock_object_unused ( MDL_context ctx,
LF_PINS pins 
)
inline

Increment unused MDL_lock objects counter.

If number of such objects exceeds threshold and unused/total objects ratio is high enough try to free some of them.

◆ lock_object_used()

void MDL_map::lock_object_used ( )
inline

Decrement unused MDL_lock objects counter.

◆ remove_random_unused()

void MDL_map::remove_random_unused ( MDL_context ctx,
LF_PINS pins,
int32 unused_locks 
)
private

Try to find random MDL_lock object in MDL_map for which there are no "fast" path nor "slow" path locks.

If found - mark it as destroyed, remove object from MDL_map and return it back to allocator.

Parameters
[in]ctxContext on which behalf we are trying to remove unused object. Primarily needed to generate random value to be used for random dive into the hash in MDL_map.
[in,out]pinsPins for the calling thread to be used for hash lookup and deletion.
[out]unused_locksNumber of unused lock objects after operation.
Note
In reality MDL_lock object will be returned to allocator once it is no longer pinned by any threads.

Member Data Documentation

◆ m_acl_cache_lock

MDL_lock* MDL_map::m_acl_cache_lock
private

Pre-allocated MDL_lock object for ACL_CACHE namespace.

◆ m_backup_lock

MDL_lock* MDL_map::m_backup_lock
private

Pre-allocated MDL_lock object for BACKUP_LOCK namespace.

◆ m_commit_lock

MDL_lock* MDL_map::m_commit_lock
private

Pre-allocated MDL_lock object for COMMIT namespace.

◆ m_global_lock

MDL_lock* MDL_map::m_global_lock
private

Pre-allocated MDL_lock object for GLOBAL namespace.

◆ m_locks

LF_HASH MDL_map::m_locks
private

LF_HASH with all locks in the server.

◆ m_unused_lock_objects

std::atomic<int32> MDL_map::m_unused_lock_objects
private

Number of unused MDL_lock objects in the server.

Updated using atomic operations, read using both atomic and ordinary reads. We assume that ordinary reads of 32-bit words can't result in partial results, but may produce stale results thanks to memory reordering, LF_HASH seems to be using similar assumption.

Note that due to fact that updates to this counter are not atomic with marking MDL_lock objects as used/unused it might easily get negative for some short period of time. Code which uses its value needs to take this into account.


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