MySQL a sync fault caused by an upset parameter

Source: Internet
Author: User

Recently there is a synchronization problem, our data into the order of Mysql->redis, the business layer only for MySQL operation, and synchronization to Redis the operation is to use the open source drive package to write their own synchronization tool, the latest program updates restart, sometimes without the same error:

Error Error 1105 (HY000): Failed to register Slave:too long ' report-host ' "

Error restart one or two times and normal, at first suspected that the program inside of what has a problem, because of their own small synchronization program did not appear this error, but also let developers in the detection, after the inspection did not pass what about the host parameters, so went to the official website to search the next Report_host take a chance to see if there is this parameter, there is really ........ , the official website is described as follows:

The host name or IP address of the slave to is reported to the master during slave registration. This value appears in the output of SHOW SLAVE HOSTS on the master server. Leave The value unset if you don't want the slave to register itself with the master.

It is probably meant that this parameter is used by slave to pass the hostname when the master-slave is established , with the show slave hosts command can be seen, If you do not add this parameter is not visible, can only be viewed in processlist , so the development of children's shoes to the driver pack to find out to get the native hostname delivery, To this basic determination is due to the hostname over the length of the MySQL limit caused, then why the update start times wrong, restart after the normal, continue .......

Our application is deployed in a Docker cluster, andDocker generates a random hostname using the application name and random string when booting with the image . Restart after the generation will be shorter, which causes the first start will be error, and restart after the normal, find out the reason to see MySQL where can modify the limit, after looking for no parameters about this ............. so the source of the search, found Report_host the length is written dead - :

Int register_slave_on_master (mysql* mysql, master_info *mi,                               bool *suppress_warnings) {  uchar buf[1024], *pos=  buf;  size_t report_host_len=0, report_user_len=0, report_password_len=0;   dbug_enter ("Register_slave_on_master");    *suppress_warnings= false;  if   (Report_host)     report_host_len= strlen (report_host)  //get the length of report_host   if  (report_host_len > hostname_length)   //determine if report_host length is more than hostname_ length=60 limit   {    sql_print_warning ("The length of report_host  is %zu.  "                        "It is larger than the max length (%d),  so  this  "                        "slave cannot be registered to the  master%s. ",                       report_host_len, HOSTNAME_LENGTH,                       mi->get_for _channel_str ());     dbug_return (0);  }    ....    int4store (pos, server_id);  pos+= 4; //------------- Top 4bytes Write Server_id  pos= net_store_data (pos,  (uchar*)  report_host, report_host_ len);//Here is the write report_host and length, the rule is length of 1bytes, followed by the repOrt_host  pos= net_store_data (pos,  (uchar*)  report_user, report_user_len);   pos= net_store_data (pos,  (uchar*)  report_password, report_password_len);   ......................................}

This is the source of the slave end in the protocol set up the Group protocol package of the abbreviated content, in fact, here the length of the report_host is checked, if more than 60 of the length will be error, you can not establish Master-slave, But we're writing our own tools, and the drive bag just gets hostname and doesn't judge its length.


Int register_slave (thd* thd, uchar* packet, size_t packet_length) {   Int res;  slave_info *si;  uchar *p= packet, *p_end= packet  + packet_length;  const char *errmsg=  "wrong parameters to  Function register_slave ";   if  (check_access (thd, repl_slave_acl, any_db,  null, null, 0, 0)     return 1;  if  (!) ( si =  (slave_info*) My_malloc (key_memory_slave_info,                                      sizeof (Slave_info),  MYF (MY_WME)))      goto err2;   /* 4 bytes for the server id  */  if  (p  + 4 > p_end)   {    my_error (ER_MALFORMED_PACKET, MYF (0)) ;     my_free (SI);     return 1;  }   thd- >server_id= si->server_id= uint4korr (P);  //first in front 4bytes gets server_id  p+= 4;   get_object (p,si->host,  "failed to register slave: too long " Report-host ' ");  //here is to get report_host, and make judgments, error content and our application error content consistent, Si->host is char host[hostname_length+1] The length of both 61   get_object (p,si->user,  "Failed to register slave: too long   ' Report-user ');   get_object (p,si->password,  "failed to register slave;  too long  ' Report-password ');  &nbsp, ...............}

The above-mentioned abbreviated content is the operation that master received after slave initiated the protocol package, in which our error content, and get_object is judged in the following way:


#define GET_OBJECT (p, obj, msg) {UINT Len;    ..... len= (UINT) *p++,..... ......    if (p + len > P_end | | len >= sizeof (obj)) {errmsg= msg;   Goto err; }  .........................}


based on the lookup analysis of the source code,MySQL limits the report_host to a maximum of 60 bytes, i.e. non-Chinese characters, this is a relatively unpopular parameter, and in the source code also wrote dead length, we only to the service name and Docker hostname control to solve this problem

the problem in our usual use in fact rarely encountered, and the official website did not introduce this length limit, just beginning to encounter a little touch, if there are children shoes do synchronization can do reference, we use the go-mysql this open source package, If there is a use can be noted under


Ps:mysql Technology QQ Group 479472450



MySQL a sync fault caused by an upset parameter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.