Skip to content

Commit feff755

Browse files
committed
WL#7491: GTID-based replication applier recovery and positioning
Step 3: Add the syntax for CHANGE REPLICATION SOURCE ReviewBoard: 26588
1 parent db174bd commit feff755

19 files changed

+1021
-564
lines changed

mysql-test/suite/rpl_gtid/r/rpl_async_conn_failover_checks.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION=1;
1212
#
1313
# 2. Verify disabling AUTO_POSITION while enabling Asynchronous
1414
# Replication Connection Failover results in
15-
# ER_DISABLE_AUTO_POSITION_REQUIRES_ASYNC_RECONNECT_OFF error.
15+
# ER_RPL_ASYNC_RECONNECT_AUTO_POSITION_OFF
1616
#
1717
CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION=0, SOURCE_CONNECTION_AUTO_FAILOVER=1;
18-
ERROR HY000: CHANGE MASTER TO MASTER_AUTO_POSITION = 0 cannot be executed because Asynchronous Replication Connection Failover is enabled i.e. CHANGE MASTER TO SOURCE_CONNECTION_AUTO_FAILOVER = 1.
18+
ERROR HY000: Failed to enable Asynchronous Replication Connection Failover feature. The CHANGE MASTER TO SOURCE_CONNECTION_AUTO_FAILOVER = 1 can only be set when MASTER_AUTO_POSITION option of CHANGE MASTER TO is enabled.
1919
#
2020
# 3. Verify Asynchronous Replication Connection Failover is disabled and
2121
# Auto_position is enabled.

mysql-test/suite/rpl_gtid/t/rpl_async_conn_failover_checks.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION=1;
4646
--echo #
4747
--echo # 2. Verify disabling AUTO_POSITION while enabling Asynchronous
4848
--echo # Replication Connection Failover results in
49-
--echo # ER_DISABLE_AUTO_POSITION_REQUIRES_ASYNC_RECONNECT_OFF error.
49+
--echo # ER_RPL_ASYNC_RECONNECT_AUTO_POSITION_OFF
5050
--echo #
5151

52-
--error ER_DISABLE_AUTO_POSITION_REQUIRES_ASYNC_RECONNECT_OFF
52+
--error ER_RPL_ASYNC_RECONNECT_AUTO_POSITION_OFF
5353
CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION=0, SOURCE_CONNECTION_AUTO_FAILOVER=1;
5454

55-
5655
--echo #
5756
--echo # 3. Verify Asynchronous Replication Connection Failover is disabled and
5857
--echo # Auto_position is enabled.

mysql-test/suite/rpl_nogtid/r/rpl_assign_gtids_to_anonymous_transactions.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ include/sync_slave_sql_with_master.inc
5555
include/gtid_step_assert.inc [count=2, only_count=0]
5656
include/stop_slave.inc
5757
SET GLOBAL GTID_MODE=ON_PERMISSIVE;
58-
ERROR HY000: SET @@GLOBAL.GTID_MODE = OFF is not allowed because replication channel '' is configured with ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS set to LOCAL or to a UUID. Execute CHANGE MASTER TO ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = OFF FOR CHANNEL '' before you set @@GLOBAL.GTID_MODE = 'ON_PERMISSIVE'..
58+
ERROR HY000: SET @@GLOBAL.GTID_MODE = ON_PERMISSIVE is not allowed because replication channel '' is configured with ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS set to LOCAL or to a UUID. Execute CHANGE MASTER TO ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = OFF FOR CHANNEL '' before you set @@GLOBAL.GTID_MODE = 'ON_PERMISSIVE'.
5959
CHANGE REPLICATION SOURCE TO ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = LOCAL, SOURCE_AUTO_POSITION = 1;
6060
ERROR HY000: The options ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = LOCAL|<UUID> and MASTER_AUTO_POSITION = 1 cannot be used together.
6161
include/start_slave_io.inc

share/messages_to_clients.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9441,7 +9441,7 @@ ER_DA_ERROR_LOG_MULTIPLE_FILTERS
94419441
ER_DA_CANT_OPEN_ERROR_LOG
94429442
eng "Could not open file '%s' for error logging%s%s"
94439443

9444-
ER_USER_REFERENCED_AS_DEFINER
9444+
ER_USER_REFERENCED_AS_DEFINER
94459445
eng "User %.256s is referenced as a definer account in %s."
94469446

94479447
ER_CANNOT_USER_REFERENCED_AS_DEFINER
@@ -9625,6 +9625,21 @@ ER_MFA_METHODS_IDENTICAL
96259625
ER_INVALID_MFA_OPERATIONS_FOR_PASSWORDLESS_USER
96269626
eng "The operation \"%s\" cannot be performed for user '%s'@'%s' configured to connect without a password."
96279627

9628+
ER_CHANGE_REPLICATION_SOURCE_NO_OPTIONS_FOR_GTID_ONLY
9629+
eng "GTID_ONLY cannot be enabled for replication channel '%.192s'. You need GTID_MODE = ON, SOURCE_AUTO_POSITION = 1 and REQUIRE_ROW_FORMAT = 1."
9630+
9631+
ER_CHANGE_REP_SOURCE_CANT_DISABLE_REQ_ROW_FORMAT_WITH_GTID_ONLY
9632+
eng "REQUIRE_ROW_FORMAT cannot be disabled for replication channel '%.192s' when GTID_ONLY=1."
9633+
9634+
ER_CHANGE_REP_SOURCE_CANT_DISABLE_AUTO_POS_FORMAT_WITH_GTID_ONLY
9635+
eng "SOURCE_AUTO_POSITION cannot be disabled for replication channel '%.192s' when GTID_ONLY=1."
9636+
9637+
ER_CHANGE_REP_SOURCE_CANT_DISABLE_GTID_ONLY_WITHOUT_POSITIONS
9638+
eng "When disabling GTID_ONLY and SOURCE_AUTO_POSITION FOR CHANNEL '%.192s' you must provide SOURCE_LOG_FILE and SOURCE_LOG_POS."
9639+
9640+
ER_CHANGE_REP_SOURCE_CANT_DISABLE_AUTO_POS_WITHOUT_POSITIONS
9641+
eng "When disabling SOURCE_AUTO_POSITION FOR CHANNEL '%.192s' you must provide SOURCE_LOG_FILE and SOURCE_LOG_POS as source positions are invalid"
9642+
96289643
#
96299644
# End of 8.0 error messages (server-to-client).
96309645
# Do NOT add messages intended for the error log above!

sql/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ TARGET_LINK_LIBRARIES(master binlog sql_main)
975975
SET (SLAVE_SOURCE
976976
dynamic_ids.cc
977977
changestreams/apply/commit_order_queue.cc
978+
changestreams/apply/replication_thread_status.cc
978979
rpl_applier_reader.cc
979980
rpl_async_conn_failover.cc
980981
rpl_async_conn_failover_table_operations.cc

sql/changestreams/apply/constants.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright (c) 2021, Oracle and/or its affiliates.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License, version 2.0,
6+
as published by the Free Software Foundation.
7+
8+
This program is also distributed with certain software (including
9+
but not limited to OpenSSL) that is licensed under separate terms,
10+
as designated in a particular file or component or in included license
11+
documentation. The authors of MySQL hereby grant you an additional
12+
permission to link the program and your derivative works with the
13+
separately licensed software that they have included with MySQL.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License, version 2.0, for more details.
19+
20+
You should have received a copy of the GNU General Public License
21+
along with this program; if not, write to the Free Software
22+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23+
24+
#ifndef CHANGE_STREAM_APPLY_CONSTANTS_H_
25+
#define CHANGE_STREAM_APPLY_CONSTANTS_H_
26+
27+
/* masks for start/stop operations on io and sql slave threads */
28+
static constexpr unsigned long SLAVE_IO = 1;
29+
static constexpr unsigned long SLAVE_SQL = 2;
30+
// We also have SLAVE_FORCE_ALL 4
31+
static constexpr unsigned long SLAVE_MONITOR = 8;
32+
33+
#endif /* CHANGE_STREAM_APPLY_CONSTANTS_H_ */
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright (c) 2021, Oracle and/or its affiliates.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License, version 2.0,
6+
as published by the Free Software Foundation.
7+
8+
This program is also distributed with certain software (including
9+
but not limited to OpenSSL) that is licensed under separate terms,
10+
as designated in a particular file or component or in included license
11+
documentation. The authors of MySQL hereby grant you an additional
12+
permission to link the program and your derivative works with the
13+
separately licensed software that they have included with MySQL.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License, version 2.0, for more details.
19+
20+
You should have received a copy of the GNU General Public License
21+
along with this program; if not, write to the Free Software
22+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23+
24+
#include "sql/changestreams/apply/replication_thread_status.h"
25+
#include "sql/changestreams/apply/constants.h"
26+
#include "sql/rpl_io_monitor.h"
27+
28+
void lock_slave_threads(Master_info *mi) {
29+
DBUG_TRACE;
30+
31+
// protection against mixed locking order (see rpl_slave.cc header)
32+
mi->channel_assert_some_wrlock();
33+
34+
// TODO: see if we can do this without dual mutex
35+
mysql_mutex_lock(&mi->run_lock);
36+
mysql_mutex_lock(&mi->rli->run_lock);
37+
}
38+
39+
void unlock_slave_threads(Master_info *mi) {
40+
DBUG_TRACE;
41+
42+
// TODO: see if we can do this without dual mutex
43+
mysql_mutex_unlock(&mi->rli->run_lock);
44+
mysql_mutex_unlock(&mi->run_lock);
45+
}
46+
47+
void init_thread_mask(int *mask, Master_info *mi, bool inverse,
48+
bool ignore_monitor_thread) {
49+
bool set_io = mi->slave_running, set_sql = mi->rli->slave_running;
50+
bool set_monitor{
51+
Source_IO_monitor::get_instance()->is_monitoring_process_running()};
52+
int tmp_mask{0};
53+
DBUG_TRACE;
54+
55+
if (set_io) tmp_mask |= SLAVE_IO;
56+
if (set_sql) tmp_mask |= SLAVE_SQL;
57+
if (!ignore_monitor_thread && set_monitor &&
58+
mi->is_source_connection_auto_failover()) {
59+
tmp_mask |= SLAVE_MONITOR;
60+
}
61+
62+
if (inverse) {
63+
tmp_mask ^= (SLAVE_IO | SLAVE_SQL);
64+
if (!ignore_monitor_thread && mi->is_source_connection_auto_failover()) {
65+
tmp_mask ^= SLAVE_MONITOR;
66+
}
67+
}
68+
69+
*mask = tmp_mask;
70+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright (c) 2021, Oracle and/or its affiliates.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License, version 2.0,
6+
as published by the Free Software Foundation.
7+
8+
This program is also distributed with certain software (including
9+
but not limited to OpenSSL) that is licensed under separate terms,
10+
as designated in a particular file or component or in included license
11+
documentation. The authors of MySQL hereby grant you an additional
12+
permission to link the program and your derivative works with the
13+
separately licensed software that they have included with MySQL.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License, version 2.0, for more details.
19+
20+
You should have received a copy of the GNU General Public License
21+
along with this program; if not, write to the Free Software
22+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23+
24+
#ifndef CHANGE_STREAM_REPLICATION_THREAD_STATUS_H_
25+
#define CHANGE_STREAM_REPLICATION_THREAD_STATUS_H_
26+
27+
#include "sql/rpl_mi.h"
28+
29+
/**
30+
This method locks both (in this order)
31+
mi->run_lock
32+
rli->run_lock
33+
34+
@param mi The associated master info object
35+
36+
@note this method shall be invoked while locking mi->m_channel_lock
37+
for writes. This is due to the mixed order in which these locks are released
38+
and acquired in such method as the slave threads start and stop methods.
39+
*/
40+
void lock_slave_threads(Master_info *mi);
41+
42+
/**
43+
Unlock replica master and relay log info locks.
44+
45+
@param mi the repo info object that contains the lock
46+
*/
47+
void unlock_slave_threads(Master_info *mi);
48+
49+
/**
50+
Find out which replications threads are running
51+
52+
@param mask Return value here
53+
@param mi master_info for slave
54+
@param inverse If set, returns which threads are not running
55+
@param ignore_monitor_thread If set, ignores monitor io thread
56+
57+
IMPLEMENTATION
58+
Get a bit mask for which threads are running.
59+
60+
@return
61+
If inverse == 0, running threads
62+
If inverse == 1, stopped threads
63+
*/
64+
void init_thread_mask(int *mask, Master_info *mi, bool inverse,
65+
bool ignore_monitor_thread = false);
66+
67+
#endif /* CHANGE_STREAM_REPLICATION_THREAD_STATUS_H_ */

sql/lex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static const SYMBOL symbols[] = {
297297
{SYM("GROUP", GROUP_SYM)},
298298
{SYM("GROUPING", GROUPING_SYM)},
299299
{SYM("GROUPS", GROUPS_SYM)},
300+
{SYM("GTID_ONLY", GTID_ONLY_SYM)},
300301
{SYM("HANDLER", HANDLER_SYM)},
301302
{SYM("HASH", HASH_SYM)},
302303
{SYM("HAVING", HAVING)},

sql/rpl_async_conn_failover.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "mysql/components/services/log_builtins.h"
2424

25+
#include "sql/changestreams/apply/replication_thread_status.h"
2526
#include "sql/current_thd.h"
2627
#include "sql/debug_sync.h" // DEBUG_SYNC
2728
#include "sql/rpl_async_conn_failover.h"

sql/rpl_channel_service_interface.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "mysqld_error.h"
4848
#include "sql/auth/sql_security_ctx.h"
4949
#include "sql/binlog.h"
50+
#include "sql/changestreams/apply/replication_thread_status.h"
5051
#include "sql/current_thd.h"
5152
#include "sql/log.h"
5253
#include "sql/log_event.h"

sql/rpl_filter.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "mysqld_error.h"
4646
#include "sql/auth/auth_acls.h"
4747
#include "sql/auth/sql_security_ctx.h"
48+
#include "sql/changestreams/apply/replication_thread_status.h"
4849
#include "sql/current_thd.h"
4950
#include "sql/item.h" // Item
5051
#include "sql/mysqld.h" // table_alias_charset

sql/rpl_io_monitor.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <mysql/components/services/group_replication_status_service.h>
2626
#include "mysql/components/services/log_builtins.h"
2727

28+
#include "sql/changestreams/apply/replication_thread_status.h"
2829
#include "sql/json_dom.h"
2930
#include "sql/mysqld.h"
3031
#include "sql/mysqld_thd_manager.h" // Global_THD_manager

0 commit comments

Comments
 (0)