Skip to content

Commit

Permalink
[Postfix] Abnormal Exit of Xtrabackup caused replication stop
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jiyang.zjy authored and jianwei.zhao committed Apr 22, 2024
1 parent 2882490 commit ad92832
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 38 deletions.
39 changes: 6 additions & 33 deletions storage/innobase/xtrabackup/src/backup_mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}
4 changes: 0 additions & 4 deletions storage/innobase/xtrabackup/src/backup_mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion storage/innobase/xtrabackup/src/xtrabackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ad92832

Please sign in to comment.