MySQL  8.0.16
Source Code Documentation
connection_handler_impl.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
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.
69  static bool shrink_cache; // Protected by LOCK_thread_cache
70  // System variable
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 
95 
96  protected:
97  virtual bool add_connection(Channel_info *channel_info);
98 
99  virtual uint get_max_threads() const;
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:
114 
115  protected:
116  virtual bool add_connection(Channel_info *channel_info);
117 
118  virtual uint get_max_threads() const { return 1; }
119 };
120 
121 #endif // CONNECTION_HANDLER_IMPL_INCLUDED
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:379
Instrumentation helpers for mutexes.
virtual uint get_max_threads() const
Definition: connection_handler_impl.h:118
virtual ~One_thread_connection_handler()
Definition: connection_handler_impl.h:113
This abstract base class represents how connections are processed, most importantly how they map to O...
Definition: connection_handler.h:36
One_thread_connection_handler & operator=(const One_thread_connection_handler &)
static mysql_mutex_t LOCK_thread_cache
Definition: connection_handler_impl.h:61
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
Per_thread_connection_handler & operator=(const Per_thread_connection_handler &)
static ulong slow_launch_threads
Definition: connection_handler_impl.h:68
static void destroy()
Definition: connection_handler_per_thread.cc:125
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
virtual bool add_connection(Channel_info *channel_info)
Add a connection.
Definition: connection_handler_one_thread.cc:42
static mysql_cond_t COND_thread_cache
Definition: connection_handler_impl.h:62
static ulong max_blocked_pthreads
Definition: connection_handler_impl.h:71
virtual uint get_max_threads() const
Definition: connection_handler_per_thread.cc:435
static void init()
Definition: connection_handler_per_thread.cc:108
unsigned int uint
Definition: uca-dump.cc:29
Instrumentation helpers for conditions.
This class represents the connection handling functionality that each connection is being handled in ...
Definition: connection_handler_impl.h:41
virtual bool add_connection(Channel_info *channel_info)
Add a connection.
Definition: connection_handler_per_thread.cc:396
static mysql_cond_t COND_flush_thread_cache
Definition: connection_handler_impl.h:63
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
static bool shrink_cache
Definition: connection_handler_impl.h:69
This class represents the connection handling functionality of all connections being handled in a sin...
Definition: connection_handler_impl.h:106
virtual ~Per_thread_connection_handler()
Definition: connection_handler_impl.h:94
static Channel_info * block_until_new_connection()
Block until a new connection arrives.
Definition: connection_handler_per_thread.cc:143
static void modify_thread_cache_size(const ulong thread_cache_size)
Modify the thread cache size.
Definition: connection_handler_per_thread.cc:352
One_thread_connection_handler()
Definition: connection_handler_impl.h:112
static void kill_blocked_pthreads()
Wake blocked pthreads and wait until they have terminated.
Definition: connection_handler_per_thread.cc:375
Per_thread_connection_handler()
Definition: connection_handler_impl.h:93
This abstract base class represents connection channel information about a new connection.
Definition: channel_info.h:46
unsigned long ulong
Definition: my_inttypes.h:46
static ulong blocked_pthread_count
Definition: connection_handler_impl.h:67
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:776