MySQL 8.4.3
Source Code Documentation
rpl_handler.cc File Reference
#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_delegatetransaction_delegate
 
Binlog_storage_delegatebinlog_storage_delegate
 
Server_state_delegateserver_state_delegate
 
Binlog_transmit_delegatebinlog_transmit_delegate
 
Binlog_relay_IO_delegatebinlog_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...
 

Macro Definition Documentation

◆ FOREACH_OBSERVER

#define FOREACH_OBSERVER (   r,
  f,
  args 
)

◆ FOREACH_OBSERVER_ERROR_OUT

#define FOREACH_OBSERVER_ERROR_OUT (   r,
  f,
  args,
  out 
)

Typedef Documentation

◆ Trans_binlog_info

Function Documentation

◆ delegates_acquire_locks()

void delegates_acquire_locks ( )

Invokes write_lock() for all the observer delegate objects.

◆ delegates_destroy()

void delegates_destroy ( )

◆ delegates_init()

int delegates_init ( )

◆ delegates_release_locks()

void delegates_release_locks ( )

Releases locks for all the observer delegate objects.

◆ delegates_shutdown()

void delegates_shutdown ( )

Verify that the replication plugins are ready and OK to be unloaded.

◆ delegates_update_lock_type()

void delegates_update_lock_type ( )

Toggles the type of lock between a classical read-write lock and a shared-exclusive spin-lock.

◆ delegates_update_plugin_ref_count()

static void delegates_update_plugin_ref_count ( )
static

◆ get_user_var_int()

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.

Parameters
nameuser variable name
valuepointer to return the value
null_valueif not NULL, the function will set it to true if the value of variable is null, set to false if not
Return values
0Success
1Variable not found

◆ get_user_var_real()

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.

Parameters
nameuser variable name
valuepointer to return the value
null_valueif not NULL, the function will set it to true if the value of variable is null, set to false if not
Return values
0Success
1Variable not found

◆ get_user_var_str()

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.

Parameters
nameuser variable name
valuepointer to the value buffer
lenlength of the value buffer
precisionprecision of the value if it is a float number
null_valueif not NULL, the function will set it to true if the value of variable is null, set to false if not
Return values
0Success
1Variable not found

◆ has_cascade_foreign_key()

bool has_cascade_foreign_key ( TABLE table)

Helper method to check if the given table has 'CASCADE' foreign key or not.

Parameters
[in]tableTable object that needs to be verified.
Returns
bool true If the table has 'CASCADE' foreign key. false If the table does not have 'CASCADE' foreign key.

◆ is_show_status()

static bool is_show_status ( enum_sql_command  sql_command)
static

◆ launch_hook_trans_begin()

int launch_hook_trans_begin ( THD thd,
Table_ref all_tables 
)

◆ prepare_table_info()

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.

◆ prepare_transaction_context()

static void prepare_transaction_context ( THD thd,
Trans_context_info ctx_info 
)
static

Helper that gathers all table runtime information.

Parameters
[in]thdthe current execution thread
[out]ctx_infoTrans_context_info in which the result is stored.

◆ register_binlog_relay_io_observer()

int register_binlog_relay_io_observer ( Binlog_relay_IO_observer observer,
void *  p 
)

Register a binlog relay IO (slave IO thread) observer.

Parameters
observerThe binlog relay IO observer to register
ppointer to the internal plugin structure
Return values
0Success
1Observer already exists

◆ register_binlog_storage_observer()

int register_binlog_storage_observer ( Binlog_storage_observer observer,
void *  p 
)

Register a binlog storage observer.

Parameters
observerThe binlog storage observer to register
ppointer to the internal plugin structure
Return values
0Success
1Observer already exists

◆ register_binlog_transmit_observer()

int register_binlog_transmit_observer ( Binlog_transmit_observer observer,
void *  p 
)

Register a binlog transmit observer.

Parameters
observerThe binlog transmit observer to register
ppointer to the internal plugin structure
Return values
0Success
1Observer already exists

◆ register_server_state_observer()

int register_server_state_observer ( Server_state_observer observer,
void *  p 
)

Register a server state observer.

Parameters
observerThe server state observer to register
ppointer to the internal plugin structure
Return values
0Success
1Observer already exists

◆ register_trans_observer()

int register_trans_observer ( Trans_observer observer,
void *  p 
)

Register a transaction observer.

Parameters
observerThe transaction observer to register
ppointer to the internal plugin structure
Return values
0Success
1Observer already exists

◆ se_after_commit()

static bool se_after_commit ( THD ,
plugin_ref  plugin,
void *  arg 
)
static

◆ se_before_commit()

static bool se_before_commit ( THD ,
plugin_ref  plugin,
void *  arg 
)
static

◆ se_before_rollback()

static bool se_before_rollback ( THD ,
plugin_ref  plugin,
void *  arg 
)
static

◆ unregister_binlog_relay_io_observer()

int unregister_binlog_relay_io_observer ( Binlog_relay_IO_observer observer,
void *  p 
)

Unregister a binlog relay IO (slave IO thread) observer.

Parameters
observerThe binlog relay IO observer to unregister
ppointer to the internal plugin structure
Return values
0Success
1Observer not exists

◆ unregister_binlog_storage_observer()

int unregister_binlog_storage_observer ( Binlog_storage_observer observer,
void *  p 
)

Unregister a binlog storage observer.

Parameters
observerThe binlog storage observer to unregister
ppointer to the internal plugin structure
Return values
0Success
1Observer not exists

◆ unregister_binlog_transmit_observer()

int unregister_binlog_transmit_observer ( Binlog_transmit_observer observer,
void *  p 
)

Unregister a binlog transmit observer.

Parameters
observerThe binlog transmit observer to unregister
ppointer to the internal plugin structure
Return values
0Success
1Observer not exists

◆ unregister_server_state_observer()

int unregister_server_state_observer ( Server_state_observer observer,
void *  p 
)

Unregister a server state observer.

Parameters
observerThe server state observer to unregister
ppointer to the internal plugin structure
Return values
0Success
1Observer not exists

◆ unregister_trans_observer()

int unregister_trans_observer ( Trans_observer observer,
void *  p 
)

Unregister a transaction observer.

Parameters
observerThe transaction observer to unregister
ppointer to the internal plugin structure
Return values
0Success
1Observer not exists

Variable Documentation

◆ binlog_relay_io_delegate

Binlog_relay_IO_delegate* binlog_relay_io_delegate

◆ binlog_storage_delegate

Binlog_storage_delegate* binlog_storage_delegate

◆ binlog_transmit_delegate

Binlog_transmit_delegate* binlog_transmit_delegate

◆ opt_replication_optimize_for_static_plugin_config

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.

◆ opt_replication_sender_observe_commit_only

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* server_state_delegate

◆ transaction_delegate

Trans_delegate* transaction_delegate