From e590f89114bd205e30488cb8b1433f645babc170 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 Mar 2013 12:16:04 +0100 Subject: [PATCH] MDEV-26: Global transaction ID. Fix MDEV-4278: Slave does not check that master understands GTID. Now the slave will abort with a suitable error if an attempt is made to connect with GTID to a master that does not support GTID. --- .../suite/rpl/r/rpl_gtid_errorhandling.result | 12 +++++++++ .../suite/rpl/t/rpl_gtid_errorhandling.test | 27 +++++++++++++++++++ sql/item_func.cc | 8 ++++++ sql/slave.cc | 21 +++++++++++++++ sql/sql_repl.cc | 1 + 5 files changed, 69 insertions(+) diff --git a/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result b/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result index 8785b7a1684..db6e2672a18 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result @@ -73,5 +73,17 @@ a 3 4 5 +*** MDEV-4278: Slave does not detect that master is not GTID-aware *** +include/stop_slave.inc +SET @old_dbug= @@global.DEBUG_DBUG; +SET GLOBAL debug_dbug="+d,simulate_non_gtid_aware_master"; +START SLAVE; +include/wait_for_slave_io_error.inc [errno=1233] +SET GLOBAL debug_dbug= @old_dbug; +INSERT INTO t1 VALUES (6); +START SLAVE; +SET sql_log_bin=0; +CALL mtr.add_suppression("The slave I/O thread stops because master does not support MariaDB global transaction id"); +SET sql_log_bin=1; DROP TABLE t1; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test b/mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test index 2f10b9ee284..ada6fa22490 100644 --- a/mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test +++ b/mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test @@ -107,6 +107,33 @@ INSERT INTO t1 VALUES (5); SELECT * FROM t1 ORDER BY a; +--echo *** MDEV-4278: Slave does not detect that master is not GTID-aware *** + +--connection slave +--source include/stop_slave.inc + +--connection master +SET @old_dbug= @@global.DEBUG_DBUG; +SET GLOBAL debug_dbug="+d,simulate_non_gtid_aware_master"; + +--connection slave +START SLAVE; +--let $slave_io_errno= 1233 +--source include/wait_for_slave_io_error.inc + +--connection master +SET GLOBAL debug_dbug= @old_dbug; +INSERT INTO t1 VALUES (6); +--save_master_pos + +--connection slave +START SLAVE; +--sync_with_master +SET sql_log_bin=0; +CALL mtr.add_suppression("The slave I/O thread stops because master does not support MariaDB global transaction id"); +SET sql_log_bin=1; + + --connection master DROP TABLE t1; diff --git a/sql/item_func.cc b/sql/item_func.cc index 8b4e5542a1f..7fd3ba56f50 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5678,6 +5678,14 @@ longlong Item_func_get_system_var::val_int() { THD *thd= current_thd; + DBUG_EXECUTE_IF("simulate_non_gtid_aware_master", + { + if (0 == strcmp("gtid_domain_id", var->name.str)) + { + my_error(ER_VAR_CANT_BE_READ, MYF(0), var->name.str); + return 0; + } + }); if (cache_present && thd->query_id == used_query_id) { if (cache_present & GET_SYS_VAR_CACHE_LONG) diff --git a/sql/slave.cc b/sql/slave.cc index efbd12e04d5..f373c8b2c45 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1823,6 +1823,27 @@ after_set_capability: rpl_gtid *binlog_gtid_list= NULL; uint32 num_binlog_gtids= 0; + /* + Read the master @@GLOBAL.gtid_domain_id variable. + This is mostly to check that master is GTID aware, but we could later + perhaps use it to check that different multi-source masters are correctly + configured with distinct domain_id. + */ + if (mysql_real_query(mysql, + STRING_WITH_LEN("SELECT @@GLOBAL.gtid_domain_id")) || + !(master_res= mysql_store_result(mysql)) || + !(master_row= mysql_fetch_row(master_res))) + { + err_code= mysql_errno(mysql); + errmsg= "The slave I/O thread stops because master does not support " + "MariaDB global transaction id. A fatal error is encountered when " + "it tries to SELECT @@GLOBAL.gtid_domain_id."; + sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql)); + goto err; + } + mysql_free_result(master_res); + master_res= NULL; + if (opt_bin_log) { int err= mysql_bin_log.get_most_recent_gtid_list(&binlog_gtid_list, diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 572b0e67ae3..5b52163eb0e 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1419,6 +1419,7 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, connect_gtid_state.length(0); using_gtid_state= get_slave_connect_state(thd, &connect_gtid_state); + DBUG_EXECUTE_IF("simulate_non_gtid_aware_master", using_gtid_state= false;); if (global_system_variables.log_warnings > 1) sql_print_information("Start binlog_dump to slave_server(%d), pos(%s, %lu)",