diff options
author | Brandon Nesterenko <brandon.nesterenko@mariadb.com> | 2022-05-23 14:14:00 -0600 |
---|---|---|
committer | Brandon Nesterenko <brandon.nesterenko@mariadb.com> | 2022-07-26 13:31:27 -0600 |
commit | 5ab5ff08b008417f32dd4bb15820a1a53ea3821c (patch) | |
tree | 065fb608faf7067e7efb40e5d2ef1f74d9d7a17e /sql | |
parent | 8c2faad576d6a77314e92755a389de2c41e21242 (diff) | |
download | mariadb-git-5ab5ff08b008417f32dd4bb15820a1a53ea3821c.tar.gz |
MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based replication is used by default if master supports it
This commit makes replicas crash-safe by default by changing the
Using_Gtid value to be Slave_Pos on a fresh slave start and after
RESET SLAVE is issued. If the primary server does not support GTIDs
(i.e., version < 10), the replica will fall back to Using_Gtid=No on
slave start and after RESET SLAVE.
The following additional informational messages/warnings are added:
1. When Using_Gtid is automatically changed. That is, if RESET
SLAVE reverts Using_Gtid back to Slave_Pos, or Using_Gtid is
inferred to No from a CHANGE MASTER TO given with log coordinates
without MASTER_USE_GTID.
2. If options are ignored in CHANGE MASTER TO. If CHANGE MASTER TO
is given with log coordinates, yet also specifies
MASTER_USE_GTID=Slave_Pos, a warning message is given that the log
coordinate options are ignored.
Additionally, an MTR macro has been added for RESET SLAVE,
reset_slave.inc, which provides modes/options for resetting a slave
in log coordinate or gtid modes. When in log coordinates mode, the
macro will execute CHANGE MASTER TO MASTER_USE_GTID=No after the
RESET SLAVE command. When in GTID mode, an extra parameter,
reset_slave_keep_gtid_state, can be set to reset or preserve the
value of gtid_slave_pos.
Reviewed By:
===========
Andrei Elkin <andrei.elkin@mariadb.com>
Diffstat (limited to 'sql')
-rw-r--r-- | sql/rpl_mi.cc | 9 | ||||
-rw-r--r-- | sql/rpl_mi.h | 7 | ||||
-rw-r--r-- | sql/share/errmsg-utf8.txt | 4 | ||||
-rw-r--r-- | sql/slave.cc | 11 | ||||
-rw-r--r-- | sql/sql_repl.cc | 44 |
5 files changed, 72 insertions, 3 deletions
diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index 2283f91ba02..b4331c9efc5 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -39,12 +39,12 @@ Master_info::Master_info(LEX_CSTRING *connection_name_arg, clock_diff_with_master(0), sync_counter(0), heartbeat_period(0), received_heartbeats(0), master_id(0), prev_master_id(0), - using_gtid(USE_GTID_NO), events_queued_since_last_gtid(0), + using_gtid(USE_GTID_SLAVE_POS), events_queued_since_last_gtid(0), gtid_reconnect_event_skip_count(0), gtid_event_seen(false), in_start_all_slaves(0), in_stop_all_slaves(0), in_flush_all_relay_logs(0), users(0), killed(0), total_ddl_groups(0), total_non_trans_groups(0), total_trans_groups(0), - is_shutdown(false) + is_shutdown(false), master_supports_gtid(true) { char *tmp; host[0] = 0; user[0] = 0; password[0] = 0; @@ -211,7 +211,10 @@ void init_master_log_pos(Master_info* mi) mi->master_log_name[0] = 0; mi->master_log_pos = BIN_LOG_HEADER_SIZE; // skip magic number - mi->using_gtid= Master_info::USE_GTID_NO; + if (mi->master_supports_gtid) + { + mi->using_gtid= Master_info::USE_GTID_SLAVE_POS; + } mi->gtid_current_pos.reset(); mi->events_queued_since_last_gtid= 0; mi->gtid_reconnect_event_skip_count= 0; diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h index b8135b8b55f..fa3327873c4 100644 --- a/sql/rpl_mi.h +++ b/sql/rpl_mi.h @@ -361,6 +361,13 @@ class Master_info : public Slave_reporting_capability at time its alter info struct is about to be appened to the list. */ bool is_shutdown; + + /* + A replica will default to Slave_Pos for using Using_Gtid; however, we + first need to test if the master supports GTIDs. If not, fall back to 'No'. + Cache the value so future RESET SLAVE commands don't revert to Slave_Pos. + */ + bool master_supports_gtid; }; struct start_alter_thd_args diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index e20dcec3b9f..0c05167823b 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -10074,3 +10074,7 @@ ER_INCONSISTENT_SLAVE_TEMP_TABLE eng "Replicated query '%s' table `%s.%s` can not be temporary" ER_VERS_HIST_PART_FAILED eng "Versioned table %`s.%`s: adding HISTORY partition(s) failed" +WARN_OPTION_CHANGING + eng "%s is implicitly changing the value of '%s' from '%s' to '%s'" +ER_CM_OPTION_MISSING_REQUIREMENT + eng "CHANGE MASTER TO option '%s=%s' is missing requirement %s" diff --git a/sql/slave.cc b/sql/slave.cc index 5c746271cf5..616e1248738 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1775,6 +1775,9 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) } else { + DBUG_EXECUTE_IF("mock_mariadb_primary_v5_in_get_master_version", + version= 5;); + /* Note the following switch will bug when we have MySQL branch 30 ;) */ @@ -2358,6 +2361,14 @@ past_checksum: after_set_capability: #endif + if (!(mi->master_supports_gtid= version >= 10)) + { + sql_print_information( + "Slave I/O thread: Falling back to Using_Gtid=No because " + "master does not support GTIDs"); + mi->using_gtid= Master_info::USE_GTID_NO; + } + if (mi->using_gtid != Master_info::USE_GTID_NO) { /* Request dump to start from slave replication GTID state. */ diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 90fdce1b56f..d4a455e9034 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -3420,6 +3420,16 @@ int reset_slave(THD *thd, Master_info* mi) goto err; } + if (mi->using_gtid != Master_info::USE_GTID_SLAVE_POS && + mi->master_supports_gtid) + { + push_warning_printf( + thd, Sql_condition::WARN_LEVEL_NOTE, WARN_OPTION_CHANGING, + ER_THD(thd, WARN_OPTION_CHANGING), "RESET SLAVE", "Using_Gtid", + mi->using_gtid_astext(mi->using_gtid), + mi->using_gtid_astext(Master_info::USE_GTID_SLAVE_POS)); + } + /* Clear master's log coordinates and associated information */ mi->clear_in_memory_info(thd->lex->reset_slave_info.all); @@ -3816,7 +3826,41 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) else if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_NO || lex_mi->log_file_name || lex_mi->pos || lex_mi->relay_log_name || lex_mi->relay_log_pos) + { + if (lex_mi->use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_NO) + { + push_warning_printf( + thd, Sql_condition::WARN_LEVEL_NOTE, WARN_OPTION_CHANGING, + ER_THD(thd, WARN_OPTION_CHANGING), "CHANGE MASTER TO", "Using_Gtid", + mi->using_gtid_astext(mi->using_gtid), + mi->using_gtid_astext(Master_info::USE_GTID_NO)); + } mi->using_gtid= Master_info::USE_GTID_NO; + } + + /* + Warn about ignored options if there are GTID/log coordinate option + conflicts + */ + if (mi->using_gtid != Master_info::USE_GTID_NO) + { + if (lex_mi->log_file_name) + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, + WARN_OPTION_IGNORED, + ER_THD(thd, WARN_OPTION_IGNORED), "MASTER_LOG_FILE"); + if (lex_mi->pos) + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, + WARN_OPTION_IGNORED, + ER_THD(thd, WARN_OPTION_IGNORED), "MASTER_LOG_POS"); + if (lex_mi->relay_log_name) + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, + WARN_OPTION_IGNORED, + ER_THD(thd, WARN_OPTION_IGNORED), "RELAY_LOG_FILE"); + if (lex_mi->relay_log_pos) + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, + WARN_OPTION_IGNORED, + ER_THD(thd, WARN_OPTION_IGNORED), "RELAY_LOG_POS"); + } do_ids= ((lex_mi->repl_do_domain_ids_opt == LEX_MASTER_INFO::LEX_MI_ENABLE) ? |