MySQL 9.0.0
Source Code Documentation
srv0conc.cc File Reference

InnoDB concurrency manager. More...

#include <mysql/service_thd_wait.h>
#include <stddef.h>
#include <sys/types.h>
#include "dict0dict.h"
#include "ha_prototypes.h"
#include "row0mysql.h"
#include "srv0srv.h"
#include "trx0trx.h"

Classes

struct  srv_conc_t
 Variables tracking the active and waiting threads. More...
 

Functions

static void srv_enter_innodb_with_tickets (trx_t *trx)
 Note that a user thread is entering InnoDB. More...
 
static dberr_t srv_conc_enter_innodb_with_atomics (trx_t *trx)
 Handle the scheduling of a user thread that wants to enter InnoDB. More...
 
static void srv_conc_exit_innodb_with_atomics (trx_t *trx)
 Note that a user thread is leaving InnoDB code. More...
 
dberr_t srv_conc_enter_innodb (row_prebuilt_t *prebuilt)
 Puts an OS thread to wait if there are too many concurrent threads (>= srv_thread_concurrency) inside InnoDB. More...
 
void srv_conc_force_enter_innodb (trx_t *trx)
 This lets a thread enter InnoDB regardless of the number of threads inside InnoDB. More...
 
void srv_conc_force_exit_innodb (trx_t *trx)
 This must be called when a thread exits InnoDB in a lock wait or at the end of an SQL statement. More...
 
int32_t srv_conc_get_waiting_threads (void)
 Get the count of threads waiting inside InnoDB. More...
 
int32_t srv_conc_get_active_threads (void)
 Get the count of threads active inside InnoDB. More...
 

Variables

ulong srv_n_free_tickets_to_enter = 500
 Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket. More...
 
ulong srv_adaptive_max_sleep_delay = 150000
 Maximum sleep delay (in micro-seconds), value of 0 disables it. More...
 
ulong srv_thread_sleep_delay = 10000
 Sleep delay for threads waiting to enter InnoDB. More...
 
ulong srv_thread_concurrency = 0
 The following controls how many threads we let inside InnoDB concurrently: threads waiting for locks are not counted into the number because otherwise we could get a deadlock. More...
 
static srv_conc_t srv_conc
 

Detailed Description

InnoDB concurrency manager.

Created 2011/04/18 Sunny Bains

Function Documentation

◆ srv_conc_enter_innodb()

dberr_t srv_conc_enter_innodb ( row_prebuilt_t prebuilt)

Puts an OS thread to wait if there are too many concurrent threads (>= srv_thread_concurrency) inside InnoDB.

The threads wait in a FIFO queue.

Parameters
[in,out]prebuiltrow prebuilt handler
Returns
Innodb error code.

◆ srv_conc_enter_innodb_with_atomics()

static dberr_t srv_conc_enter_innodb_with_atomics ( trx_t trx)
static

Handle the scheduling of a user thread that wants to enter InnoDB.

Setting srv_adaptive_max_sleep_delay > 0 switches the adaptive sleep calibration to ON. When set, we want to wait in the queue for as little time as possible. However, very short waits will result in a lot of context switches and that is also not desirable. When threads need to sleep multiple times we increment srv_thread_sleep_delay by one. When we see threads getting a slot without waiting and there are no other threads waiting in the queue, we try and reduce the wait as much as we can. Currently we reduce it by half each time. If the thread only had to wait for one turn before it was able to enter InnoDB we decrement it by one. This is to try and keep the sleep time stable around the "optimum" sleep time.

Returns
InnoDB error code.
Parameters
trxin/out: transaction that wants to enter InnoDB

◆ srv_conc_exit_innodb_with_atomics()

static void srv_conc_exit_innodb_with_atomics ( trx_t trx)
static

Note that a user thread is leaving InnoDB code.

Parameters
trxin/out: transaction

◆ srv_conc_force_enter_innodb()

void srv_conc_force_enter_innodb ( trx_t trx)

This lets a thread enter InnoDB regardless of the number of threads inside InnoDB.

This must be called when a thread ends a lock wait.

Parameters
trxin: transaction object associated with the thread

◆ srv_conc_force_exit_innodb()

void srv_conc_force_exit_innodb ( trx_t trx)

This must be called when a thread exits InnoDB in a lock wait or at the end of an SQL statement.

in: transaction object associated with the thread

Parameters
trxin: transaction object associated with the thread

◆ srv_conc_get_active_threads()

int32_t srv_conc_get_active_threads ( void  )

Get the count of threads active inside InnoDB.

◆ srv_conc_get_waiting_threads()

int32_t srv_conc_get_waiting_threads ( void  )

Get the count of threads waiting inside InnoDB.

◆ srv_enter_innodb_with_tickets()

static void srv_enter_innodb_with_tickets ( trx_t trx)
static

Note that a user thread is entering InnoDB.

Parameters
trxin/out: transaction that wants to enter InnoDB

Variable Documentation

◆ srv_adaptive_max_sleep_delay

ulong srv_adaptive_max_sleep_delay = 150000

Maximum sleep delay (in micro-seconds), value of 0 disables it.

◆ srv_conc

srv_conc_t srv_conc
static

◆ srv_n_free_tickets_to_enter

ulong srv_n_free_tickets_to_enter = 500

Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket.

◆ srv_thread_concurrency

ulong srv_thread_concurrency = 0

The following controls how many threads we let inside InnoDB concurrently: threads waiting for locks are not counted into the number because otherwise we could get a deadlock.

Value of 0 will disable the concurrency check.

◆ srv_thread_sleep_delay

ulong srv_thread_sleep_delay = 10000

Sleep delay for threads waiting to enter InnoDB.

In micro-seconds.