MySQL 8.4.2
Source Code Documentation
connection_handler_impl.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2013, 2024, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef CONNECTION_HANDLER_IMPL_INCLUDED
27#define CONNECTION_HANDLER_IMPL_INCLUDED
28
29#include <list>
30
31#include "mysql/psi/mysql_cond.h" // mysql_cond_t
32#include "mysql/psi/mysql_mutex.h" // mysql_mutex_t
33#include "sql/conn_handler/connection_handler.h" // Connection_handler
34
35class Channel_info;
36class THD;
37
38/**
39 This class represents the connection handling functionality
40 that each connection is being handled in a single thread
41*/
46
47 /**
48 Check if idle threads to handle connection in
49 thread cache. If so enqueue the new connection
50 to be picked by the idle thread in thread cache.
51
52 @retval false if idle pthread was found, else true.
53 */
55
56 /**
57 List of pending channel info objects to be picked by idle
58 threads. Protected by LOCK_thread_cache.
59 */
60 static std::list<Channel_info *> *waiting_channel_info_list;
61
65
66 public:
67 // Status variables related to Per_thread_connection_handler
68 static ulong blocked_pthread_count; // Protected by LOCK_thread_cache.
69 static ulong slow_launch_threads;
70 static bool shrink_cache; // Protected by LOCK_thread_cache
71 // System variable
73
74 static void init();
75 static void destroy();
76
77 /**
78 Wake blocked pthreads and wait until they have terminated.
79 */
80 static void kill_blocked_pthreads();
81
82 /**
83 Block until a new connection arrives.
84 */
86
87 /**
88 Modify the thread cache size.
89
90 @param thread_cache_size size of thread cache.
91 */
92 static void modify_thread_cache_size(const ulong thread_cache_size);
93
94 /**
95 Return blocked threads count.
96 */
97 static ulong get_blocked_pthread_count();
98
100 ~Per_thread_connection_handler() override = default;
101
102 protected:
103 bool add_connection(Channel_info *channel_info) override;
104
105 uint get_max_threads() const override;
106};
107
108/**
109 This class represents the connection handling functionality
110 of all connections being handled in a single worker thread.
111*/
116
117 public:
119 ~One_thread_connection_handler() override = default;
120
121 protected:
122 bool add_connection(Channel_info *channel_info) override;
123
124 uint get_max_threads() const override { return 1; }
125};
126
127#endif // CONNECTION_HANDLER_IMPL_INCLUDED
This abstract base class represents connection channel information about a new connection.
Definition: channel_info.h:47
This abstract base class represents how connections are processed, most importantly how they map to O...
Definition: connection_handler.h:37
This class represents the connection handling functionality of all connections being handled in a sin...
Definition: connection_handler_impl.h:112
One_thread_connection_handler(const One_thread_connection_handler &)
uint get_max_threads() const override
Definition: connection_handler_impl.h:124
~One_thread_connection_handler() override=default
bool add_connection(Channel_info *channel_info) override
Add a connection.
Definition: connection_handler_one_thread.cc:43
One_thread_connection_handler & operator=(const One_thread_connection_handler &)
This class represents the connection handling functionality that each connection is being handled in ...
Definition: connection_handler_impl.h:42
static ulong get_blocked_pthread_count()
Return blocked threads count.
Definition: connection_handler_per_thread.cc:446
static void destroy()
Definition: connection_handler_per_thread.cc:126
static void kill_blocked_pthreads()
Wake blocked pthreads and wait until they have terminated.
Definition: connection_handler_per_thread.cc:383
bool add_connection(Channel_info *channel_info) override
Add a connection.
Definition: connection_handler_per_thread.cc:404
static void modify_thread_cache_size(const ulong thread_cache_size)
Modify the thread cache size.
Definition: connection_handler_per_thread.cc:360
static ulong max_blocked_pthreads
Definition: connection_handler_impl.h:72
bool check_idle_thread_and_enqueue_connection(Channel_info *channel_info)
Check if idle threads to handle connection in thread cache.
Definition: connection_handler_per_thread.cc:387
static bool shrink_cache
Definition: connection_handler_impl.h:70
Per_thread_connection_handler(const Per_thread_connection_handler &)
Per_thread_connection_handler & operator=(const Per_thread_connection_handler &)
static ulong slow_launch_threads
Definition: connection_handler_impl.h:69
~Per_thread_connection_handler() override=default
static mysql_cond_t COND_thread_cache
Definition: connection_handler_impl.h:63
static ulong blocked_pthread_count
Definition: connection_handler_impl.h:68
static std::list< Channel_info * > * waiting_channel_info_list
List of pending channel info objects to be picked by idle threads.
Definition: connection_handler_impl.h:60
uint get_max_threads() const override
Definition: connection_handler_per_thread.cc:442
static mysql_mutex_t LOCK_thread_cache
Definition: connection_handler_impl.h:62
static void init()
Definition: connection_handler_per_thread.cc:109
static Channel_info * block_until_new_connection()
Block until a new connection arrives.
Definition: connection_handler_per_thread.cc:144
static mysql_cond_t COND_flush_thread_cache
Definition: connection_handler_impl.h:64
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Instrumentation helpers for conditions.
Instrumentation helpers for mutexes.
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50