Bug #109977 Contribution by Tencent: semisync plugin may print a negative server id
Submitted: 8 Feb 2023 8:05 Modified: 8 Feb 2023 8:30
Reporter: yewei Xu (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:8.0.32,5.7.41 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, semisync

[8 Feb 2023 8:05] yewei Xu
Description:
The server id in mysql is declared as uint32 type, but in the semisync plugin, the server id is printed by %d, and a negative server id may be printed by mistake.

How to repeat:
read code

Suggested fix:
fix for mysql5.7:

diff --git a/plugin/semisync/semisync_master_plugin.cc b/plugin/semisync/semisync_master_plugin.cc
index 54dbb4fbc87..e3ecf001430 100644
--- a/plugin/semisync/semisync_master_plugin.cc
+++ b/plugin/semisync/semisync_master_plugin.cc
@@ -159,7 +159,7 @@ int repl_semi_binlog_dump_start(Binlog_transmit_param *param,
   else
     param->set_dont_observe_flag();
 
-  sql_print_information("Start %s binlog_dump to slave (server_id: %d), pos(%s, %lu)",
+  sql_print_information("Start %s binlog_dump to slave (server_id: %u), pos(%s, %lu)",
                        semi_sync_slave != 0 ? "semi-sync" : "asynchronous",
                        param->server_id, log_file, (unsigned long)log_pos);
 
@@ -170,7 +170,7 @@ int repl_semi_binlog_dump_end(Binlog_transmit_param *param)
 {
   bool semi_sync_slave= is_semi_sync_dump();
 
-  sql_print_information("Stop %s binlog_dump to slave (server_id: %d)",
+  sql_print_information("Stop %s binlog_dump to slave (server_id: %u)",
                         semi_sync_slave ? "semi-sync" : "asynchronous",
                         param->server_id);
   if (semi_sync_slave)

fix for mysql8.0:

diff --git a/share/messages_to_error_log.txt b/share/messages_to_error_log.txt
index c593f51ca01..59b25683b18 100644
--- a/share/messages_to_error_log.txt
+++ b/share/messages_to_error_log.txt
@@ -3567,10 +3567,10 @@ ER_SEMISYNC_FAILED_REGISTER_SLAVE_TO_RECEIVER
   eng "Failed to register slave to semi-sync ACK receiver thread."
 
 ER_SEMISYNC_START_BINLOG_DUMP_TO_SLAVE
-  eng "Start %s binlog_dump to slave (server_id: %d), pos(%s, %lu)."
+  eng "Start %s binlog_dump to slave (server_id: %u), pos(%s, %lu)."
 
 ER_SEMISYNC_STOP_BINLOG_DUMP_TO_SLAVE
-  eng "Stop %s binlog_dump to slave (server_id: %d)."
+  eng "Stop %s binlog_dump to slave (server_id: %u)."
 
 ER_SEMISYNC_UNREGISTER_TRX_OBSERVER_FAILED
   eng "unregister_trans_observer failed."
[8 Feb 2023 8:30] MySQL Verification Team
Hello  Yewei Xu,

Thank you for the report and contribution.

regards,
Umesh