MySQL 9.0.0
Source Code Documentation
|
#include "sql/rpl_handler.h"
#include <string.h>
#include <memory>
#include <new>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lex_string.h"
#include "map_helpers.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_io.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/my_loglevel.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include "mysqld_error.h"
#include "prealloced_array.h"
#include "sql/current_thd.h"
#include "sql/debug_sync.h"
#include "sql/handler.h"
#include "sql/item_func.h"
#include "sql/key.h"
#include "sql/log.h"
#include "sql/mysqld.h"
#include "sql/psi_memory_key.h"
#include "sql/raii/sentry.h"
#include "sql/replication.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_mi.h"
#include "sql/set_var.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_lex.h"
#include "sql/sql_parse.h"
#include "sql/sql_plugin.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thr_malloc.h"
#include "sql/transaction_info.h"
#include "sql_string.h"
Classes | |
struct | Trans_binlog_info |
Macros | |
#define | FOREACH_OBSERVER(r, f, args) |
#define | FOREACH_OBSERVER_ERROR_OUT(r, f, args, out) |
Typedefs | |
typedef struct Trans_binlog_info | Trans_binlog_info |
Functions | |
int | get_user_var_int (const char *name, long long int *value, int *null_value) |
Get the value of user variable as an integer. More... | |
int | get_user_var_real (const char *name, double *value, int *null_value) |
Get the value of user variable as a double precision float number. More... | |
int | get_user_var_str (const char *name, char *value, size_t len, unsigned int precision, int *null_value) |
Get the value of user variable as a string. More... | |
int | delegates_init () |
void | delegates_shutdown () |
Verify that the replication plugins are ready and OK to be unloaded. More... | |
void | delegates_destroy () |
static void | delegates_update_plugin_ref_count () |
void | delegates_acquire_locks () |
Invokes write_lock() for all the observer delegate objects. More... | |
void | delegates_release_locks () |
Releases locks for all the observer delegate objects. More... | |
void | delegates_update_lock_type () |
Toggles the type of lock between a classical read-write lock and a shared-exclusive spin-lock. More... | |
static bool | se_before_commit (THD *, plugin_ref plugin, void *arg) |
bool | has_cascade_foreign_key (TABLE *table) |
Helper method to check if the given table has 'CASCADE' foreign key or not. More... | |
void | prepare_table_info (THD *thd, Trans_table_info *&table_info_list, uint &number_of_tables) |
Helper method to create table information for the hook call. More... | |
static void | prepare_transaction_context (THD *thd, Trans_context_info &ctx_info) |
Helper that gathers all table runtime information. More... | |
static bool | se_before_rollback (THD *, plugin_ref plugin, void *arg) |
static bool | se_after_commit (THD *, plugin_ref plugin, void *arg) |
int | register_trans_observer (Trans_observer *observer, void *p) |
Register a transaction observer. More... | |
int | unregister_trans_observer (Trans_observer *observer, void *) |
Unregister a transaction observer. More... | |
int | register_binlog_storage_observer (Binlog_storage_observer *observer, void *p) |
Register a binlog storage observer. More... | |
int | unregister_binlog_storage_observer (Binlog_storage_observer *observer, void *) |
Unregister a binlog storage observer. More... | |
int | register_server_state_observer (Server_state_observer *observer, void *plugin_var) |
Register a server state observer. More... | |
int | unregister_server_state_observer (Server_state_observer *observer, void *) |
Unregister a server state observer. More... | |
int | register_binlog_transmit_observer (Binlog_transmit_observer *observer, void *p) |
Register a binlog transmit observer. More... | |
int | unregister_binlog_transmit_observer (Binlog_transmit_observer *observer, void *) |
Unregister a binlog transmit observer. More... | |
int | register_binlog_relay_io_observer (Binlog_relay_IO_observer *observer, void *p) |
Register a binlog relay IO (slave IO thread) observer. More... | |
int | unregister_binlog_relay_io_observer (Binlog_relay_IO_observer *observer, void *) |
Unregister a binlog relay IO (slave IO thread) observer. More... | |
static bool | is_show_status (enum_sql_command sql_command) |
int | launch_hook_trans_begin (THD *thd, Table_ref *all_tables) |
Variables | |
Trans_delegate * | transaction_delegate |
Binlog_storage_delegate * | binlog_storage_delegate |
Server_state_delegate * | server_state_delegate |
Binlog_transmit_delegate * | binlog_transmit_delegate |
Binlog_relay_IO_delegate * | binlog_relay_io_delegate |
bool | opt_replication_optimize_for_static_plugin_config {false} |
Variable to keep the value set for the replication_optimize_for_static_plugin_config global. More... | |
std::atomic< bool > | opt_replication_sender_observe_commit_only {false} |
Variable to keep the value set for the replication_sender_observe_commit_only global. More... | |
#define FOREACH_OBSERVER | ( | r, | |
f, | |||
args | |||
) |
#define FOREACH_OBSERVER_ERROR_OUT | ( | r, | |
f, | |||
args, | |||
out | |||
) |
typedef struct Trans_binlog_info Trans_binlog_info |
void delegates_acquire_locks | ( | ) |
Invokes write_lock()
for all the observer delegate objects.
void delegates_destroy | ( | ) |
int delegates_init | ( | ) |
void delegates_release_locks | ( | ) |
Releases locks for all the observer delegate objects.
void delegates_shutdown | ( | ) |
Verify that the replication plugins are ready and OK to be unloaded.
void delegates_update_lock_type | ( | ) |
Toggles the type of lock between a classical read-write lock and a shared-exclusive spin-lock.
|
static |
int get_user_var_int | ( | const char * | name, |
long long int * | value, | ||
int * | null_value | ||
) |
Get the value of user variable as an integer.
This function will return the value of variable name as an integer. If the original value of the variable is not an integer, the value will be converted into an integer.
name | user variable name |
value | pointer to return the value |
null_value | if not NULL, the function will set it to true if the value of variable is null, set to false if not |
0 | Success |
1 | Variable not found |
int get_user_var_real | ( | const char * | name, |
double * | value, | ||
int * | null_value | ||
) |
Get the value of user variable as a double precision float number.
This function will return the value of variable name as real number. If the original value of the variable is not a real number, the value will be converted into a real number.
name | user variable name |
value | pointer to return the value |
null_value | if not NULL, the function will set it to true if the value of variable is null, set to false if not |
0 | Success |
1 | Variable not found |
int get_user_var_str | ( | const char * | name, |
char * | value, | ||
size_t | len, | ||
unsigned int | precision, | ||
int * | null_value | ||
) |
Get the value of user variable as a string.
This function will return the value of variable name as string. If the original value of the variable is not a string, the value will be converted into a string.
name | user variable name |
value | pointer to the value buffer |
len | length of the value buffer |
precision | precision of the value if it is a float number |
null_value | if not NULL, the function will set it to true if the value of variable is null, set to false if not |
0 | Success |
1 | Variable not found |
bool has_cascade_foreign_key | ( | TABLE * | table | ) |
Helper method to check if the given table has 'CASCADE' foreign key or not.
[in] | table | Table object that needs to be verified. |
|
static |
void prepare_table_info | ( | THD * | thd, |
Trans_table_info *& | table_info_list, | ||
uint & | number_of_tables | ||
) |
Helper method to create table information for the hook call.
|
static |
Helper that gathers all table runtime information.
[in] | thd | the current execution thread |
[out] | ctx_info | Trans_context_info in which the result is stored. |
int register_binlog_relay_io_observer | ( | Binlog_relay_IO_observer * | observer, |
void * | p | ||
) |
Register a binlog relay IO (slave IO thread) observer.
observer | The binlog relay IO observer to register |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer already exists |
int register_binlog_storage_observer | ( | Binlog_storage_observer * | observer, |
void * | p | ||
) |
Register a binlog storage observer.
observer | The binlog storage observer to register |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer already exists |
int register_binlog_transmit_observer | ( | Binlog_transmit_observer * | observer, |
void * | p | ||
) |
Register a binlog transmit observer.
observer | The binlog transmit observer to register |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer already exists |
int register_server_state_observer | ( | Server_state_observer * | observer, |
void * | p | ||
) |
Register a server state observer.
observer | The server state observer to register |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer already exists |
int register_trans_observer | ( | Trans_observer * | observer, |
void * | p | ||
) |
Register a transaction observer.
observer | The transaction observer to register |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer already exists |
|
static |
|
static |
|
static |
int unregister_binlog_relay_io_observer | ( | Binlog_relay_IO_observer * | observer, |
void * | p | ||
) |
Unregister a binlog relay IO (slave IO thread) observer.
observer | The binlog relay IO observer to unregister |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer not exists |
int unregister_binlog_storage_observer | ( | Binlog_storage_observer * | observer, |
void * | p | ||
) |
Unregister a binlog storage observer.
observer | The binlog storage observer to unregister |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer not exists |
int unregister_binlog_transmit_observer | ( | Binlog_transmit_observer * | observer, |
void * | p | ||
) |
Unregister a binlog transmit observer.
observer | The binlog transmit observer to unregister |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer not exists |
int unregister_server_state_observer | ( | Server_state_observer * | observer, |
void * | p | ||
) |
Unregister a server state observer.
observer | The server state observer to unregister |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer not exists |
int unregister_trans_observer | ( | Trans_observer * | observer, |
void * | p | ||
) |
Unregister a transaction observer.
observer | The transaction observer to unregister |
p | pointer to the internal plugin structure |
0 | Success |
1 | Observer not exists |
Binlog_relay_IO_delegate* binlog_relay_io_delegate |
Binlog_storage_delegate* binlog_storage_delegate |
Binlog_transmit_delegate* binlog_transmit_delegate |
bool opt_replication_optimize_for_static_plugin_config {false} |
Variable to keep the value set for the replication_optimize_for_static_plugin_config
global.
When this global variable value is set to 1
, we prevent all plugins that register replication observers to be unloaded until the variable is set to 0
, again. While the value of the variable is 1
, we are also exchanging the Delegate
class read-write lock by an atomic-based shared spin-lock.
This behaviour is useful for increasing the throughtput of the master when a large number of slaves is connected, by preventing the acquisition of the LOCK_plugin
mutex and using a more read-friendly lock in the Delegate
class, when invoking the observer's hooks.
Note that a large number of slaves means a large number of dump threads, which means a large number of threads calling the registered observers hooks.
If UNINSTALL
is executed on a replication observer plugin while the variable is set to 1
, the unload of the plugin will be deferred until the variable's value is set to 0
.
std::atomic<bool> opt_replication_sender_observe_commit_only {false} |
Variable to keep the value set for the replication_sender_observe_commit_only
global.
When this global variable is set to 1
, only the replication observer's commit hook will be called, every other registered hook invocation is skipped.
Server_state_delegate* server_state_delegate |
Trans_delegate* transaction_delegate |