MySQL  8.0.27
Source Code Documentation
connection_handler_impl.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013, 2021, 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 CONNECTION_HANDLER_IMPL_INCLUDED
26 #define CONNECTION_HANDLER_IMPL_INCLUDED
27 
28 #include <list>
29 
30 #include "mysql/psi/mysql_cond.h" // mysql_cond_t
31 #include "mysql/psi/mysql_mutex.h" // mysql_mutex_t
32 #include "sql/conn_handler/connection_handler.h" // Connection_handler
33 
34 class Channel_info;
35 class THD;
36 
37 /**
38  This class represents the connection handling functionality
39  that each connection is being handled in a single thread
40 */
45 
46  /**
47  Check if idle threads to handle connection in
48  thread cache. If so enqueue the new connection
49  to be picked by the idle thread in thread cache.
50 
51  @retval false if idle pthread was found, else true.
52  */
54 
55  /**
56  List of pending channel info objects to be picked by idle
57  threads. Protected by LOCK_thread_cache.
58  */
59  static std::list<Channel_info *> *waiting_channel_info_list;
60 
64 
65  public:
66  // Status variables related to Per_thread_connection_handler
67  static ulong blocked_pthread_count; // Protected by LOCK_thread_cache.
68  static ulong slow_launch_threads;
69  static bool shrink_cache; // Protected by LOCK_thread_cache
70  // System variable
71  static ulong max_blocked_pthreads;
72 
73  static void init();
74  static void destroy();
75 
76  /**
77  Wake blocked pthreads and wait until they have terminated.
78  */
79  static void kill_blocked_pthreads();
80 
81  /**
82  Block until a new connection arrives.
83  */
85 
86  /**
87  Modify the thread cache size.
88 
89  @param thread_cache_size size of thread cache.
90  */
91  static void modify_thread_cache_size(const ulong thread_cache_size);
92 
94  ~Per_thread_connection_handler() override = default;
95 
96  protected:
97  bool add_connection(Channel_info *channel_info) override;
98 
99  uint get_max_threads() const override;
100 };
101 
102 /**
103  This class represents the connection handling functionality
104  of all connections being handled in a single worker thread.
105 */
110 
111  public:
113  ~One_thread_connection_handler() override = default;
114 
115  protected:
116  bool add_connection(Channel_info *channel_info) override;
117 
118  uint get_max_threads() const override { return 1; }
119 };
120 
121 #endif // CONNECTION_HANDLER_IMPL_INCLUDED
This abstract base class represents connection channel information about a new connection.
Definition: channel_info.h:46
This abstract base class represents how connections are processed, most importantly how they map to O...
Definition: connection_handler.h:36
This class represents the connection handling functionality of all connections being handled in a sin...
Definition: connection_handler_impl.h:106
One_thread_connection_handler(const One_thread_connection_handler &)
One_thread_connection_handler & operator=(const One_thread_connection_handler &)
uint get_max_threads() const override
Definition: connection_handler_impl.h:118
~One_thread_connection_handler() override=default
bool add_connection(Channel_info *channel_info) override
Add a connection.
Definition: connection_handler_one_thread.cc:42
This class represents the connection handling functionality that each connection is being handled in ...
Definition: connection_handler_impl.h:41
static void destroy()
Definition: connection_handler_per_thread.cc:125
Per_thread_connection_handler & operator=(const Per_thread_connection_handler &)
static void kill_blocked_pthreads()
Wake blocked pthreads and wait until they have terminated.
Definition: connection_handler_per_thread.cc:373
bool add_connection(Channel_info *channel_info) override
Add a connection.
Definition: connection_handler_per_thread.cc:394
static void modify_thread_cache_size(const ulong thread_cache_size)
Modify the thread cache size.
Definition: connection_handler_per_thread.cc:350
static ulong max_blocked_pthreads
Definition: connection_handler_impl.h:71
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:377
static bool shrink_cache
Definition: connection_handler_impl.h:69
Per_thread_connection_handler(const Per_thread_connection_handler &)
static ulong slow_launch_threads
Definition: connection_handler_impl.h:68
~Per_thread_connection_handler() override=default
static mysql_cond_t COND_thread_cache
Definition: connection_handler_impl.h:62
static ulong blocked_pthread_count
Definition: connection_handler_impl.h:67
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:59
uint get_max_threads() const override
Definition: connection_handler_per_thread.cc:432
static mysql_mutex_t LOCK_thread_cache
Definition: connection_handler_impl.h:61
static void init()
Definition: connection_handler_per_thread.cc:108
static Channel_info * block_until_new_connection()
Block until a new connection arrives.
Definition: connection_handler_per_thread.cc:143
static mysql_cond_t COND_flush_thread_cache
Definition: connection_handler_impl.h:63
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
Instrumentation helpers for conditions.
Instrumentation helpers for mutexes.
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
unsigned int uint
Definition: uca-dump.cc:29