MySQL 9.1.0
Source Code Documentation
|
The plugin declaration part of the Rewriter plugin. More...
#include "plugin/rewriter/rewriter_plugin.h"
#include "my_config.h"
#include <assert.h>
#include <mysql/plugin_audit.h>
#include <mysql/psi/mysql_thread.h>
#include <stddef.h>
#include <algorithm>
#include <atomic>
#include <new>
#include <mysql/components/my_service.h>
#include <mysql/components/services/dynamic_privilege.h>
#include <mysql/components/services/log_builtins.h>
#include <mysql/components/services/mysql_current_thread_reader.h>
#include <mysql/components/services/mysql_thd_attributes.h>
#include <mysql/components/services/security_context.h>
#include "my_inttypes.h"
#include "my_psi_config.h"
#include "my_sys.h"
#include "mysql/psi/mysql_rwlock.h"
#include "mysqld_error.h"
#include "plugin/rewriter/rewriter.h"
#include "plugin/rewriter/rule.h"
#include "plugin/rewriter/services.h"
#include "template_utils.h"
Macros | |
#define | ACQUIRE_SERVICE(name) |
#define | RELEASE_SERVICE(service) |
Functions | |
template<class T > | |
T * | acquire_service (const char *service_name) |
template<class T , class TNoConst > | |
void | release_service (T *service) |
static void | update_verbose (MYSQL_THD, SYS_VAR *, void *, const void *save) |
Updater function for the status variable ..._verbose. More... | |
static void | update_enabled (MYSQL_THD, SYS_VAR *, void *, const void *value) |
Updater function for the status variable ..._enabled. More... | |
static void | update_enabled_for_threads_without_privilege_checks (MYSQL_THD, SYS_VAR *, void *, const void *value) |
Updater function for the status variable ..._enabled_for_threads_without_privilege_checks. More... | |
static | MYSQL_SYSVAR_INT (verbose, sys_var_verbose, PLUGIN_VAR_NOCMDARG, "Tells " PLUGIN_NAME " how verbose it should be.", nullptr, update_verbose, 1, 0, 2, 1) |
static | MYSQL_SYSVAR_BOOL (enabled, sys_var_enabled, PLUGIN_VAR_NOCMDARG, "Whether queries should actually be rewritten.", nullptr, update_enabled, 1) |
static | MYSQL_SYSVAR_BOOL (enabled_for_threads_without_privilege_checks, sys_var_enabled_for_threads_without_privilege_checks, PLUGIN_VAR_NOCMDARG, "Whether queries from threads which execute with privilege checks disabled" " should be rewritten.", nullptr, update_enabled_for_threads_without_privilege_checks, 1) |
MYSQL_PLUGIN | get_rewriter_plugin_info () |
static void | init_rewriter_psi_keys () |
static bool | reload (MYSQL_THD thd) |
Reloads the rules into the in-memory table. More... | |
static bool | lock_and_reload (MYSQL_THD thd) |
bool | refresh_rules_table () |
static string | shorten_query (MYSQL_LEX_STRING query) |
static void | log_nonrewritten_query (MYSQL_THD thd, const uchar *digest_buf, Rewrite_result result) |
Writes a message in the log saying that the query did not get rewritten. More... | |
static bool | allow_rewrite () |
Check if rewrite should be skipped for this query. More... | |
Status variables for the plugin. | |
#define | PLUGIN_NAME "Rewriter" |
static std::atomic< long long > | status_var_number_rewritten_queries |
Number of queries that were rewritten. More... | |
static bool | status_var_reload_error |
Indicates if there was an error during the last reload. More... | |
static unsigned | status_var_number_loaded_rules |
Number of rules loaded in the in-memory table. More... | |
static long long | status_var_number_reloads |
Number of times the in-memory table was reloaded. More... | |
static SHOW_VAR | rewriter_plugin_status_vars [] |
Plugin declaration. | |
static struct st_mysql_audit | rewrite_query_descriptor |
mysql_declare_plugin_end | |
static int | rewrite_query_notify (MYSQL_THD thd, mysql_event_class_t event_class, const void *event) |
Entry point to the plugin. More... | |
static int | rewriter_plugin_init (MYSQL_PLUGIN plugin_ref) |
static int | rewriter_plugin_deinit (void *) |
mysql_declare_plugin (audit_log) | |
The plugin declaration part of the Rewriter plugin.
This file (alone) creates a post-parse query rewrite plugin. All of the functionality is brought in by including rewriter.h.
#define ACQUIRE_SERVICE | ( | name | ) |
#define PLUGIN_NAME "Rewriter" |
#define RELEASE_SERVICE | ( | service | ) |
T * acquire_service | ( | const char * | service_name | ) |
|
static |
Check if rewrite should be skipped for this query.
Skip rewrites for
true | if query should not skip rewrite |
false | if query should skip rewrite |
MYSQL_PLUGIN get_rewriter_plugin_info | ( | ) |
|
static |
|
static |
|
static |
Writes a message in the log saying that the query did not get rewritten.
(Only if verbose level is high enough.)
mysql_declare_plugin | ( | audit_log | ) |
|
static |
|
static |
|
static |
bool refresh_rules_table | ( | ) |
void release_service | ( | T * | service | ) |
|
static |
Reloads the rules into the in-memory table.
This function assumes that the appropriate lock is already taken and doesn't concern itself with locks.
|
static |
Entry point to the plugin.
The server calls this function after each parsed query when the plugin is active. The function extracts the digest of the query. If the digest matches an existing rewrite rule, it is executed.
|
static |
|
static |
|
static |
Updater function for the status variable ..._enabled.
|
static |
Updater function for the status variable ..._enabled_for_threads_without_privilege_checks.
Updater function for the status variable ..._verbose.
|
static |
const mysql_service_dynamic_privilege_register_t* dynamic_privilege_register = nullptr |
const mysql_service_global_grants_check_t* global_grants_check = nullptr |
PSI_rwlock_key key_rwlock_LOCK_table_ |
|
static |
const mysql_service_log_builtins_t* log_bi = nullptr |
accessor built-ins
accessor built-ins
const mysql_service_log_builtins_string_t* log_bs = nullptr |
string built-ins
|
static |
const mysql_service_mysql_current_thread_reader_t* mysql_current_thread_reader |
mysql_declare_plugin_end |
const mysql_service_mysql_thd_attributes_t* mysql_thd_attributes = nullptr |
|
static |
We handle recovery in a kind of lazy manner.
If the server was shut down with this plugin installed, we should ideally load the rules into memory right on the spot in rewriter_plugin_init() as the server comes to. But this plugin is relying on transactions to do that and unfortunately the transaction log is not set up at this point. (It's set up about 200 lines further down in init_server_components() at the time of writing.) That's why we simply set this flag in rewriter_plugin_init() and reload in rewrite_query_post_parse() if it is set.
|
static |
|
static |
|
static |
|
static |
|
static |
SYS_VAR* rewriter_plugin_sys_vars[] |
|
static |
Number of rules loaded in the in-memory table.
|
static |
Number of times the in-memory table was reloaded.
|
static |
Number of queries that were rewritten.
|
static |
Indicates if there was an error during the last reload.
|
static |
Enabled.
|
static |
Enabled for threads with privilege checks disabled.
|
static |
Verbose level.