thread_pool_priv.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License, version 2.0,
  5. as published by the Free Software Foundation.
  6. This program is also distributed with certain software (including
  7. but not limited to OpenSSL) that is licensed under separate terms,
  8. as designated in a particular file or component or in included license
  9. documentation. The authors of MySQL hereby grant you an additional
  10. permission to link the program and your derivative works with the
  11. separately licensed software that they have included with MySQL.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License, version 2.0, for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef THREAD_POOL_PRIV_INCLUDED
  21. #define THREAD_POOL_PRIV_INCLUDED
  22. /*
  23. The thread pool requires access to some MySQL server error codes, this is
  24. accessed from mysqld_error.h.
  25. We need access to the struct that defines the thread pool plugin interface
  26. which is accessed through scheduler.h.
  27. All accesses to THD variables and functions are defined in this header file.
  28. A thread pool can also use DEBUG_SYNC and must thus include
  29. debug_sync.h
  30. To handle definitions of Information Schema plugins it is also required
  31. to include sql_profile.h and table.h.
  32. */
  33. #include <mysqld_error.h> /* To get ER_ERROR_ON_READ */
  34. #define MYSQL_SERVER 1
  35. #include <conn_handler/channel_info.h>
  36. #include <conn_handler/connection_handler_manager.h>
  37. #include <debug_sync.h>
  38. #include <sql_profile.h>
  39. #include <table.h>
  40. #include "field.h"
  41. #include "sql_thd_internal_api.h"
  42. #include <set>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. This structure must be populated by plugins which implement connection
  48. handlers and passed as an argument to my_connection_handler_set() in
  49. order to activate the connection handler.
  50. The structure contains pointers to plugin functions which the server
  51. will call when a new client connects or when the connection handler is
  52. unloaded. It also containts the maximum number of threads the connection
  53. handler will create.
  54. */
  55. struct Connection_handler_functions
  56. {
  57. /**
  58. The maximum number of threads this connection handler will create.
  59. */
  60. uint max_threads;
  61. /**
  62. Called by the server when a new client connects.
  63. @param channel_info Pointer to object containing information
  64. about the new connection.
  65. @retval true failure
  66. @retval false success
  67. */
  68. bool (*add_connection)(Channel_info *channel_info);
  69. /**
  70. Called by the server when the connection handler is destroyed.
  71. */
  72. void (*end)(void);
  73. };
  74. /* create thd from channel_info object */
  75. THD* create_thd(Channel_info* channel_info);
  76. /* destroy channel_info object */
  77. void destroy_channel_info(Channel_info* channel_info);
  78. /* Decrement connection counter */
  79. void dec_connection_count();
  80. /*
  81. thread_created is maintained by thread pool when activated since
  82. user threads are created by the thread pool (and also special
  83. threads to maintain the thread pool). This is done through
  84. inc_thread_created.
  85. */
  86. void inc_thread_created();
  87. void thd_lock_thread_count(THD *thd);
  88. void thd_unlock_thread_count(THD *thd);
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. /*
  93. Interface to global thread list iterator functions.
  94. Executes a function with signature 'void f(THD*, uint64)' for all THDs.
  95. */
  96. typedef void (do_thd_impl_uint64)(THD*, uint64);
  97. void do_for_all_thd(do_thd_impl_uint64, uint64);
  98. /* Needed to get access to scheduler variables */
  99. void* thd_get_scheduler_data(THD *thd);
  100. void thd_set_scheduler_data(THD *thd, void *data);
  101. PSI_thread* thd_get_psi(THD *thd);
  102. void thd_set_psi(THD *thd, PSI_thread *psi);
  103. /* Interface to THD variables and functions */
  104. void thd_set_killed(THD *thd);
  105. void thd_clear_errors(THD *thd);
  106. void thd_close_connection(THD *thd);
  107. THD *thd_get_current_thd();
  108. void thd_lock_data(THD *thd);
  109. void thd_unlock_data(THD *thd);
  110. bool thd_is_transaction_active(THD *thd);
  111. int thd_connection_has_data(THD *thd);
  112. void thd_set_net_read_write(THD *thd, uint val);
  113. uint thd_get_net_read_write(THD *thd);
  114. void thd_set_not_killable(THD *thd);
  115. ulong thd_get_net_wait_timeout(THD *thd);
  116. my_socket thd_get_fd(THD *thd);
  117. int thd_store_globals(THD* thd);
  118. /* Print to the MySQL error log */
  119. void sql_print_error(const char *format, ...);
  120. void sql_print_warning(const char *format, ...);
  121. void sql_print_information(const char *format, ...);
  122. /* Store a table record */
  123. bool schema_table_store_record(THD *thd, TABLE *table);
  124. /*
  125. The thread pool must be able to execute statements using the connection
  126. state in THD object. This is the main objective of the thread pool to
  127. schedule the start of these commands.
  128. */
  129. bool do_command(THD *thd);
  130. /*
  131. The thread pool requires an interface to the connection logic in the
  132. MySQL Server since the thread pool will maintain the event logic on
  133. the TCP connection of the MySQL Server. Thus new connections, dropped
  134. connections will be discovered by the thread pool and it needs to
  135. ensure that the proper MySQL Server logic attached to these events is
  136. executed.
  137. */
  138. /* Prepare connection as part of connection set-up */
  139. bool thd_prepare_connection(THD *thd);
  140. /* Release auditing before executing statement */
  141. void mysql_audit_release(THD *thd);
  142. /* Check if connection is still alive */
  143. bool thd_connection_alive(THD *thd);
  144. /* Close connection with possible error code */
  145. void close_connection(THD *thd, uint sql_errno,
  146. bool server_shutdown, bool generate_event);
  147. /* End the connection before closing it */
  148. void end_connection(THD *thd);
  149. /* Reset thread globals */
  150. void reset_thread_globals(THD *thd);
  151. /*
  152. max_connections is needed to calculate the maximum number of threads
  153. that is allowed to be started by the thread pool. The method
  154. get_max_connections() gets reference to this variable.
  155. */
  156. ulong get_max_connections(void);
  157. /*
  158. connection_attrib is the thread attributes for connection threads,
  159. the method get_connection_attrib provides a reference to these
  160. attributes.
  161. */
  162. my_thread_attr_t *get_connection_attrib(void);
  163. /* Increment the status variable 'Aborted_connects'. */
  164. #ifndef EMBEDDED_LIBRARY
  165. void increment_aborted_connects();
  166. #endif
  167. #endif // THREAD_POOL_PRIV_INCLUDED