MySQL 8.2.0
Source Code Documentation
sql_plugin.h
Go to the documentation of this file.
1/* Copyright (c) 2005, 2023, Oracle and/or its affiliates.
2
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
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef _sql_plugin_h
24#define _sql_plugin_h
25
26#include <stddef.h>
27#include <sys/types.h>
28#include <vector>
29
30#include "lex_string.h"
31#include "my_io.h"
32#include "my_sqlcommand.h" // enum_sql_command
34#include "sql/sql_cmd.h" // Sql_cmd
35#include "sql/sql_plugin_ref.h" // plugin_ref
36
37class THD;
38class i_string;
39struct MEM_ROOT;
40struct SYS_VAR;
41struct my_option;
42template <class T>
43class I_List;
44
45extern const char *global_plugin_typelib_names[];
48
49#ifdef NDEBUG
50#define plugin_ref_to_int(A) A
51#define plugin_int_to_ref(A) A
52#else
53#define plugin_ref_to_int(A) (A ? A[0] : NULL)
54#define plugin_int_to_ref(A) &(A)
55#endif
56
57/*
58 the following flags are valid for plugin_init()
59*/
60#define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
61#define PLUGIN_INIT_SKIP_PLUGIN_TABLE 2
62#define PLUGIN_INIT_SKIP_INITIALIZATION 4
63#define PLUGIN_INIT_DELAY_UNTIL_AFTER_UPGRADE 8
64
65#define MYSQL_ANY_PLUGIN -1
66
67/*
68 different values of st_plugin_int::state
69 though they look like a bitmap, plugin may only
70 be in one of those eigenstates, not in a superposition of them :)
71 It's a bitmap, because it makes it easier to test
72 "whether the state is one of those..."
73*/
74#define PLUGIN_IS_FREED 1
75#define PLUGIN_IS_DELETED 2
76#define PLUGIN_IS_UNINITIALIZED 4
77#define PLUGIN_IS_READY 8
78#define PLUGIN_IS_DYING 16
79#define PLUGIN_IS_DISABLED 32
80#define PLUGIN_IS_WAITING_FOR_UPGRADE 64
81
82/* A handle for the dynamic library containing a plugin or plugins. */
83
86 void *handle;
89 uint ref_count; /* number of plugins loaded from the library */
90};
91
92/**
93 This class implements the INSTALL PLUGIN statement.
94*/
95
97 public:
99 : m_comment(comment), m_ident(ident) {}
100
103 }
104
105 /**
106 Install a new plugin by inserting a row into the
107 mysql.plugin table, creating a cache entry and
108 initializing plugin's internal data.
109
110 @param thd Thread context
111
112 @returns false if success, true otherwise
113 */
114 bool execute(THD *thd) override;
115
116 private:
119};
120
121/**
122 This class implements the UNINSTALL PLUGIN statement.
123*/
124
126 public:
128 : m_comment(comment) {}
129
132 }
133
134 /**
135 Uninstall a plugin by removing a row from the
136 mysql.plugin table, deleting a cache entry and
137 deinitializing plugin's internal data.
138
139 @param thd Thread context
140
141 @returns false if success, true otherwise
142 */
143 bool execute(THD *thd) override;
144
145 private:
147};
148
149typedef int (*plugin_type_init)(struct st_plugin_int *);
150
153extern char *opt_plugin_dir_ptr;
154extern char opt_plugin_dir[FN_REFLEN];
155extern const LEX_CSTRING plugin_type_names[];
156
157extern bool plugin_register_early_plugins(int *argc, char **argv, int flags);
158extern bool plugin_register_builtin_and_init_core_se(int *argc, char **argv);
159extern bool plugin_register_dynamic_and_init_all(int *argc, char **argv,
160 int init_flags);
161extern bool update_persisted_plugin_sysvars(const char *name);
162
163namespace dd {
164namespace upgrade {
166}
167} // namespace dd
168
170extern void plugin_shutdown(void);
171extern void memcached_shutdown(void);
172void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root);
173extern bool plugin_is_ready(const LEX_CSTRING &name, int type);
174#define my_plugin_lock_by_name(A, B, C) plugin_lock_by_name(A, B, C)
175#define my_plugin_lock_by_name_ci(A, B, C) plugin_lock_by_name(A, B, C)
176#define my_plugin_lock(A, B) plugin_lock(A, B)
177#define my_plugin_lock_ci(A, B) plugin_lock(A, B)
178extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr);
180 int type);
181extern void plugin_unlock(THD *thd, plugin_ref plugin);
182extern void plugin_unlock_list(THD *thd, plugin_ref *list, size_t count);
183extern void plugin_thdvar_init(THD *thd, bool enable_plugins);
184extern void plugin_thdvar_cleanup(THD *thd, bool enable_plugins);
185extern void plugin_thdvar_safe_update(THD *thd, SYS_VAR *var, char **dest,
186 const char *value);
187extern bool check_valid_path(const char *path, size_t length);
188extern void alloc_and_copy_thd_dynamic_variables(THD *thd, bool global_lock);
189
190typedef bool(plugin_foreach_func)(THD *thd, plugin_ref plugin, void *arg);
191#define plugin_foreach(A, B, C, D) \
192 plugin_foreach_with_mask(A, B, C, PLUGIN_IS_READY, D)
193extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
194 int type, uint state_mask, void *arg);
195extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func **funcs,
196 int type, uint state_mask, void *arg);
197bool end_transaction(THD *thd, bool error);
198
199/**
200 Initialize one plugin.
201*/
202bool plugin_early_load_one(int *argc, char **argv, const char *plugin);
203
204#endif
Definition: sql_list.h:810
This class implements the INSTALL PLUGIN statement.
Definition: sql_plugin.h:96
bool execute(THD *thd) override
Install a new plugin by inserting a row into the mysql.plugin table, creating a cache entry and initi...
Definition: sql_plugin.cc:3708
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_plugin.h:101
LEX_STRING m_ident
Definition: sql_plugin.h:118
LEX_CSTRING m_comment
Definition: sql_plugin.h:117
Sql_cmd_install_plugin(const LEX_CSTRING &comment, const LEX_STRING &ident)
Definition: sql_plugin.h:98
This class implements the UNINSTALL PLUGIN statement.
Definition: sql_plugin.h:125
Sql_cmd_uninstall_plugin(const LEX_CSTRING &comment)
Definition: sql_plugin.h:127
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_plugin.h:130
LEX_CSTRING m_comment
Definition: sql_plugin.h:146
bool execute(THD *thd) override
Uninstall a plugin by removing a row from the mysql.plugin table, deleting a cache entry and deinitia...
Definition: sql_plugin.cc:3715
Representation of an SQL command.
Definition: sql_cmd.h:81
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: sql_list.h:697
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
static int flags[50]
Definition: hp_test1.cc:39
#define comment
Definition: lexyy.cc:959
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:82
enum_sql_command
Definition: my_sqlcommand.h:45
@ SQLCOM_INSTALL_PLUGIN
Definition: my_sqlcommand.h:161
@ SQLCOM_UNINSTALL_PLUGIN
Definition: my_sqlcommand.h:162
static int count
Definition: myisam_ftdump.cc:44
ABI for instrumented mutexes.
Log error(cerr, "ERROR")
static char * path
Definition: mysqldump.cc:148
bool plugin_initialize_delayed_after_upgrade()
Initialize delayed plugins.
Definition: sql_plugin.cc:1721
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
Definition: options.cc:56
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2877
required string type
Definition: replication_group_member_actions.proto:33
Representation of an SQL command.
bool plugin_early_load_one(int *argc, char **argv, const char *plugin)
Initialize one plugin.
Definition: sql_plugin.cc:2252
void plugin_unlock(THD *thd, plugin_ref plugin)
Definition: sql_plugin.cc:1265
void alloc_and_copy_thd_dynamic_variables(THD *thd, bool global_lock)
Allocate memory and copy dynamic variables from global system variables to per-thread system variable...
Definition: sql_plugin.cc:2935
void plugin_thdvar_init(THD *thd, bool enable_plugins)
Definition: sql_plugin.cc:3041
char * opt_plugin_dir_ptr
Definition: sql_plugin.cc:344
void plugin_thdvar_cleanup(THD *thd, bool enable_plugins)
Definition: sql_plugin.cc:3114
bool is_builtin_and_core_se_initialized()
Definition: sql_plugin.cc:1700
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr)
Definition: sql_plugin.cc:986
int(* plugin_type_init)(struct st_plugin_int *)
Definition: sql_plugin.h:149
mysql_mutex_t LOCK_plugin
Serializes access to the global plugin memory list.
Definition: sql_plugin.cc:452
const LEX_CSTRING plugin_type_names[]
Definition: sql_plugin.cc:350
bool check_valid_path(const char *path, size_t length)
Check if the provided path is valid in the sense that it does cause a relative reference outside the ...
Definition: sql_plugin.cc:573
const char * global_plugin_typelib_names[]
Definition: sql_plugin.cc:334
bool plugin_register_dynamic_and_init_all(int *argc, char **argv, int init_flags)
Register and initialize the dynamic plugins.
Definition: sql_plugin.cc:1790
bool plugin_register_builtin_and_init_core_se(int *argc, char **argv)
Register the builtin plugins.
Definition: sql_plugin.cc:1567
bool() plugin_foreach_func(THD *thd, plugin_ref plugin, void *arg)
Definition: sql_plugin.h:190
void plugin_unlock_list(THD *thd, plugin_ref *list, size_t count)
Definition: sql_plugin.cc:1279
void add_plugin_options(std::vector< my_option > *options, MEM_ROOT *mem_root)
Definition: sql_plugin.cc:3676
char opt_plugin_dir[FN_REFLEN]
Definition: sql_plugin.cc:345
I_List< i_string > * opt_early_plugin_load_list_ptr
Definition: sql_plugin.cc:343
void plugin_thdvar_safe_update(THD *thd, SYS_VAR *var, char **dest, const char *value)
Set value for a thread local variable.
Definition: sql_plugin.cc:3177
void memcached_shutdown(void)
Definition: sql_plugin.cc:2050
bool end_transaction(THD *thd, bool error)
Definition: sql_plugin.cc:2225
plugin_ref plugin_lock_by_name(THD *thd, const LEX_CSTRING &name, int type)
Definition: sql_plugin.cc:996
bool plugin_is_ready(const LEX_CSTRING &name, int type)
Definition: sql_plugin.cc:936
bool plugin_register_early_plugins(int *argc, char **argv, int flags)
Register and initialize early plugins.
Definition: sql_plugin.cc:1512
mysql_mutex_t LOCK_plugin_delete
Definition: sql_plugin.cc:441
bool update_persisted_plugin_sysvars(const char *name)
Update read-write persisted plugin system variables.
Definition: sql_plugin.cc:1545
I_List< i_string > * opt_plugin_load_list_ptr
Definition: sql_plugin.cc:341
void plugin_shutdown(void)
Definition: sql_plugin.cc:2079
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, int type, uint state_mask, void *arg)
Definition: sql_plugin.cc:2795
case opt name
Definition: sslopt-case.h:32
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: mysql_lex_string.h:39
Definition: mysql_lex_string.h:34
Definition: plugin.h:67
Definition: my_getopt.h:92
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Definition: plugin.h:634
Definition: sql_plugin.h:84
LEX_STRING dl
Definition: sql_plugin.h:85
void * handle
Definition: sql_plugin.h:86
int version
Definition: sql_plugin.h:88
struct st_mysql_plugin * plugins
Definition: sql_plugin.h:87
uint ref_count
Definition: sql_plugin.h:89
Definition: sql_plugin_ref.h:44