From ad92832a1f28a9e669405b5ae60390068ca56ec1 Mon Sep 17 00:00:00 2001 From: "jiyang.zjy" Date: Wed, 3 Apr 2024 09:56:29 +0800 Subject: [PATCH] [Postfix] Abnormal Exit of Xtrabackup caused replication stop Summary ------- To obtain a consistent index before locking, XPAXOS replication will be stopped. After the backup ends, XPAXOS replication will be restarted. If Xtrabackup exits abnormally, it may cause the xpaxos replication status to remain in a stopped state. Fix --- Force use FTWRL when bakcup XCluster instance to get a valid index. --- .../innobase/xtrabackup/src/backup_mysql.cc | 39 +++---------------- .../innobase/xtrabackup/src/backup_mysql.h | 4 -- storage/innobase/xtrabackup/src/xtrabackup.cc | 1 - 3 files changed, 6 insertions(+), 38 deletions(-) diff --git a/storage/innobase/xtrabackup/src/backup_mysql.cc b/storage/innobase/xtrabackup/src/backup_mysql.cc index 0961baa1402..f7b0dc4b022 100644 --- a/storage/innobase/xtrabackup/src/backup_mysql.cc +++ b/storage/innobase/xtrabackup/src/backup_mysql.cc @@ -1139,6 +1139,12 @@ bool lock_tables_maybe(MYSQL *connection, int timeout, int retry_count) { bool force_ftwrl = opt_slave_info && !slave_auto_position && !(server_flavor == FLAVOR_PERCONA_SERVER); + /** If it's XCluster, always use FTWRL, because commit index (for leader), + apply index (for follower) can not get from p_s.log_status. */ + if (server_flavor == FLAVOR_X_CLUSTER) { + force_ftwrl = true; + } + if (tables_locked || (opt_lock_ddl_per_table && !force_ftwrl)) { return (true); } @@ -1147,8 +1153,6 @@ bool lock_tables_maybe(MYSQL *connection, int timeout, int retry_count) { return (true); } - disable_replication_for_polarx(connection); - if (have_backup_locks && !force_ftwrl) { return lock_tables_for_backup(connection, timeout, retry_count); } @@ -1172,8 +1176,6 @@ void unlock_all(MYSQL *connection) { } xb::info() << "All tables unlocked"; - - enable_replication_for_polarx(connection); } static int get_open_temp_tables(MYSQL *connection) { @@ -2628,32 +2630,3 @@ bool print_instant_versioned_tables(MYSQL *connection) { return ret; } -void disable_replication_for_polarx(MYSQL *connection) { - if (xcluster_sql_thread_started) return; - - if (server_flavor == FLAVOR_X_CLUSTER) { - // if slave_sql_running, stop mts - char *slave_sql_running = NULL; - mysql_variable status[] = {{"Slave_SQL_Running", &slave_sql_running}, - {NULL, NULL}}; - read_mysql_variables(connection, "SHOW SLAVE STATUS", status, false); - if (strcmp(slave_sql_running, "Yes") == 0) { - xb::info() << "Disable replication for polarx..."; - xcluster_sql_thread_started = true; - xb_mysql_query(connection, "STOP SLAVE SQL_THREAD", false, false); - xb_mysql_query(connection, "STOP XPAXOS_REPLICATION", false, false); - } - free_mysql_variables(status); - } -} - -void enable_replication_for_polarx(MYSQL *connection) { - if (!xcluster_sql_thread_started) return; - - if (server_flavor == FLAVOR_X_CLUSTER) { - xb::info() << "Enable replication for polarx..."; - xb_mysql_query(connection, "START SLAVE SQL_THREAD", false, false); - xb_mysql_query(connection, "START XPAXOS_REPLICATION", false, false); - xcluster_sql_thread_started = false; - } -} diff --git a/storage/innobase/xtrabackup/src/backup_mysql.h b/storage/innobase/xtrabackup/src/backup_mysql.h index 102813c2aa1..ac5249b7463 100644 --- a/storage/innobase/xtrabackup/src/backup_mysql.h +++ b/storage/innobase/xtrabackup/src/backup_mysql.h @@ -278,8 +278,4 @@ void check_dump_innodb_buffer_pool(MYSQL *connection); bool print_instant_versioned_tables(MYSQL *connection); extern log_status_t log_status; -void disable_replication_for_polarx(MYSQL *connection); - -void enable_replication_for_polarx(MYSQL *connection); - #endif diff --git a/storage/innobase/xtrabackup/src/xtrabackup.cc b/storage/innobase/xtrabackup/src/xtrabackup.cc index a401f03da97..06061a28e13 100644 --- a/storage/innobase/xtrabackup/src/xtrabackup.cc +++ b/storage/innobase/xtrabackup/src/xtrabackup.cc @@ -7660,7 +7660,6 @@ bool xb_init() { } if (opt_lock_ddl) { - disable_replication_for_polarx(mysql_connection); if (!lock_tables_for_backup(mysql_connection, opt_lock_ddl_timeout, 0)) return (false); }