MySQL 9.1.0
Source Code Documentation
sync0debug.cc File Reference

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_tsync_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 CreateTrackercreate_tracker
 Track latch creation location. More...
 

Detailed Description

Debug checks for latches.

Created 2012-08-21 Sunny Bains

Macro Definition Documentation

◆ LEVEL_MAP_INSERT

#define LEVEL_MAP_INSERT (   T)
Value:
do { \
std::pair<Levels::iterator, bool> result = \
m_levels.insert(Levels::value_type(T, #T)); \
ut_ad(result.second); \
} while (0)
uint16_t value_type
Definition: vt100.h:184
Definition: result.h:30

Typedef Documentation

◆ Latches

typedef std::vector<Latched, ut::allocator<Latched> > Latches

Thread specific latches.

This is ordered on level in descending order.

Function Documentation

◆ rw_lock_debug_mutex_enter()

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.

◆ rw_lock_debug_mutex_exit()

void rw_lock_debug_mutex_exit ( )

Releases the debug mutex.

◆ sync_check_close()

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.

◆ sync_check_enable()

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

◆ sync_check_find()

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.

Parameters
[in]levelto find
Returns
a matching latch, or NULL if not found

◆ sync_check_init()

void sync_check_init ( size_t  max_threads)

Initializes the synchronization data structures.

Parameters
[in]max_threadsMaximum threads that can be created.

For collecting latch statistic - SHOW ... MUTEX

For trcking mutex creation location

◆ sync_check_iterate()

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.

Parameters
[in,out]functorcalled for each element.
Returns
true if the functor returns true

◆ sync_check_lock()

void sync_check_lock ( const latch_t latch,
latch_level_t  level 
)

Check if it is OK to acquire the latch.

Parameters
[in]latchlatch type
[in]levelthe level of the mutex

◆ sync_check_lock_granted()

void sync_check_lock_granted ( const latch_t latch)

Note that the lock has been granted.

Parameters
[in]latchlatch type

◆ sync_check_lock_validate()

void sync_check_lock_validate ( const latch_t latch)

Check if it is OK to acquire the latch.

Parameters
[in]latchlatch type

◆ sync_check_relock()

void sync_check_relock ( const latch_t latch)

Check if it is OK to re-acquire the lock.

Parameters
[in]latchRW-LOCK to relock (recursive X locks)

◆ sync_check_unlock()

void sync_check_unlock ( const latch_t latch)

Removes a latch from the thread level array if it is found there.

Parameters
[in]latchThe latch to unlock

◆ sync_file_created_deregister()

void sync_file_created_deregister ( const void *  ptr)

Deregister a latch, called when it is destroyed.

Parameters
[in]ptrLatch to be destroyed

◆ sync_file_created_get()

std::string sync_file_created_get ( const void *  ptr)

Get the string where the file was created.

Its format is "name:line"

Parameters
[in]ptrLatch instance
Returns
created information or "" if can't be found

◆ sync_file_created_register()

void sync_file_created_register ( const void *  ptr,
const char *  filename,
uint16_t  line 
)

Register a latch, called when it is created.

Parameters
[in]ptrLatch instance that was created
[in]filenameFilename where it was created
[in]lineLine number in filename

◆ sync_latch_meta_destroy()

static void sync_latch_meta_destroy ( )
static

Destroy the latch meta data.

◆ sync_latch_meta_init()

static void sync_latch_meta_init ( )
static

Load the latch meta data.

Variable Documentation

◆ create_tracker

CreateTracker* create_tracker
static

Track latch creation location.

For reducing the size of the latches

◆ latch_meta

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()

◆ rw_lock_debug_event

os_event_t rw_lock_debug_event
static

If deadlock detection does not get immediately the mutex, it may wait for this event.

◆ rw_lock_debug_mutex

ib_mutex_t rw_lock_debug_mutex
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.

◆ rw_lock_debug_waiters

std::atomic<bool> rw_lock_debug_waiters {false}
static

This is set to true, if there may be waiters for the event.

◆ srv_sync_debug

bool srv_sync_debug