Added Gtid_binlog_pos to SHOW MASTER STATUS

Other things:
- Extended mysqltest to write GTID's for master and slave if
  sync_slave_with_master fails.
This commit is contained in:
Monty 2025-12-27 14:13:49 +02:00
parent 6efa06805d
commit f2ffd68d81
2 changed files with 32 additions and 6 deletions

View File

@ -308,6 +308,7 @@ struct Parser
struct MasterPos
{
char file[FN_REFLEN];
char gtid[256];
ulong pos;
} master_pos;
@ -4937,9 +4938,20 @@ void do_sync_with_master2(struct st_command *command, long offset,
if (!result_str || result < 0)
{
char *gtid_slave_pos;
/* master_pos_wait returned NULL or < 0 */
fprintf(stderr, "analyze: sync_with_master\n");
if (!mysql_query(mysql, "select @@global.gtid_slave_pos"))
{
if ((res= mysql_store_result(mysql)))
{
if ((row= mysql_fetch_row(res)))
gtid_slave_pos= my_strdup(PSI_NOT_INSTRUMENTED, row[0], MYF(0));
}
mysql_free_result(res);
}
sprintf(query_buf2, "show slave \"%s\" status", connection_name);
if (!mysql_query(mysql, query_buf2))
@ -4948,15 +4960,19 @@ void do_sync_with_master2(struct st_command *command, long offset,
{
if ((row= mysql_fetch_row(res)))
{
fprintf(stderr, "Slave position: file: %s position: %s\n",
fprintf(stderr, "Slave position: file: %s position: %s GTID_IO: %s GTID_slave_pos: %s\n",
get_col_value(res, row, "Relay_Master_Log_File"),
get_col_value(res, row, "Read_Master_Log_Pos"));
fprintf(stderr, "Master position: file: %s position: %lld\n",
master_pos.file, (longlong) (master_pos.pos + offset));
get_col_value(res, row, "Read_Master_Log_Pos"),
get_col_value(res, row, "Gtid_IO_Pos"),
gtid_slave_pos ? gtid_slave_pos : "");
fprintf(stderr, "Master position: file: %s position: %lld GTID: %s\n",
master_pos.file, (longlong) (master_pos.pos + offset), master_pos.gtid);
}
mysql_free_result(res);
}
}
my_free(gtid_slave_pos);
if (!result_str)
{
/*
@ -5034,8 +5050,9 @@ int do_save_master_pos()
die("mysql_store_result() returned NULL for '%s'", query);
if (!(row = mysql_fetch_row(res)))
die("empty result in show master status");
strnmov(master_pos.file, row[0], sizeof(master_pos.file)-1);
master_pos.pos = strtoul(row[1], (char**) 0, 10);
strmake(master_pos.file, row[0], sizeof(master_pos.file)-1);
master_pos.pos= strtoul(row[1], (char**) 0, 10);
strmake(master_pos.gtid, row[4], sizeof(master_pos.gtid)-1);
mysql_free_result(res);
DBUG_RETURN(0);
}

View File

@ -4716,6 +4716,9 @@ void show_binlog_info_get_fields(THD *thd, List<Item> *field_list)
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Binlog_Ignore_DB", 255),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Gtid_Binlog_Pos", 255),
mem_root);
}
@ -4747,11 +4750,17 @@ bool show_binlog_info(THD* thd)
mysql_bin_log.get_current_log(&li);
size_t dir_len = dirname_length(li.log_file_name);
const char *base= li.log_file_name + dir_len;
char buf[128];
String str(buf, sizeof(buf), system_charset_info);
str.length(0);
(void) mysql_bin_log.append_state_pos(&str);
protocol->store(base, strlen(base), &my_charset_bin);
protocol->store((ulonglong) li.pos);
protocol->store(binlog_filter->get_do_db());
protocol->store(binlog_filter->get_ignore_db());
protocol->store(&str);
if (protocol->write())
DBUG_RETURN(TRUE);
}