MySQL 8.4.2
Source Code Documentation
|
Debug checks for latches. More...
#include "sync0debug.h"
#include <stddef.h>
#include <algorithm>
#include <atomic>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include "sync0rw.h"
#include "ut0mutex.h"
#include <scope_guard.h>
#include "srv0start.h"
#include "ut0new.h"
#include <current_thd.h>
Classes | |
struct | Latched |
The latch held by a thread. More... | |
struct | LatchDebug |
The deadlock detector. More... | |
struct | LatchDebug::latch_level_less |
Comparator for the Levels . More... | |
struct | CreateTracker |
Track mutex file creation name and line number. More... | |
struct | CreateTracker::File |
For tracking the filename and line number. More... | |
Macros | |
#define | LEVEL_MAP_INSERT(T) |
Typedefs | |
typedef std::vector< Latched, ut::allocator< Latched > > | Latches |
Thread specific latches. More... | |
Functions | |
void | sync_check_lock_validate (const latch_t *latch) |
Check if it is OK to acquire the latch. More... | |
void | sync_check_lock_granted (const latch_t *latch) |
Note that the lock has been granted. More... | |
void | sync_check_lock (const latch_t *latch, latch_level_t level) |
Check if it is OK to acquire the latch. More... | |
void | sync_check_relock (const latch_t *latch) |
Check if it is OK to re-acquire the lock. More... | |
void | sync_check_unlock (const latch_t *latch) |
Removes a latch from the thread level array if it is found there. More... | |
const latch_t * | sync_check_find (latch_level_t level) |
Checks if the level array for the current thread contains a mutex or rw-latch at the specified level. More... | |
bool | sync_check_iterate (sync_check_functor_t &functor) |
Checks that the level array for the current thread is empty. More... | |
void | sync_check_enable () |
Enable sync order checking. More... | |
void | rw_lock_debug_mutex_enter () |
Acquires the debug mutex. More... | |
void | rw_lock_debug_mutex_exit () |
Releases the debug mutex. More... | |
static void | sync_latch_meta_init () 1 |
Load the latch meta data. More... | |
static void | sync_latch_meta_destroy () |
Destroy the latch meta data. More... | |
void | sync_file_created_register (const void *ptr, const char *filename, uint16_t line) |
Register a latch, called when it is created. More... | |
void | sync_file_created_deregister (const void *ptr) |
Deregister a latch, called when it is destroyed. More... | |
std::string | sync_file_created_get (const void *ptr) |
Get the string where the file was created. More... | |
void | sync_check_init (size_t max_threads) |
Initializes the synchronization data structures. More... | |
void | sync_check_close () |
Frees the resources in InnoDB's own synchronization data structures. More... | |
Variables | |
bool | srv_sync_debug |
static ib_mutex_t | rw_lock_debug_mutex |
The global mutex which protects debug info lists of all rw-locks. More... | |
static os_event_t | rw_lock_debug_event |
If deadlock detection does not get immediately the mutex, it may wait for this event. More... | |
static std::atomic< bool > | rw_lock_debug_waiters {false} |
This is set to true, if there may be waiters for the event. More... | |
LatchMetaData | latch_meta |
Note: This is accessed without any mutex protection. More... | |
static CreateTracker * | create_tracker |
Track latch creation location. More... | |
Debug checks for latches.
Created 2012-08-21 Sunny Bains
#define LEVEL_MAP_INSERT | ( | T | ) |
typedef std::vector<Latched, ut::allocator<Latched> > Latches |
Thread specific latches.
This is ordered on level in descending order.
void rw_lock_debug_mutex_enter | ( | ) |
Acquires the debug mutex.
We cannot use the mutex defined in sync0sync, because the debug mutex is also acquired in sync0arr while holding the OS mutex protecting the sync array, and the ordinary mutex_enter might recursively call routines in sync0arr, leading to a deadlock on the OS mutex.
void rw_lock_debug_mutex_exit | ( | ) |
Releases the debug mutex.
void sync_check_close | ( | ) |
Frees the resources in InnoDB's own synchronization data structures.
Frees the resources in synchronization data structures.
Use os_sync_free() after calling this.
void sync_check_enable | ( | ) |
Enable sync order checking.
Note: We don't enforce any synchronisation checks. The caller must ensure that no races can occur
const latch_t * sync_check_find | ( | latch_level_t | level | ) |
Checks if the level array for the current thread contains a mutex or rw-latch at the specified level.
[in] | level | to find |
void sync_check_init | ( | size_t | max_threads | ) |
Initializes the synchronization data structures.
[in] | max_threads | Maximum threads that can be created. |
For collecting latch statistic - SHOW ... MUTEX
For trcking mutex creation location
bool sync_check_iterate | ( | sync_check_functor_t & | functor | ) |
Checks that the level array for the current thread is empty.
Terminate iteration if the functor returns true.
[in,out] | functor | called for each element. |
void sync_check_lock | ( | const latch_t * | latch, |
latch_level_t | level | ||
) |
Check if it is OK to acquire the latch.
[in] | latch | latch type |
[in] | level | the level of the mutex |
void sync_check_lock_granted | ( | const latch_t * | latch | ) |
Note that the lock has been granted.
[in] | latch | latch type |
void sync_check_lock_validate | ( | const latch_t * | latch | ) |
Check if it is OK to acquire the latch.
[in] | latch | latch type |
void sync_check_relock | ( | const latch_t * | latch | ) |
Check if it is OK to re-acquire the lock.
[in] | latch | RW-LOCK to relock (recursive X locks) |
void sync_check_unlock | ( | const latch_t * | latch | ) |
Removes a latch from the thread level array if it is found there.
[in] | latch | The latch to unlock |
void sync_file_created_deregister | ( | const void * | ptr | ) |
Deregister a latch, called when it is destroyed.
[in] | ptr | Latch to be destroyed |
std::string sync_file_created_get | ( | const void * | ptr | ) |
Get the string where the file was created.
Its format is "name:line"
[in] | ptr | Latch instance |
void sync_file_created_register | ( | const void * | ptr, |
const char * | filename, | ||
uint16_t | line | ||
) |
Register a latch, called when it is created.
[in] | ptr | Latch instance that was created |
[in] | filename | Filename where it was created |
[in] | line | Line number in filename |
|
static |
Destroy the latch meta data.
|
static |
Load the latch meta data.
|
static |
Track latch creation location.
For reducing the size of the latches
LatchMetaData latch_meta |
Note: This is accessed without any mutex protection.
It is initialised at startup and elements should not be added to or removed from it after that. See sync_latch_meta_init()
|
static |
If deadlock detection does not get immediately the mutex, it may wait for this event.
|
static |
The global mutex which protects debug info lists of all rw-locks.
To modify the debug info list of an rw-lock, this mutex has to be acquired in addition to the mutex protecting the lock.
|
static |
This is set to true, if there may be waiters for the event.
bool srv_sync_debug |