MySQL 8.3.0
Source Code Documentation
thread_pool_priv.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2010, 2023, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef THREAD_POOL_PRIV_INCLUDED
26#define THREAD_POOL_PRIV_INCLUDED
27
28/**
29 @file include/mysql/thread_pool_priv.h
30 All accesses to THD variables and functions are defined in this header file.
31*/
32#include <mysqld_error.h> /* To get ER_ERROR_ON_READ */
33
36
37/**
38 Called by the server when a new client connects.
39
40 @param channel_info Pointer to object containing information
41 about the new connection.
42
43 @retval true failure
44 @retval false success
45*/
46typedef bool (*add_connection_t)(Channel_info *channel_info);
47
48/**
49 Called by the server when the connection handler is destroyed.
50*/
51typedef void (*end_t)(void);
52
53/**
54 This structure must be populated by plugins which implement connection
55 handlers and passed as an argument to my_connection_handler_set() in
56 order to activate the connection handler.
57
58 The structure contains pointers to plugin functions which the server
59 will call when a new client connects or when the connection handler is
60 unloaded. It also contains the maximum number of threads the connection
61 handler will create.
62*/
64 /**
65 The maximum number of threads this connection handler will create.
66 */
68
71};
72
73/* create thd from channel_info object */
74THD *create_thd(Channel_info *channel_info);
75/* destroy channel_info object */
76void destroy_channel_info(Channel_info *channel_info);
77/* Decrement connection counter */
79/*
80 thread_created is maintained by thread pool when activated since
81 user threads are created by the thread pool (and also special
82 threads to maintain the thread pool). This is done through
83 inc_thread_created.
84*/
86
89
90/*
91 Interface to global thread list iterator functions.
92 Executes a function with signature 'void f(THD*, uint64)' for all THDs.
93*/
94typedef void(do_thd_impl_uint64)(THD *, uint64);
96
97/* Needed to get access to scheduler variables */
98void *thd_get_scheduler_data(THD *thd);
99void thd_set_scheduler_data(THD *thd, void *data);
101void thd_set_psi(THD *thd, PSI_thread *psi);
102
103/* Interface to THD variables and functions */
104void thd_set_killed(THD *thd);
105void thd_clear_errors(THD *thd);
106void thd_close_connection(THD *thd);
108void thd_lock_data(THD *thd);
109void thd_unlock_data(THD *thd);
113void thd_set_net_read_write(THD *thd, uint val);
114uint thd_get_net_read_write(THD *thd);
115void thd_set_not_killable(THD *thd);
116ulong thd_get_net_wait_timeout(THD *thd);
118void thd_store_globals(THD *thd);
120
121/*
122 The thread pool must be able to execute statements using the connection
123 state in THD object. This is the main objective of the thread pool to
124 schedule the start of these commands.
125*/
126bool do_command(THD *thd);
127
128/*
129 The thread pool requires an interface to the connection logic in the
130 MySQL Server since the thread pool will maintain the event logic on
131 the TCP connection of the MySQL Server. Thus new connections, dropped
132 connections will be discovered by the thread pool and it needs to
133 ensure that the proper MySQL Server logic attached to these events is
134 executed.
135*/
136/* Prepare connection as part of connection set-up */
137bool thd_prepare_connection(THD *thd);
138/* Release auditing before executing statement */
139void mysql_audit_release(THD *thd);
140/* Check if connection is still alive */
141bool thd_connection_alive(THD *thd);
142/* Close connection with possible error code */
143void close_connection(THD *thd, uint sql_errno, bool server_shutdown,
144 bool generate_event);
145/* End the connection before closing it */
146void end_connection(THD *thd);
147/* Reset thread globals */
148void reset_thread_globals(THD *thd);
149
150/*
151 max_connections is needed to calculate the maximum number of threads
152 that is allowed to be started by the thread pool. The method
153 get_max_connections() gets reference to this variable.
154*/
155ulong get_max_connections(void);
156/*
157 connection_attrib is the thread attributes for connection threads,
158 the method get_connection_attrib provides a reference to these
159 attributes.
160*/
162
163/* Increment the status variable 'Aborted_connects'. */
165
166#endif // THREAD_POOL_PRIV_INCLUDED
This abstract base class represents connection channel information about a new connection.
Definition: channel_info.h:46
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
bool do_command(THD *thd)
Read one command from connection and execute it (query or simple command).
Definition: sql_parse.cc:1318
struct PSI_thread PSI_thread
Definition: psi_thread_bits.h:81
uint64_t uint64
Definition: my_inttypes.h:68
pthread_attr_t my_thread_attr_t
Definition: my_thread_bits.h:48
int my_socket
Definition: mysql.h:64
This structure must be populated by plugins which implement connection handlers and passed as an argu...
Definition: thread_pool_priv.h:63
uint max_threads
The maximum number of threads this connection handler will create.
Definition: thread_pool_priv.h:67
add_connection_t add_connection
Definition: thread_pool_priv.h:69
end_t end
Definition: thread_pool_priv.h:70
void(* end_t)(void)
Called by the server when the connection handler is destroyed.
Definition: thread_pool_priv.h:51
bool thd_prepare_connection(THD *thd)
Definition: sql_connect.cc:892
PSI_thread * thd_get_psi(THD *thd)
Get reference to Performance Schema object for THD object.
Definition: sql_thd_api.cc:109
void do_for_all_thd(do_thd_impl_uint64, uint64)
Definition: mysqld_thd_manager.cc:393
ulong get_max_connections(void)
Get max number of connections.
Definition: sql_thd_api.cc:301
bool thd_in_active_multi_stmt_transaction(const THD *)
Predicate for determining if connection is in active multi-statement transaction.
Definition: sql_thd_api.cc:222
void close_connection(THD *thd, uint sql_errno, bool server_shutdown, bool generate_event)
Close a connection.
Definition: sql_connect.cc:917
ulong thd_get_net_wait_timeout(THD *thd)
Get net_wait_timeout for THD object.
Definition: sql_thd_api.cc:119
THD * thd_get_current_thd()
Get current THD object from thread local data.
Definition: sql_thd_api.cc:177
void * thd_get_scheduler_data(THD *thd)
Get reference to scheduler data object.
Definition: sql_thd_api.cc:88
my_thread_attr_t * get_connection_attrib(void)
Get thread attributes for connection threads.
Definition: sql_thd_api.cc:293
void reset_thread_globals(THD *thd)
Reset thread globals associated.
Definition: sql_thd_api.cc:185
void thd_lock_thread_count()
Definition: mysqld_thd_manager.cc:366
uint thd_get_net_read_write(THD *thd)
Get reading/writing on socket from THD object.
Definition: sql_thd_api.cc:244
void thd_lock_data(THD *thd)
Lock data that needs protection in THD object.
Definition: sql_thd_api.cc:196
void thd_close_connection(THD *thd)
Close the socket used by this connection.
Definition: sql_thd_api.cc:166
void mysql_audit_release(THD *thd)
Release any resources associated with the current thd.
Definition: sql_audit.cc:608
void thd_set_killed(THD *thd)
Set the state on connection to killed.
Definition: sql_thd_api.cc:138
void increment_aborted_connects()
Definition: connection_handler_manager.cc:280
bool(* add_connection_t)(Channel_info *channel_info)
Called by the server when a new client connects.
Definition: thread_pool_priv.h:46
void thd_set_not_killable(THD *thd)
Mark the THD as not killable as it is not currently used by a thread.
Definition: sql_thd_api.cc:265
void thd_unlock_data(THD *thd)
Unlock data that needs protection in THD object.
Definition: sql_thd_api.cc:204
THD * create_thd(Channel_info *channel_info)
Definition: connection_handler_manager.cc:266
bool thd_connection_alive(THD *thd)
Definition: sql_connect.cc:935
int thd_connection_has_data(THD *thd)
Check if there is buffered data on the socket representing the connection.
Definition: sql_thd_api.cc:232
void end_connection(THD *thd)
Definition: sql_connect.cc:732
void thd_set_net_read_write(THD *thd, uint val)
Set reading/writing on socket, used by SHOW PROCESSLIST.
Definition: sql_thd_api.cc:255
void() do_thd_impl_uint64(THD *, uint64)
Definition: thread_pool_priv.h:94
my_socket thd_get_fd(THD *thd)
Get socket file descriptor for this connection.
Definition: sql_thd_api.cc:275
void thd_unlock_thread_count()
Definition: mysqld_thd_manager.cc:371
void destroy_channel_info(Channel_info *channel_info)
Definition: connection_handler_manager.cc:274
void thd_set_psi(THD *thd, PSI_thread *psi)
Set reference to Performance Schema object for THD object.
Definition: sql_thd_api.cc:130
void thd_set_scheduler_data(THD *thd, void *data)
Set reference to Scheduler data object for THD object.
Definition: sql_thd_api.cc:97
bool thd_is_transaction_active(THD *thd)
Support method to check if connection has already started transaction.
Definition: sql_thd_api.cc:214
bool thd_check_connection_admin_privilege(THD *thd)
void dec_connection_count()
Definition: connection_handler_manager.cc:276
void thd_clear_errors(THD *thd)
Clear errors from the previous THD.
Definition: sql_thd_api.cc:157
void thd_store_globals(THD *thd)
Set thread specific environment required for thd cleanup in thread pool.
Definition: sql_thd_api.cc:285
void inc_thread_created()
Definition: mysqld_thd_manager.cc:362