mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
Implementation of Multi-source replication (MDEV:253)
Documentation of the feature can be found at: http://kb.askmonty.org/en/multi-source-replication/ This code is based on code from Taobao, developed by Plinux BUILD/SETUP.sh: Added -Wno-invalid-offsetof to get rid of warning of offsetof() on C++ class (safe in the contex we use it) client/mysqltest.cc: Added support for error names starting with 'W' Added connection_name support to --sync_with_master cmake/maintainer.cmake: Added -Wno-invalid-offsetof to get rid of warning of offsetof() on C++ class (safe in the contex we use it) mysql-test/r/mysqltest.result: Updated results mysql-test/r/parser.result: Updated results mysql-test/suite/multi_source/my.cnf: Setup of multi-master tests mysql-test/suite/multi_source/simple.result: Simple basic test of multi-source functionality mysql-test/suite/multi_source/simple.test: Simple basic test of multi-source functionality mysql-test/suite/multi_source/syntax.result: Test of multi-source syntax mysql-test/suite/multi_source/syntax.test: Test of multi-source syntax mysql-test/suite/rpl/r/rpl_rotate_logs.result: Updated results because of new error messages mysql-test/t/parser.test: Updated test as master_pos_wait() now takes more arguments than before sql/event_scheduler.cc: No reason to initialize slave_thread (it's guaranteed to be zero here) sql/item_create.cc: Added connection_name argument to master_pos_wait() Simplified code sql/item_func.cc: Added connection_name argument to master_pos_wait() sql/item_func.h: Added connection_name argument to master_pos_wait() sql/log.cc: Added tag "Master 'connection_name'" to slave errors that has a connection name. sql/mysqld.cc: Added variable mysqld_server_initialized so that other functions can test if server is fully initialized. Free all slave data in one place (fewer ifdef's) Removed not needed call to close_active_mi() Initialize slaves() later in startup to ensure that everthing is really initialized when slaves start. Made status variable slave_running multi-source safe sql/mysqld.h: Added mysqld_server_initialized sql/rpl_mi.cc: Store connection name and cmp_connection_name (only used for show full slave status) in Master_info Added code for Master_info_index, which handles storage of multi-master information Don't write the empty "" connection_name to multi-master.info file. This is handled by the original code. sql/rpl_mi.h: Added connection_name and Master_info_index sql/rpl_rli.cc: Added connection_name to relay log files. sql/rpl_rli.h: Fixed type of slave_skip_counter as we now access it directly in sys_vars.cc, so it must be uint sql/share/errmsg-utf8.txt: Added new error messages needed for multi-source Added multi-source name to error ER_MASTER_INFO and WARN_NO_MASTER_INFO sql/slave.cc: Moved things a bit around to make it easier to handle error conditions. Create a global master_info_index and add the "" connection to it Ensure that new Master_info doesn't fail. Don't call terminate_slave_threads(active_mi..) on end_slave() as this is now done automaticly when deleting master_info_index. Delete not needed function close_active_mi(). One can achive same thing by calling end_slave(). Added support for SHOW FULL SLAVE STATUS (show status for all master connections with connection_name as first column) sql/slave.h: Added new prototypes sql/sql_base.cc: More DBUG_PRINT sql/sql_class.cc: Reset thd->connection_name and thd-->default_master_connection sql/sql_class.h: Added thd->connection_name and thd-->default_master_connection Added slave_skip_count to variables to make changing the @@sql_slave_skip_count variable thread safe sql/sql_const.h: Added MAX_CONNECTION_NAME sql/sql_lex.cc: Reset 'lex->verbose' (to simplify some sql_yacc.yy code) sql/sql_lex.h: Added connection_name sql/sql_parse.cc: Added support for connection_name to all SLAVE commands. - Instead of using active_mi, we now get the current Master_info from master_info_index. - Create new replication threads with CHANGE MASTER - Added support for show_all_master_info() sql/sql_reload.cc: Made reset/full slave use master_info_index->get_master_info() instead of active_mi. If one uses 'RESET SLAVE "connection_name" all' the connection is removed from master_info_index. sql/sql_repl.cc: sql_slave_skip_counter is moved to thd->variables to make it thread safe and fix some bugs with it Add connection name to relay log files. Added connection name to errors. Added some logging for multi-master if log_warnings > 1 stop_slave(): - Don't check if thd is set. It's guaranteed to always be set. change_master(): - Check for duplicate connection names in change_master() - Check for wrong arguments first in file (to simplify error handling) - Register new connections in master_info_index sql/sql_yacc.yy: Added optional connection_name to a all relevant master/slave commands sql/strfunc.cc: my_global.h shoud always be included first. sql/sys_vars.cc: Added variable default_master_connection Made variable sql_slave_skip_counter multi-source safe sql/sys_vars.h: Added Sys_var_session_lexstring (needed for default_master_connection) Added Sys_var_multi_source_uint (needed for sql_slave_skip_counter).
This commit is contained in:
127
sql/sql_repl.cc
127
sql/sql_repl.cc
@ -34,14 +34,6 @@ my_bool opt_sporadic_binlog_dump_fail = 0;
|
||||
static int binlog_dump_count = 0;
|
||||
#endif
|
||||
|
||||
/**
|
||||
a copy of active_mi->rli->slave_skip_counter, for showing in SHOW VARIABLES,
|
||||
INFORMATION_SCHEMA.GLOBAL_VARIABLES and @@sql_slave_skip_counter without
|
||||
taking all the mutexes needed to access active_mi->rli->slave_skip_counter
|
||||
properly.
|
||||
*/
|
||||
uint sql_slave_skip_counter;
|
||||
|
||||
extern TYPELIB binlog_checksum_typelib;
|
||||
|
||||
/*
|
||||
@ -1310,8 +1302,17 @@ int start_slave(THD* thd , Master_info* mi, bool net_report)
|
||||
{
|
||||
int slave_errno= 0;
|
||||
int thread_mask;
|
||||
char master_info_file_tmp[FN_REFLEN];
|
||||
char relay_log_info_file_tmp[FN_REFLEN];
|
||||
DBUG_ENTER("start_slave");
|
||||
|
||||
create_signed_file_name(master_info_file_tmp,
|
||||
sizeof(master_info_file_tmp),
|
||||
master_info_file, '.', &mi->connection_name);
|
||||
create_signed_file_name(relay_log_info_file_tmp,
|
||||
sizeof(relay_log_info_file_tmp),
|
||||
relay_log_info_file, '.', &mi->connection_name);
|
||||
|
||||
if (check_access(thd, SUPER_ACL, any_db, NULL, NULL, 0, 0))
|
||||
DBUG_RETURN(1);
|
||||
lock_slave_threads(mi); // this allows us to cleanly read slave_running
|
||||
@ -1327,7 +1328,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report)
|
||||
thread_mask&= thd->lex->slave_thd_opt;
|
||||
if (thread_mask) //some threads are stopped, start them
|
||||
{
|
||||
if (init_master_info(mi,master_info_file,relay_log_info_file, 0,
|
||||
if (init_master_info(mi,master_info_file_tmp,relay_log_info_file_tmp, 0,
|
||||
thread_mask))
|
||||
slave_errno=ER_MASTER_INFO;
|
||||
else if (server_id_supplied && *mi->host)
|
||||
@ -1401,10 +1402,11 @@ int start_slave(THD* thd , Master_info* mi, bool net_report)
|
||||
|
||||
if (!slave_errno)
|
||||
slave_errno = start_slave_threads(0 /*no mutex */,
|
||||
1 /* wait for start */,
|
||||
mi,
|
||||
master_info_file,relay_log_info_file,
|
||||
thread_mask);
|
||||
1 /* wait for start */,
|
||||
mi,
|
||||
master_info_file_tmp,
|
||||
relay_log_info_file_tmp,
|
||||
thread_mask);
|
||||
}
|
||||
else
|
||||
slave_errno = ER_BAD_SLAVE;
|
||||
@ -1421,7 +1423,9 @@ int start_slave(THD* thd , Master_info* mi, bool net_report)
|
||||
if (slave_errno)
|
||||
{
|
||||
if (net_report)
|
||||
my_message(slave_errno, ER(slave_errno), MYF(0));
|
||||
my_error(slave_errno, MYF(0),
|
||||
(int) mi->connection_name.length,
|
||||
mi->connection_name.str);
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
else if (net_report)
|
||||
@ -1446,11 +1450,9 @@ int start_slave(THD* thd , Master_info* mi, bool net_report)
|
||||
*/
|
||||
int stop_slave(THD* thd, Master_info* mi, bool net_report )
|
||||
{
|
||||
DBUG_ENTER("stop_slave");
|
||||
|
||||
int slave_errno;
|
||||
if (!thd)
|
||||
thd = current_thd;
|
||||
DBUG_ENTER("stop_slave");
|
||||
DBUG_PRINT("enter",("Connection: %s", mi->connection_name.str));
|
||||
|
||||
if (check_access(thd, SUPER_ACL, any_db, NULL, NULL, 0, 0))
|
||||
DBUG_RETURN(1);
|
||||
@ -1514,6 +1516,8 @@ int reset_slave(THD *thd, Master_info* mi)
|
||||
int thread_mask= 0, error= 0;
|
||||
uint sql_errno=ER_UNKNOWN_ERROR;
|
||||
const char* errmsg= "Unknown error occured while reseting slave";
|
||||
char master_info_file_tmp[FN_REFLEN];
|
||||
char relay_log_info_file_tmp[FN_REFLEN];
|
||||
DBUG_ENTER("reset_slave");
|
||||
|
||||
lock_slave_threads(mi);
|
||||
@ -1549,22 +1553,35 @@ int reset_slave(THD *thd, Master_info* mi)
|
||||
|
||||
// close master_info_file, relay_log_info_file, set mi->inited=rli->inited=0
|
||||
end_master_info(mi);
|
||||
|
||||
// and delete these two files
|
||||
fn_format(fname, master_info_file, mysql_data_home, "", 4+32);
|
||||
create_signed_file_name(master_info_file_tmp,
|
||||
sizeof(master_info_file_tmp),
|
||||
master_info_file, '.', &mi->connection_name);
|
||||
create_signed_file_name(relay_log_info_file_tmp,
|
||||
sizeof(relay_log_info_file_tmp),
|
||||
relay_log_info_file, '.', &mi->connection_name);
|
||||
|
||||
fn_format(fname, master_info_file_tmp, mysql_data_home, "", 4+32);
|
||||
if (mysql_file_stat(key_file_master_info, fname, &stat_area, MYF(0)) &&
|
||||
mysql_file_delete(key_file_master_info, fname, MYF(MY_WME)))
|
||||
{
|
||||
error=1;
|
||||
goto err;
|
||||
}
|
||||
else if (global_system_variables.log_warnings > 1)
|
||||
sql_print_information("Deleted Master_info file '%s'.", fname);
|
||||
|
||||
// delete relay_log_info_file
|
||||
fn_format(fname, relay_log_info_file, mysql_data_home, "", 4+32);
|
||||
fn_format(fname, relay_log_info_file_tmp, mysql_data_home, "", 4+32);
|
||||
if (mysql_file_stat(key_file_relay_log_info, fname, &stat_area, MYF(0)) &&
|
||||
mysql_file_delete(key_file_relay_log_info, fname, MYF(MY_WME)))
|
||||
{
|
||||
error=1;
|
||||
goto err;
|
||||
}
|
||||
else if (global_system_variables.log_warnings > 1)
|
||||
sql_print_information("Deleted Master_info file '%s'.", fname);
|
||||
|
||||
RUN_HOOK(binlog_relay_io, after_reset_slave, (thd, mi));
|
||||
err:
|
||||
@ -1644,12 +1661,36 @@ bool change_master(THD* thd, Master_info* mi)
|
||||
char saved_host[HOSTNAME_LENGTH + 1];
|
||||
uint saved_port;
|
||||
char saved_log_name[FN_REFLEN];
|
||||
char master_info_file_tmp[FN_REFLEN];
|
||||
char relay_log_info_file_tmp[FN_REFLEN];
|
||||
my_off_t saved_log_pos;
|
||||
LEX_MASTER_INFO* lex_mi= &thd->lex->mi;
|
||||
DBUG_ENTER("change_master");
|
||||
|
||||
/*
|
||||
We need to check if there is an empty master_host. Otherwise
|
||||
change master succeeds, a master.info file is created containing
|
||||
empty master_host string and when issuing: start slave; an error
|
||||
is thrown stating that the server is not configured as slave.
|
||||
(See BUG#28796).
|
||||
*/
|
||||
if (lex_mi->host && !*lex_mi->host)
|
||||
{
|
||||
my_error(ER_WRONG_ARGUMENTS, MYF(0), "MASTER_HOST");
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
if (master_info_index->check_duplicate_master_info(&lex_mi->connection_name,
|
||||
lex_mi->host,
|
||||
lex_mi->port))
|
||||
{
|
||||
my_error(ER_MASTER_INFO, MYF(0),
|
||||
(int) lex_mi->connection_name.length,
|
||||
lex_mi->connection_name.str);
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
lock_slave_threads(mi);
|
||||
init_thread_mask(&thread_mask,mi,0 /*not inverse*/);
|
||||
LEX_MASTER_INFO* lex_mi= &thd->lex->mi;
|
||||
if (thread_mask) // We refuse if any slave thread is running
|
||||
{
|
||||
my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
|
||||
@ -1658,24 +1699,40 @@ bool change_master(THD* thd, Master_info* mi)
|
||||
}
|
||||
|
||||
thd_proc_info(thd, "Changing master");
|
||||
/*
|
||||
We need to check if there is an empty master_host. Otherwise
|
||||
change master succeeds, a master.info file is created containing
|
||||
empty master_host string and when issuing: start slave; an error
|
||||
is thrown stating that the server is not configured as slave.
|
||||
(See BUG#28796).
|
||||
*/
|
||||
if(lex_mi->host && !*lex_mi->host)
|
||||
|
||||
create_signed_file_name(master_info_file_tmp,
|
||||
sizeof(master_info_file_tmp),
|
||||
master_info_file, '.', &mi->connection_name);
|
||||
create_signed_file_name(relay_log_info_file_tmp,
|
||||
sizeof(relay_log_info_file_tmp),
|
||||
relay_log_info_file, '.', &mi->connection_name);
|
||||
|
||||
/* if new Master_info doesn't exists, add it */
|
||||
if (!master_info_index->get_master_info(&mi->connection_name,
|
||||
MYSQL_ERROR::WARN_LEVEL_NOTE))
|
||||
{
|
||||
my_error(ER_WRONG_ARGUMENTS, MYF(0), "MASTER_HOST");
|
||||
unlock_slave_threads(mi);
|
||||
DBUG_RETURN(TRUE);
|
||||
if (master_info_index->add_master_info(mi, TRUE))
|
||||
{
|
||||
my_error(ER_MASTER_INFO, MYF(0),
|
||||
(int) lex_mi->connection_name.length,
|
||||
lex_mi->connection_name.str);
|
||||
ret= TRUE;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
// TODO: see if needs re-write
|
||||
if (init_master_info(mi, master_info_file, relay_log_info_file, 0,
|
||||
if (global_system_variables.log_warnings > 1)
|
||||
sql_print_information("Master: '%.*s' Master_info_file: '%s' "
|
||||
"Relay_info_file: '%s'",
|
||||
(int) mi->connection_name.length,
|
||||
mi->connection_name.str,
|
||||
master_info_file_tmp, relay_log_info_file_tmp);
|
||||
|
||||
if (init_master_info(mi, master_info_file_tmp, relay_log_info_file_tmp, 0,
|
||||
thread_mask))
|
||||
{
|
||||
my_message(ER_MASTER_INFO, ER(ER_MASTER_INFO), MYF(0));
|
||||
my_error(ER_MASTER_INFO, MYF(0),
|
||||
(int) lex_mi->connection_name.length,
|
||||
lex_mi->connection_name.str);
|
||||
ret= TRUE;
|
||||
goto err;
|
||||
}
|
||||
|
Reference in New Issue
Block a user