MySQL 26.10.0
Source Code Documentation
mrs_component.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, 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 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 MRS_COMPONENT_H
27#define MRS_COMPONENT_H
28
29#include <atomic>
30#include <memory>
31#include <string>
32
52
58
59#include <mysqld_error.h> /* Errors */
60
61/**
62 Component Service placeholders
63*/
64
65// Logging services
67extern REQUIRES_SERVICE_PLACEHOLDER_AS(log_builtins_string, log_bs);
68
69// Sysvar reader
70extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_system_variable_reader,
72
73// Sysvar registry
74extern REQUIRES_SERVICE_PLACEHOLDER_AS(component_sys_variable_register,
75 sysvar_register);
76extern REQUIRES_SERVICE_PLACEHOLDER_AS(component_sys_variable_unregister,
77 sysvar_unregister);
78
79// Statusvar reader and registry
80extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_status_variable_string,
81 statusvar_reader);
82extern REQUIRES_SERVICE_PLACEHOLDER_AS(status_variable_registration,
83 statusvar_register);
84
85// Command-service sessions and text query execution
86extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_factory, cmd_factory);
87extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_options, cmd_options);
88extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_query, cmd_query);
89extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_thread, cmd_thread);
90extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_query_result,
91 cmd_query_result);
92extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_field_info,
93 cmd_field_info);
94extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_error_info,
95 cmd_error_info);
96extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_field_metadata,
97 cmd_field_meta);
98extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_command_session_state,
99 cmd_session_state);
100
101// Prepared statement execution
102extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_factory, stmt_factory);
104extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_metadata, stmt_metadata);
105extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_bind, stmt_bind);
106extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_get_string, stmt_get_string);
107extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_get_time, stmt_get_time);
108extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_get_double, stmt_get_double);
109extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_get_unsigned_integer,
110 stmt_get_unsigned_integer);
111extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_get_integer,
112 stmt_get_integer);
113extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_diagnostics,
114 stmt_diagnostics);
115extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_resultset_metadata,
116 stmt_resultset_metadata);
117extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_result, stmt_result);
118extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_stmt_attributes, stmt_attributes);
119
120// MySQL thread context
123extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_thd_security_context,
124 thread_security_ctx);
125extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_security_context_factory,
126 security_ctx_factory);
128 mysql_account_database_security_context_lookup, security_ctx_lookup);
129extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_security_context_options,
130 thread_security_ctx_opts);
131
132// Dynamic privilege management
134 dynamic_privilege_registry);
136 global_grants_checker);
137
138// MySQL String
139extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_string_factory, string_factory);
140extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_string_get_data_in_charset,
141 string_get_data_in_charset);
142extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_string_converter,
143 string_converter);
144
145// Table access
146extern REQUIRES_SERVICE_PLACEHOLDER_AS(table_access_factory_v1,
147 table_access_factory);
148extern REQUIRES_SERVICE_PLACEHOLDER_AS(table_access_v1, table_access);
149extern REQUIRES_SERVICE_PLACEHOLDER_AS(field_varchar_access_v1,
150 field_varchar_access);
151extern REQUIRES_SERVICE_PLACEHOLDER_AS(table_access_scan_v1, table_access_scan);
152extern REQUIRES_SERVICE_PLACEHOLDER_AS(field_access_nullability_v1,
153 field_access_nullability);
154extern REQUIRES_SERVICE_PLACEHOLDER_AS(field_any_access_v1, field_any_access);
155
156// UDF registry
157extern REQUIRES_SERVICE_PLACEHOLDER_AS(udf_registration, udf_registry);
158extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_udf_metadata, udf_metadata);
159
160// DBUG_EXECUTE_IF for Components
161#if !defined(NDEBUG)
162extern REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_debug_keyword_service,
163 debug_keyword_service);
164extern REQUIRES_SERVICE_PLACEHOLDER(mysql_debug_sync_service);
165#endif
166
167namespace mrs_component {
168
172
173constexpr const char kMysqlRestServiceAdmin[] = "MYSQL_REST_SERVICE_ADMIN";
174
175class MRSComponent;
176class ServerConfig;
177class SystemVars;
178
179extern std::unique_ptr<MRSComponent> s_mrs_component; // main handler
180
181/**
182 Returns the active MRS component instance.
183*/
185
186/**
187 Coordinates registration and lifecycle of the MySQL REST Service component.
188*/
190 public:
191 MRSComponent() = default;
192 ~MRSComponent() = default;
193
194 MRSComponent(const MRSComponent &) = delete;
198
199 [[nodiscard]] const char *name() const { return m_name.c_str(); }
200
201 int server_config_init();
202 int system_vars_init();
205 int status_vars_init();
210 int udfs_init();
211 int udfs_register();
212 int udfs_unregister();
213
214 int backend_init();
215 int backend_start();
216 int backend_restart();
217 int backend_stop();
218
221
222 [[nodiscard]] bool initialized() const { return m_initialized; }
224
228 UDFs &udfs() { return m_udfs; }
229 Backend &backend() { return m_backend; }
230 const Log &log() const { return m_log; }
231
232 private:
233 const std::string m_name{"MySQL Rest Service Component"};
234
235 std::atomic<bool> m_initialized = false;
239 bool m_udfs_registered = false;
240
247};
248
249} // namespace mrs_component
250
251#endif // MRS_COMPONENT_H
Owns and controls the embedded MRS backend lifecycle.
Definition: mrs_component_backend.h:111
Emits MRS messages through the MySQL Server logging services.
Definition: mrs_component_log.h:36
Coordinates registration and lifecycle of the MySQL REST Service component.
Definition: mrs_component.h:189
bool m_udfs_registered
Definition: mrs_component.h:239
mysql_service_status_t component_deinit()
Deinitialize the Main handler class.
Definition: mrs_component.cc:428
int backend_init()
Definition: mrs_component.cc:335
ServerConfig m_server_config
Definition: mrs_component.h:241
const std::string m_name
Definition: mrs_component.h:233
const Log & log() const
Definition: mrs_component.h:230
int admin_privilege_unregister()
Definition: mrs_component.cc:284
MRSComponent(const MRSComponent &)=delete
int system_vars_unregister()
Unregister all system variables.
Definition: mrs_component.cc:221
StatusVars & status_vars()
Definition: mrs_component.h:227
StatusVars m_status_vars
Definition: mrs_component.h:243
MRSComponent & operator=(const MRSComponent &)=delete
Backend & backend()
Definition: mrs_component.h:229
Backend m_backend
Definition: mrs_component.h:246
int udfs_register()
Register all UDFs.
Definition: mrs_component.cc:309
int udfs_init()
Initialize all UDFs.
Definition: mrs_component.cc:301
int admin_privilege_register()
Definition: mrs_component.cc:266
bool m_status_vars_registered
Definition: mrs_component.h:237
int status_vars_register()
Register all status variables.
Definition: mrs_component.cc:240
int backend_stop()
Definition: mrs_component.cc:358
int udfs_unregister()
Unregister all UDFs.
Definition: mrs_component.cc:327
int status_vars_init()
Initialize all status variables.
Definition: mrs_component.cc:232
const char * name() const
Definition: mrs_component.h:199
SystemVars m_system_vars
Definition: mrs_component.h:242
bool initialized() const
Definition: mrs_component.h:222
UDFs m_udfs
Definition: mrs_component.h:244
MRSComponent & operator=(MRSComponent &&)=delete
int system_vars_init()
Initialize all system variables.
Definition: mrs_component.cc:195
int backend_start()
Definition: mrs_component.cc:344
Log m_log
Definition: mrs_component.h:245
int backend_restart()
Definition: mrs_component.cc:352
ServerConfig & server_config()
Definition: mrs_component.h:225
MRSComponent(MRSComponent &&)=delete
bool m_admin_privilege_registered
Definition: mrs_component.h:238
UDFs & udfs()
Definition: mrs_component.h:228
int status_vars_unregister()
Unregister all status variables.
Definition: mrs_component.cc:258
std::atomic< bool > m_initialized
Definition: mrs_component.h:235
mysql_service_status_t component_init()
Initialize the Main handler class.
Definition: mrs_component.cc:367
SystemVars & system_vars()
Definition: mrs_component.h:226
void set_initialized(bool initialized)
Definition: mrs_component.h:223
int system_vars_register()
Register all system variables.
Definition: mrs_component.cc:203
int server_config_init()
Read all needed Server system variables.
Definition: mrs_component.cc:187
bool m_system_vars_registered
Definition: mrs_component.h:236
Holds the Server configuration required by the MRS component.
Definition: mrs_component_server_config.h:36
Owns and manages status variables exposed by the MRS component.
Definition: mrs_component_status_vars.h:49
Owns and manages system variables exposed by the MRS component.
Definition: mrs_component_system_vars.h:68
Owns and manages the UDFs provided by the MRS component.
Definition: mrs_component_udfs.h:56
Specifies macros to define Components.
const mysql_service_log_builtins_string_t * log_bs
Definition: connection_control.cc:45
const mysql_service_log_builtins_t * log_bi
Definition: connection_control.cc:44
const mysql_service_mysql_system_variable_reader_t * sysvar_reader
Definition: ha_innodb.cc:290
REQUIRES_SERVICE_PLACEHOLDER(mysql_current_thread_reader)
REQUIRES_SERVICE_PLACEHOLDER_AS(log_builtins, log_bi)
Component Service placeholders.
int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt)
Definition: libmysql.cc:2377
Read status variable values service(s)
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
Definition: mrs_component.cc:137
MRSComponent & mrs_component()
Returns the active MRS component instance.
Definition: mrs_component.cc:178
void register_io_thread_instrumentation()
Definition: mrs_component.cc:154
void deinitialize_io_thread_instrumentation(size_t)
Definition: mrs_component.cc:171
std::unique_ptr< MRSComponent > s_mrs_component
Definition: mrs_component.cc:175
void initialize_io_thread_instrumentation(size_t index)
Definition: mrs_component.cc:161
constexpr const char kMysqlRestServiceAdmin[]
Definition: mrs_component.h:173
const mysql_service_dynamic_privilege_register_t * dynamic_privilege_register
Definition: rewriter_plugin.cc:62
const mysql_service_mysql_thd_attributes_t * mysql_thd_attributes
Definition: rewriter_plugin.cc:59
const mysql_service_mysql_current_thread_reader_t * mysql_current_thread_reader
Definition: rewriter_plugin.cc:63
const mysql_service_global_grants_check_t * global_grants_check
Definition: rewriter_plugin.cc:65
int mysql_service_status_t
Specific type for the service status return values.
Definition: service.h:34