~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/slave.cc

  • Committer: Brian Aker
  • Date: 2008-07-14 16:24:25 UTC
  • Revision ID: brian@tangent.org-20080714162425-juw3vw221gs9kysh
Cleanup around intptr_t

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003 DRIZZLE AB
 
1
/* Copyright (C) 2000-2003 MySQL AB
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
23
23
  @brief Code to run the io thread and the sql thread on the
24
24
  replication slave.
25
25
*/
26
 
#include <drizzled/server_includes.h>
27
 
 
28
 
#include <storage/myisam/myisam.h>
 
26
 
 
27
#include "mysql_priv.h"
 
28
 
 
29
#include <myisam.h>
 
30
#include "slave.h"
29
31
#include "rpl_mi.h"
30
32
#include "rpl_rli.h"
31
33
#include "sql_repl.h"
32
34
#include "rpl_filter.h"
33
35
#include "repl_failsafe.h"
34
 
#include <mysys/thr_alarm.h>
35
 
#include <libdrizzle/sql_common.h>
36
 
#include <libdrizzle/errmsg.h>
37
 
#include <mysys/mysys_err.h>
38
 
#include <drizzled/drizzled_error_messages.h>
 
36
#include <thr_alarm.h>
 
37
#include <my_dir.h>
 
38
#include <sql_common.h>
 
39
#include <errmsg.h>
 
40
#include <mysys_err.h>
 
41
 
 
42
#ifdef HAVE_REPLICATION
39
43
 
40
44
#include "rpl_tblmap.h"
41
45
 
49
53
 
50
54
char* slave_load_tmpdir = 0;
51
55
Master_info *active_mi= 0;
52
 
bool replicate_same_server_id;
 
56
my_bool replicate_same_server_id;
53
57
uint64_t relay_log_space_limit = 0;
54
58
 
55
59
/*
84
88
static const char *reconnect_messages[SLAVE_RECON_ACT_MAX][SLAVE_RECON_MSG_MAX]=
85
89
{
86
90
  {
87
 
    N_("Waiting to reconnect after a failed registration on master"),
88
 
    N_("Slave I/O thread killed while waitnig to reconnect after a "
89
 
                 "failed registration on master"),
90
 
    N_("Reconnecting after a failed registration on master"),
91
 
    N_("failed registering on master, reconnecting to try again, "
92
 
                 "log '%s' at postion %s"),
 
91
    "Waiting to reconnect after a failed registration on master",
 
92
    "Slave I/O thread killed while waitnig to reconnect after a failed \
 
93
registration on master",
 
94
    "Reconnecting after a failed registration on master",
 
95
    "failed registering on master, reconnecting to try again, \
 
96
log '%s' at postion %s",
93
97
    "COM_REGISTER_SLAVE",
94
 
    N_("Slave I/O thread killed during or after reconnect")
 
98
    "Slave I/O thread killed during or after reconnect"
95
99
  },
96
100
  {
97
 
    N_("Waiting to reconnect after a failed binlog dump request"),
98
 
    N_("Slave I/O thread killed while retrying master dump"),
99
 
    N_("Reconnecting after a failed binlog dump request"),
100
 
    N_("failed dump request, reconnecting to try again, "
101
 
                 "log '%s' at postion %s"),
 
101
    "Waiting to reconnect after a failed binlog dump request",
 
102
    "Slave I/O thread killed while retrying master dump",
 
103
    "Reconnecting after a failed binlog dump request",
 
104
    "failed dump request, reconnecting to try again, log '%s' at postion %s",
102
105
    "COM_BINLOG_DUMP",
103
 
    N_("Slave I/O thread killed during or after reconnect")
 
106
    "Slave I/O thread killed during or after reconnect"
104
107
  },
105
108
  {
106
 
    N_("Waiting to reconnect after a failed master event read"),
107
 
    N_("Slave I/O thread killed while waiting to reconnect "
108
 
                 "after a failed read"),
109
 
    N_("Reconnecting after a failed master event read"),
110
 
    N_("Slave I/O thread: Failed reading log event, "
111
 
                 "reconnecting to retry, log '%s' at postion %s"),
 
109
    "Waiting to reconnect after a failed master event read",
 
110
    "Slave I/O thread killed while waiting to reconnect after a failed read",
 
111
    "Reconnecting after a failed master event read",
 
112
    "Slave I/O thread: Failed reading log event, reconnecting to retry, \
 
113
log '%s' at postion %s",
112
114
    "",
113
 
    N_("Slave I/O thread killed during or after a "
114
 
                 "reconnect done to recover from failed read")
 
115
    "Slave I/O thread killed during or after a reconnect done to recover from \
 
116
failed read"
115
117
  }
116
118
};
117
119
 
124
126
static inline bool io_slave_killed(THD* thd,Master_info* mi);
125
127
static inline bool sql_slave_killed(THD* thd,Relay_log_info* rli);
126
128
static int32_t init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type);
127
 
static int32_t safe_connect(THD* thd, DRIZZLE *drizzle, Master_info* mi);
128
 
static int32_t safe_reconnect(THD* thd, DRIZZLE *drizzle, Master_info* mi,
 
129
static int32_t safe_connect(THD* thd, MYSQL* mysql, Master_info* mi);
 
130
static int32_t safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
129
131
                          bool suppress_warnings);
130
 
static int32_t connect_to_master(THD* thd, DRIZZLE *drizzle, Master_info* mi,
 
132
static int32_t connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
131
133
                             bool reconnect, bool suppress_warnings);
132
134
static int32_t safe_sleep(THD* thd, int32_t sec, CHECK_KILLED_FUNC thread_killed,
133
135
                      void* thread_killed_arg);
134
 
static int32_t get_master_version_and_clock(DRIZZLE *drizzle, Master_info* mi);
 
136
static int32_t get_master_version_and_clock(MYSQL* mysql, Master_info* mi);
135
137
static Log_event* next_event(Relay_log_info* rli);
136
138
static int32_t queue_event(Master_info* mi,const char* buf,uint32_t event_len);
137
139
static int32_t terminate_slave_thread(THD *thd,
224
226
  */
225
227
  if (!active_mi)
226
228
  {
227
 
    sql_print_error(_("Failed to allocate memory for the master info structure"));
 
229
    sql_print_error("Failed to allocate memory for the master info structure");
228
230
    goto err;
229
231
  }
230
232
 
231
233
  if (init_master_info(active_mi,master_info_file,relay_log_info_file,
232
234
                       1, (SLAVE_IO | SLAVE_SQL)))
233
235
  {
234
 
    sql_print_error(_("Failed to initialize the master info structure"));
 
236
    sql_print_error("Failed to initialize the master info structure");
235
237
    goto err;
236
238
  }
237
239
 
246
248
                            relay_log_info_file,
247
249
                            SLAVE_IO | SLAVE_SQL))
248
250
    {
249
 
      sql_print_error(_("Failed to create slave threads"));
 
251
      sql_print_error("Failed to create slave threads");
250
252
      goto err;
251
253
    }
252
254
  }
282
284
  use_slave_mask = 1;
283
285
  for (;my_isspace(system_charset_info,*arg);++arg)
284
286
    /* empty */;
285
 
  if (!my_strnncoll(system_charset_info,(unsigned char*)arg,4,(const unsigned char*)"all",4))
 
287
  if (!my_strnncoll(system_charset_info,(uchar*)arg,4,(const uchar*)"all",4))
286
288
  {
287
289
    bitmap_set_all(&slave_error_mask);
288
290
    return;
443
445
      pthread_cond_broadcast(start_cond);
444
446
    if (start_lock)
445
447
      pthread_mutex_unlock(start_lock);
446
 
    sql_print_error(_("Server id not set, will not start slave"));
 
448
    sql_print_error("Server id not set, will not start slave");
447
449
    return(ER_BAD_SLAVE);
448
450
  }
449
451
 
501
503
 
502
504
int32_t start_slave_threads(bool need_slave_mutex, bool wait_for_start,
503
505
                        Master_info* mi,
504
 
                        const char* master_info_fname __attribute__((unused)),
505
 
                        const char* slave_info_fname __attribute__((unused)),
 
506
                        const char* master_info_fname __attribute__((__unused__)),
 
507
                        const char* slave_info_fname __attribute__((__unused__)),
506
508
                        int32_t thread_mask)
507
509
{
508
510
  pthread_mutex_t *lock_io=0,*lock_sql=0,*lock_cond_io=0,*lock_cond_sql=0;
541
543
 
542
544
 
543
545
#ifdef NOT_USED_YET
544
 
static int32_t end_slave_on_walk(Master_info* mi, unsigned char* /*unused*/)
 
546
static int32_t end_slave_on_walk(Master_info* mi, uchar* /*unused*/)
545
547
{
546
548
  end_master_info(mi);
547
549
  return(0);
611
613
    if (difftime(time(0), rli->last_event_start_time) > 60)
612
614
    {
613
615
      rli->report(ERROR_LEVEL, 0,
614
 
                  _("SQL thread had to stop in an unsafe situation, in "
 
616
                  "SQL thread had to stop in an unsafe situation, in "
615
617
                  "the middle of applying updates to a "
616
618
                  "non-transactional table without any primary key. "
617
619
                  "There is a risk of duplicate updates when the slave "
618
620
                  "SQL thread is restarted. Please check your tables' "
619
 
                  "contents after restart."));
 
621
                  "contents after restart.");
620
622
      return(1);
621
623
    }
622
624
  }
635
637
{
636
638
  (void)net_request_file(net, "/dev/null");
637
639
  (void)my_net_read(net);                               // discard response
638
 
  (void)net_write_command(net, 0, (unsigned char*) "", 0, (unsigned char*) "", 0); // ok
 
640
  (void)net_write_command(net, 0, (uchar*) "", 0, (uchar*) "", 0); // ok
639
641
  return;
640
642
}
641
643
 
642
644
 
643
645
bool net_request_file(NET* net, const char* fname)
644
646
{
645
 
  return(net_write_command(net, 251, (unsigned char*) fname, strlen(fname),
646
 
                                (unsigned char*) "", 0));
 
647
  return(net_write_command(net, 251, (uchar*) fname, strlen(fname),
 
648
                                (uchar*) "", 0));
647
649
}
648
650
 
649
651
/*
752
754
  1       error
753
755
*/
754
756
 
755
 
static int32_t get_master_version_and_clock(DRIZZLE *drizzle, Master_info* mi)
 
757
static int32_t get_master_version_and_clock(MYSQL* mysql, Master_info* mi)
756
758
{
757
759
  char error_buf[512];
758
760
  String err_msg(error_buf, sizeof(error_buf), &my_charset_bin);
759
761
  char err_buff[MAX_SLAVE_ERRMSG];
760
762
  const char* errmsg= 0;
761
763
  int32_t err_code= 0;
762
 
  DRIZZLE_RES *master_res= 0;
763
 
  DRIZZLE_ROW master_row;
 
764
  MYSQL_RES *master_res= 0;
 
765
  MYSQL_ROW master_row;
764
766
 
765
767
  err_msg.length(0);
766
768
  /*
770
772
  delete mi->rli.relay_log.description_event_for_queue;
771
773
  mi->rli.relay_log.description_event_for_queue= 0;
772
774
 
773
 
  if (!my_isdigit(&my_charset_bin,*drizzle->server_version))
 
775
  if (!my_isdigit(&my_charset_bin,*mysql->server_version))
774
776
  {
775
 
    errmsg = _("Master reported unrecognized DRIZZLE version");
 
777
    errmsg = "Master reported unrecognized MySQL version";
776
778
    err_code= ER_SLAVE_FATAL_ERROR;
777
779
    sprintf(err_buff, ER(err_code), errmsg);
778
780
    err_msg.append(err_buff);
780
782
  else
781
783
  {
782
784
    /*
783
 
      Note the following switch will bug when we have DRIZZLE branch 30 ;)
 
785
      Note the following switch will bug when we have MySQL branch 30 ;)
784
786
    */
785
 
    switch (*drizzle->server_version)
 
787
    switch (*mysql->server_version)
786
788
    {
787
789
    case '0':
788
790
    case '1':
789
791
    case '2':
790
 
      errmsg = _("Master reported unrecognized DRIZZLE version");
 
792
      errmsg = "Master reported unrecognized MySQL version";
791
793
      err_code= ER_SLAVE_FATAL_ERROR;
792
794
      sprintf(err_buff, ER(err_code), errmsg);
793
795
      err_msg.append(err_buff);
794
796
      break;
795
797
    case '3':
796
798
      mi->rli.relay_log.description_event_for_queue= new
797
 
        Format_description_log_event(1, drizzle->server_version);
 
799
        Format_description_log_event(1, mysql->server_version);
798
800
      break;
799
801
    case '4':
800
802
      mi->rli.relay_log.description_event_for_queue= new
801
 
        Format_description_log_event(3, drizzle->server_version);
 
803
        Format_description_log_event(3, mysql->server_version);
802
804
      break;
803
805
    default:
804
806
      /*
805
 
        Master is DRIZZLE >=5.0. Give a default Format_desc event, so that we can
 
807
        Master is MySQL >=5.0. Give a default Format_desc event, so that we can
806
808
        take the early steps (like tests for "is this a 3.23 master") which we
807
809
        have to take before we receive the real master's Format_desc which will
808
810
        override this one. Note that the Format_desc we create below is garbage
810
812
        master is 3.23, 4.0, etc.
811
813
      */
812
814
      mi->rli.relay_log.description_event_for_queue= new
813
 
        Format_description_log_event(4, drizzle->server_version);
 
815
        Format_description_log_event(4, mysql->server_version);
814
816
      break;
815
817
    }
816
818
  }
828
830
  /* as we are here, we tried to allocate the event */
829
831
  if (!mi->rli.relay_log.description_event_for_queue)
830
832
  {
831
 
    errmsg= _("default Format_description_log_event");
 
833
    errmsg= "default Format_description_log_event";
832
834
    err_code= ER_SLAVE_CREATE_EVENT_FAILURE;
833
835
    sprintf(err_buff, ER(err_code), errmsg);
834
836
    err_msg.append(err_buff);
840
842
    unavailable (very old master not supporting UNIX_TIMESTAMP()?).
841
843
  */
842
844
 
843
 
  if (!drizzle_real_query(drizzle, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) &&
844
 
      (master_res= drizzle_store_result(drizzle)) &&
845
 
      (master_row= drizzle_fetch_row(master_res)))
 
845
  if (!mysql_real_query(mysql, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) &&
 
846
      (master_res= mysql_store_result(mysql)) &&
 
847
      (master_row= mysql_fetch_row(master_res)))
846
848
  {
847
849
    mi->clock_diff_with_master=
848
850
      (long) (time((time_t*) 0) - strtoul(master_row[0], 0, 10));
850
852
  else if (!check_io_slave_killed(mi->io_thd, mi, NULL))
851
853
  {
852
854
    mi->clock_diff_with_master= 0; /* The "most sensible" value */
853
 
    sql_print_warning(_("\"SELECT UNIX_TIMESTAMP()\" failed on master, "
854
 
                        "do not trust column Seconds_Behind_Master of SHOW "
855
 
                        "SLAVE STATUS. Error: %s (%d)"),
856
 
                      drizzle_error(drizzle), drizzle_errno(drizzle));
 
855
    sql_print_warning("\"SELECT UNIX_TIMESTAMP()\" failed on master, "
 
856
                      "do not trust column Seconds_Behind_Master of SHOW "
 
857
                      "SLAVE STATUS. Error: %s (%d)",
 
858
                      mysql_error(mysql), mysql_errno(mysql));
857
859
  }
858
860
  if (master_res)
859
 
    drizzle_free_result(master_res);
 
861
    mysql_free_result(master_res);
860
862
 
861
863
  /*
862
864
    Check that the master's server id and ours are different. Because if they
868
870
    Note: we could have put a @@SERVER_ID in the previous SELECT
869
871
    UNIX_TIMESTAMP() instead, but this would not have worked on 3.23 masters.
870
872
  */
871
 
  if (!drizzle_real_query(drizzle,
 
873
  if (!mysql_real_query(mysql,
872
874
                        STRING_WITH_LEN("SHOW VARIABLES LIKE 'SERVER_ID'")) &&
873
 
      (master_res= drizzle_store_result(drizzle)))
 
875
      (master_res= mysql_store_result(mysql)))
874
876
  {
875
 
    if ((master_row= drizzle_fetch_row(master_res)) &&
 
877
    if ((master_row= mysql_fetch_row(master_res)) &&
876
878
        (::server_id == strtoul(master_row[1], 0, 10)) &&
877
879
        !mi->rli.replicate_same_server_id)
878
880
    {
879
881
      errmsg=
880
 
        _("The slave I/O thread stops because master and slave have equal "
881
 
          "DRIZZLE server ids; these ids must be different "
882
 
          "for replication to work (or "
883
 
          "the --replicate-same-server-id option must be used "
884
 
          "on slave but this does"
885
 
          "not always make sense; please check the manual before using it).");
 
882
        "The slave I/O thread stops because master and slave have equal"
 
883
        " MySQL server ids; these ids must be different for replication to work (or"
 
884
        " the --replicate-same-server-id option must be used on slave but this does"
 
885
        " not always make sense; please check the manual before using it).";
886
886
      err_code= ER_SLAVE_FATAL_ERROR;
887
887
      sprintf(err_buff, ER(err_code), errmsg);
888
888
      err_msg.append(err_buff);
889
889
    }
890
 
    drizzle_free_result(master_res);
 
890
    mysql_free_result(master_res);
891
891
    if (errmsg)
892
892
      goto err;
893
893
  }
910
910
  */
911
911
 
912
912
  /* redundant with rest of code but safer against later additions */
913
 
  if (*drizzle->server_version == '3')
 
913
  if (*mysql->server_version == '3')
914
914
    goto err;
915
915
 
916
 
  if ((*drizzle->server_version == '4') &&
917
 
      !drizzle_real_query(drizzle,
 
916
  if ((*mysql->server_version == '4') &&
 
917
      !mysql_real_query(mysql,
918
918
                        STRING_WITH_LEN("SELECT @@GLOBAL.COLLATION_SERVER")) &&
919
 
      (master_res= drizzle_store_result(drizzle)))
 
919
      (master_res= mysql_store_result(mysql)))
920
920
  {
921
 
    if ((master_row= drizzle_fetch_row(master_res)) &&
 
921
    if ((master_row= mysql_fetch_row(master_res)) &&
922
922
        strcmp(master_row[0], global_system_variables.collation_server->name))
923
923
    {
924
924
      errmsg=
925
 
        _("The slave I/O thread stops because master and slave have"
926
 
          " different values for the COLLATION_SERVER global variable."
927
 
          " The values must be equal for replication to work");
 
925
        "The slave I/O thread stops because master and slave have"
 
926
        " different values for the COLLATION_SERVER global variable."
 
927
        " The values must be equal for replication to work";
928
928
      err_code= ER_SLAVE_FATAL_ERROR;
929
929
      sprintf(err_buff, ER(err_code), errmsg);
930
930
      err_msg.append(err_buff);
931
931
    }
932
 
    drizzle_free_result(master_res);
 
932
    mysql_free_result(master_res);
933
933
    if (errmsg)
934
934
      goto err;
935
935
  }
949
949
    This check is only necessary for 4.x masters (and < 5.0.4 masters but
950
950
    those were alpha).
951
951
  */
952
 
  if ((*drizzle->server_version == '4') &&
953
 
      !drizzle_real_query(drizzle, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) &&
954
 
      (master_res= drizzle_store_result(drizzle)))
 
952
  if ((*mysql->server_version == '4') &&
 
953
      !mysql_real_query(mysql, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) &&
 
954
      (master_res= mysql_store_result(mysql)))
955
955
  {
956
 
    if ((master_row= drizzle_fetch_row(master_res)) &&
 
956
    if ((master_row= mysql_fetch_row(master_res)) &&
957
957
        strcmp(master_row[0],
958
958
               global_system_variables.time_zone->get_name()->ptr()))
959
959
    {
960
960
      errmsg=
961
 
        _("The slave I/O thread stops because master and slave have"
962
 
          " different values for the TIME_ZONE global variable."
963
 
          " The values must be equal for replication to work");
 
961
        "The slave I/O thread stops because master and slave have"
 
962
        " different values for the TIME_ZONE global variable."
 
963
        " The values must be equal for replication to work";
964
964
      err_code= ER_SLAVE_FATAL_ERROR;
965
965
      sprintf(err_buff, ER(err_code), errmsg);
966
966
      err_msg.append(err_buff);
967
967
    }
968
 
    drizzle_free_result(master_res);
 
968
    mysql_free_result(master_res);
969
969
 
970
970
    if (errmsg)
971
971
      goto err;
980
980
       the period is an uint64_t of nano-secs. 
981
981
    */
982
982
    llstr((uint64_t) (mi->heartbeat_period*1000000000UL), llbuf);
983
 
    sprintf(query, query_format, llbuf);
 
983
    my_sprintf(query, (query, query_format, llbuf));
984
984
 
985
 
    if (drizzle_real_query(drizzle, query, strlen(query))
 
985
    if (mysql_real_query(mysql, query, strlen(query))
986
986
        && !check_io_slave_killed(mi->io_thd, mi, NULL))
987
987
    {
988
988
      err_msg.append("The slave I/O thread stops because querying master with '");
989
989
      err_msg.append(query);
990
990
      err_msg.append("' failed;");
991
991
      err_msg.append(" error: ");
992
 
      err_code= drizzle_errno(drizzle);
 
992
      err_code= mysql_errno(mysql);
993
993
      err_msg.qs_append(err_code);
994
994
      err_msg.append("  '");
995
 
      err_msg.append(drizzle_error(drizzle));
 
995
      err_msg.append(mysql_error(mysql));
996
996
      err_msg.append("'");
997
 
      drizzle_free_result(drizzle_store_result(drizzle));
 
997
      mysql_free_result(mysql_store_result(mysql));
998
998
      goto err;
999
999
    }
1000
 
    drizzle_free_result(drizzle_store_result(drizzle));
 
1000
    mysql_free_result(mysql_store_result(mysql));
1001
1001
  }
1002
1002
  
1003
1003
err:
1023
1023
  pthread_mutex_lock(&rli->log_space_lock);
1024
1024
  save_proc_info= thd->enter_cond(&rli->log_space_cond,
1025
1025
                                  &rli->log_space_lock,
1026
 
                                  _("Waiting for the slave SQL thread "
1027
 
                                    "to free enough relay log space"));
 
1026
                                  "\
 
1027
Waiting for the slave SQL thread to free enough relay log space");
1028
1028
  while (rli->log_space_limit < rli->log_space_total &&
1029
1029
         !(slave_killed=io_slave_killed(thd,mi)) &&
1030
1030
         !rli->ignore_log_space_limit)
1047
1047
    ignored events' end position for the use of the slave SQL thread, by
1048
1048
    calling this function. Only that thread can call it (see assertion).
1049
1049
 */
1050
 
static void write_ignored_events_info_to_relay_log(THD *thd __attribute__((unused)),
 
1050
static void write_ignored_events_info_to_relay_log(THD *thd __attribute__((__unused__)),
1051
1051
                                                   Master_info *mi)
1052
1052
{
1053
1053
  Relay_log_info *rli= &mi->rli;
1069
1069
      if (unlikely(rli->relay_log.append(ev)))
1070
1070
        mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
1071
1071
                   ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
1072
 
                   _("failed to write a Rotate event"
1073
 
                     " to the relay log, SHOW SLAVE STATUS may be"
1074
 
                     " inaccurate"));
 
1072
                   "failed to write a Rotate event"
 
1073
                   " to the relay log, SHOW SLAVE STATUS may be"
 
1074
                   " inaccurate");
1075
1075
      rli->relay_log.harvest_bytes_written(&rli->log_space_total);
1076
1076
      if (flush_master_info(mi, 1))
1077
 
        sql_print_error(_("Failed to flush master info file"));
 
1077
        sql_print_error("Failed to flush master info file");
1078
1078
      delete ev;
1079
1079
    }
1080
1080
    else
1081
1081
      mi->report(ERROR_LEVEL, ER_SLAVE_CREATE_EVENT_FAILURE,
1082
1082
                 ER(ER_SLAVE_CREATE_EVENT_FAILURE),
1083
 
                 _("Rotate_event (out of memory?),"
1084
 
                   " SHOW SLAVE STATUS may be inaccurate"));
 
1083
                 "Rotate_event (out of memory?),"
 
1084
                 " SHOW SLAVE STATUS may be inaccurate");
1085
1085
  }
1086
1086
  else
1087
1087
    pthread_mutex_unlock(log_lock);
1089
1089
}
1090
1090
 
1091
1091
 
1092
 
int32_t register_slave_on_master(DRIZZLE *drizzle, Master_info *mi,
 
1092
int32_t register_slave_on_master(MYSQL* mysql, Master_info *mi,
1093
1093
                             bool *suppress_warnings)
1094
1094
{
1095
 
  unsigned char buf[1024], *pos= buf;
 
1095
  uchar buf[1024], *pos= buf;
1096
1096
  uint32_t report_host_len, report_user_len=0, report_password_len=0;
1097
1097
 
1098
1098
  *suppress_warnings= false;
1109
1109
    return(0);                                     // safety
1110
1110
 
1111
1111
  int4store(pos, server_id); pos+= 4;
1112
 
  pos= net_store_data(pos, (unsigned char*) report_host, report_host_len);
1113
 
  pos= net_store_data(pos, (unsigned char*) report_user, report_user_len);
1114
 
  pos= net_store_data(pos, (unsigned char*) report_password, report_password_len);
1115
 
  int2store(pos, (uint16_t) report_port); pos+= 2;
 
1112
  pos= net_store_data(pos, (uchar*) report_host, report_host_len);
 
1113
  pos= net_store_data(pos, (uchar*) report_user, report_user_len);
 
1114
  pos= net_store_data(pos, (uchar*) report_password, report_password_len);
 
1115
  int2store(pos, (uint16) report_port); pos+= 2;
1116
1116
  int4store(pos, rpl_recovery_rank);    pos+= 4;
1117
1117
  /* The master will fill in master_id */
1118
1118
  int4store(pos, 0);                    pos+= 4;
1119
1119
 
1120
 
  if (simple_command(drizzle, COM_REGISTER_SLAVE, buf, (size_t) (pos- buf), 0))
 
1120
  if (simple_command(mysql, COM_REGISTER_SLAVE, buf, (size_t) (pos- buf), 0))
1121
1121
  {
1122
 
    if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
 
1122
    if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1123
1123
    {
1124
1124
      *suppress_warnings= true;                 // Suppress reconnect warning
1125
1125
    }
1126
1126
    else if (!check_io_slave_killed(mi->io_thd, mi, NULL))
1127
1127
    {
1128
1128
      char buf[256];
1129
 
      snprintf(buf, sizeof(buf), "%s (Errno: %d)", drizzle_error(drizzle), 
1130
 
               drizzle_errno(drizzle));
 
1129
      snprintf(buf, sizeof(buf), "%s (Errno: %d)", mysql_error(mysql), 
 
1130
               mysql_errno(mysql));
1131
1131
      mi->report(ERROR_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
1132
1132
                 ER(ER_SLAVE_MASTER_COM_FAILURE), "COM_REGISTER_SLAVE", buf);
1133
1133
    }
1150
1150
  field_list.push_back(new Item_empty_string("Master_User",
1151
1151
                                                     sizeof(mi->user)));
1152
1152
  field_list.push_back(new Item_return_int("Master_Port", 7,
1153
 
                                           DRIZZLE_TYPE_LONG));
 
1153
                                           MYSQL_TYPE_LONG));
1154
1154
  field_list.push_back(new Item_return_int("Connect_Retry", 10,
1155
 
                                           DRIZZLE_TYPE_LONG));
 
1155
                                           MYSQL_TYPE_LONG));
1156
1156
  field_list.push_back(new Item_empty_string("Master_Log_File",
1157
1157
                                             FN_REFLEN));
1158
1158
  field_list.push_back(new Item_return_int("Read_Master_Log_Pos", 10,
1159
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1159
                                           MYSQL_TYPE_LONGLONG));
1160
1160
  field_list.push_back(new Item_empty_string("Relay_Log_File",
1161
1161
                                             FN_REFLEN));
1162
1162
  field_list.push_back(new Item_return_int("Relay_Log_Pos", 10,
1163
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1163
                                           MYSQL_TYPE_LONGLONG));
1164
1164
  field_list.push_back(new Item_empty_string("Relay_Master_Log_File",
1165
1165
                                             FN_REFLEN));
1166
1166
  field_list.push_back(new Item_empty_string("Slave_IO_Running", 3));
1172
1172
  field_list.push_back(new Item_empty_string("Replicate_Wild_Do_Table", 24));
1173
1173
  field_list.push_back(new Item_empty_string("Replicate_Wild_Ignore_Table",
1174
1174
                                             28));
1175
 
  field_list.push_back(new Item_return_int("Last_Errno", 4, DRIZZLE_TYPE_LONG));
 
1175
  field_list.push_back(new Item_return_int("Last_Errno", 4, MYSQL_TYPE_LONG));
1176
1176
  field_list.push_back(new Item_empty_string("Last_Error", 20));
1177
1177
  field_list.push_back(new Item_return_int("Skip_Counter", 10,
1178
 
                                           DRIZZLE_TYPE_LONG));
 
1178
                                           MYSQL_TYPE_LONG));
1179
1179
  field_list.push_back(new Item_return_int("Exec_Master_Log_Pos", 10,
1180
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1180
                                           MYSQL_TYPE_LONGLONG));
1181
1181
  field_list.push_back(new Item_return_int("Relay_Log_Space", 10,
1182
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1182
                                           MYSQL_TYPE_LONGLONG));
1183
1183
  field_list.push_back(new Item_empty_string("Until_Condition", 6));
1184
1184
  field_list.push_back(new Item_empty_string("Until_Log_File", FN_REFLEN));
1185
1185
  field_list.push_back(new Item_return_int("Until_Log_Pos", 10,
1186
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1186
                                           MYSQL_TYPE_LONGLONG));
1187
1187
  field_list.push_back(new Item_empty_string("Master_SSL_Allowed", 7));
1188
1188
  field_list.push_back(new Item_empty_string("Master_SSL_CA_File",
1189
1189
                                             sizeof(mi->ssl_ca)));
1196
1196
  field_list.push_back(new Item_empty_string("Master_SSL_Key",
1197
1197
                                             sizeof(mi->ssl_key)));
1198
1198
  field_list.push_back(new Item_return_int("Seconds_Behind_Master", 10,
1199
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1199
                                           MYSQL_TYPE_LONGLONG));
1200
1200
  field_list.push_back(new Item_empty_string("Master_SSL_Verify_Server_Cert",
1201
1201
                                             3));
1202
 
  field_list.push_back(new Item_return_int("Last_IO_Errno", 4, DRIZZLE_TYPE_LONG));
 
1202
  field_list.push_back(new Item_return_int("Last_IO_Errno", 4, MYSQL_TYPE_LONG));
1203
1203
  field_list.push_back(new Item_empty_string("Last_IO_Error", 20));
1204
 
  field_list.push_back(new Item_return_int("Last_SQL_Errno", 4, DRIZZLE_TYPE_LONG));
 
1204
  field_list.push_back(new Item_return_int("Last_SQL_Errno", 4, MYSQL_TYPE_LONG));
1205
1205
  field_list.push_back(new Item_empty_string("Last_SQL_Error", 20));
1206
1206
 
1207
1207
  if (protocol->send_fields(&field_list,
1218
1218
      non-volotile members like mi->io_thd, which is guarded by the mutex.
1219
1219
    */
1220
1220
    pthread_mutex_lock(&mi->run_lock);
1221
 
    protocol->store(mi->io_thd ? mi->io_thd->get_proc_info() : "", &my_charset_bin);
 
1221
    protocol->store(mi->io_thd ? mi->io_thd->proc_info : "", &my_charset_bin);
1222
1222
    pthread_mutex_unlock(&mi->run_lock);
1223
1223
 
1224
1224
    pthread_mutex_lock(&mi->data_lock);
1225
1225
    pthread_mutex_lock(&mi->rli.data_lock);
1226
1226
    protocol->store(mi->host, &my_charset_bin);
1227
1227
    protocol->store(mi->user, &my_charset_bin);
1228
 
    protocol->store((uint32_t) mi->port);
1229
 
    protocol->store((uint32_t) mi->connect_retry);
 
1228
    protocol->store((uint32) mi->port);
 
1229
    protocol->store((uint32) mi->connect_retry);
1230
1230
    protocol->store(mi->master_log_name, &my_charset_bin);
1231
1231
    protocol->store((uint64_t) mi->master_log_pos);
1232
1232
    protocol->store(mi->rli.group_relay_log_name +
1234
1234
                    &my_charset_bin);
1235
1235
    protocol->store((uint64_t) mi->rli.group_relay_log_pos);
1236
1236
    protocol->store(mi->rli.group_master_log_name, &my_charset_bin);
1237
 
    protocol->store(mi->slave_running == DRIZZLE_SLAVE_RUN_CONNECT ?
 
1237
    protocol->store(mi->slave_running == MYSQL_SLAVE_RUN_CONNECT ?
1238
1238
                    "Yes" : "No", &my_charset_bin);
1239
1239
    protocol->store(mi->rli.slave_running ? "Yes":"No", &my_charset_bin);
1240
1240
    protocol->store(rpl_filter->get_do_db());
1253
1253
 
1254
1254
    protocol->store(mi->rli.last_error().number);
1255
1255
    protocol->store(mi->rli.last_error().message, &my_charset_bin);
1256
 
    protocol->store((uint32_t) mi->rli.slave_skip_counter);
 
1256
    protocol->store((uint32) mi->rli.slave_skip_counter);
1257
1257
    protocol->store((uint64_t) mi->rli.group_master_log_pos);
1258
1258
    protocol->store((uint64_t) mi->rli.log_space_total);
1259
1259
 
1275
1275
      Seconds_Behind_Master: if SQL thread is running and I/O thread is
1276
1276
      connected, we can compute it otherwise show NULL (i.e. unknown).
1277
1277
    */
1278
 
    if ((mi->slave_running == DRIZZLE_SLAVE_RUN_CONNECT) &&
 
1278
    if ((mi->slave_running == MYSQL_SLAVE_RUN_CONNECT) &&
1279
1279
        mi->rli.slave_running)
1280
1280
    {
1281
1281
      long time_diff= ((long)(time(0) - mi->rli.last_master_timestamp)
1295
1295
        slave is 2. At SHOW SLAVE STATUS time, assume that the difference
1296
1296
        between timestamp of slave and rli->last_master_timestamp is 0
1297
1297
        (i.e. they are in the same second), then we get 0-(2-1)=-1 as a result.
1298
 
        This confuses users, so we don't go below 0: hence the cmax().
 
1298
        This confuses users, so we don't go below 0: hence the max().
1299
1299
 
1300
1300
        last_master_timestamp == 0 (an "impossible" timestamp 1970) is a
1301
1301
        special marker to say "consider we have caught up".
1302
1302
      */
1303
1303
      protocol->store((int64_t)(mi->rli.last_master_timestamp ?
1304
 
                                 cmax((long)0, time_diff) : 0));
 
1304
                                 max(0, time_diff) : 0));
1305
1305
    }
1306
1306
    else
1307
1307
    {
1321
1321
    pthread_mutex_unlock(&mi->rli.data_lock);
1322
1322
    pthread_mutex_unlock(&mi->data_lock);
1323
1323
 
1324
 
    if (my_net_write(&thd->net, (unsigned char*) thd->packet.ptr(), packet->length()))
 
1324
    if (my_net_write(&thd->net, (uchar*) thd->packet.ptr(), packet->length()))
1325
1325
      return(true);
1326
1326
  }
1327
1327
  my_eof(thd);
1445
1445
}
1446
1446
 
1447
1447
 
1448
 
static int32_t request_dump(DRIZZLE *drizzle, Master_info* mi,
 
1448
static int32_t request_dump(MYSQL* mysql, Master_info* mi,
1449
1449
                        bool *suppress_warnings)
1450
1450
{
1451
 
  unsigned char buf[FN_REFLEN + 10];
 
1451
  uchar buf[FN_REFLEN + 10];
1452
1452
  int32_t len;
1453
1453
  int32_t binlog_flags = 0; // for now
1454
1454
  char* logname = mi->master_log_name;
1461
1461
  int4store(buf + 6, server_id);
1462
1462
  len = (uint32_t) strlen(logname);
1463
1463
  memcpy(buf + 10, logname,len);
1464
 
  if (simple_command(drizzle, COM_BINLOG_DUMP, buf, len + 10, 1))
 
1464
  if (simple_command(mysql, COM_BINLOG_DUMP, buf, len + 10, 1))
1465
1465
  {
1466
1466
    /*
1467
1467
      Something went wrong, so we will just reconnect and retry later
1468
1468
      in the future, we should do a better error analysis, but for
1469
1469
      now we just fill up the error log :-)
1470
1470
    */
1471
 
    if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
 
1471
    if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1472
1472
      *suppress_warnings= true;                 // Suppress reconnect warning
1473
1473
    else
1474
 
      sql_print_error(_("Error on COM_BINLOG_DUMP: %d  %s, will retry in %d secs"),
1475
 
                      drizzle_errno(drizzle), drizzle_error(drizzle),
 
1474
      sql_print_error("Error on COM_BINLOG_DUMP: %d  %s, will retry in %d secs",
 
1475
                      mysql_errno(mysql), mysql_error(mysql),
1476
1476
                      mi->connect_retry);
1477
1477
    return(1);
1478
1478
  }
1485
1485
 
1486
1486
  SYNOPSIS
1487
1487
    read_event()
1488
 
    DRIZZLE               DRIZZLE connection
 
1488
    mysql               MySQL connection
1489
1489
    mi                  Master connection information
1490
1490
    suppress_warnings   TRUE when a normal net read timeout has caused us to
1491
1491
                        try a reconnect.  We do not want to print anything to
1497
1497
    number              Length of packet
1498
1498
*/
1499
1499
 
1500
 
static uint32_t read_event(DRIZZLE *drizzle,
1501
 
                        Master_info *mi __attribute__((unused)),
 
1500
static uint32_t read_event(MYSQL* mysql,
 
1501
                        Master_info *mi __attribute__((__unused__)),
1502
1502
                        bool* suppress_warnings)
1503
1503
{
1504
1504
  uint32_t len;
1511
1511
  if (disconnect_slave_event_count && !(mi->events_till_disconnect--))
1512
1512
    return(packet_error);
1513
1513
 
1514
 
  len = cli_safe_read(drizzle);
 
1514
  len = cli_safe_read(mysql);
1515
1515
  if (len == packet_error || (int32_t) len < 1)
1516
1516
  {
1517
 
    if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
 
1517
    if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1518
1518
    {
1519
1519
      /*
1520
1520
        We are trying a normal reconnect after a read timeout;
1524
1524
      *suppress_warnings= true;
1525
1525
    }
1526
1526
    else
1527
 
      sql_print_error(_("Error reading packet from server: %s ( server_errno=%d)"),
1528
 
                      drizzle_error(drizzle), drizzle_errno(drizzle));
 
1527
      sql_print_error("Error reading packet from server: %s ( server_errno=%d)",
 
1528
                      mysql_error(mysql), mysql_errno(mysql));
1529
1529
    return(packet_error);
1530
1530
  }
1531
1531
 
1532
1532
  /* Check if eof packet */
1533
 
  if (len < 8 && drizzle->net.read_pos[0] == 254)
 
1533
  if (len < 8 && mysql->net.read_pos[0] == 254)
1534
1534
  {
1535
 
    sql_print_information(_("Slave: received end packet from server, apparent "
1536
 
                            "master shutdown: %s"),
1537
 
                     drizzle_error(drizzle));
 
1535
    sql_print_information("Slave: received end packet from server, apparent "
 
1536
                          "master shutdown: %s",
 
1537
                     mysql_error(mysql));
1538
1538
     return(packet_error);
1539
1539
  }
1540
1540
 
1542
1542
}
1543
1543
 
1544
1544
 
1545
 
int32_t check_expected_error(THD* thd __attribute__((unused)),
1546
 
                         Relay_log_info const *rli __attribute__((unused)),
 
1545
int32_t check_expected_error(THD* thd __attribute__((__unused__)),
 
1546
                         Relay_log_info const *rli __attribute__((__unused__)),
1547
1547
                         int32_t expected_error)
1548
1548
{
1549
1549
  switch (expected_error) {
1686
1686
    {
1687
1687
      char buf[22];
1688
1688
      rli->report(ERROR_LEVEL, ER_UNKNOWN_ERROR,
1689
 
                  _("It was not possible to update the positions"
 
1689
                  "It was not possible to update the positions"
1690
1690
                  " of the relay log information: the slave may"
1691
1691
                  " be in an inconsistent state."
1692
 
                  " Stopped in %s position %s"),
 
1692
                  " Stopped in %s position %s",
1693
1693
                  rli->group_relay_log_name,
1694
1694
                  llstr(rli->group_relay_log_pos, buf));
1695
1695
      return(2);
1761
1761
                                ev->log_pos - ev->data_written))
1762
1762
    {
1763
1763
      char buf[22];
1764
 
      sql_print_information(_("Slave SQL thread stopped because it reached its"
1765
 
                              " UNTIL position %s"),
1766
 
                            llstr(rli->until_pos(), buf));
 
1764
      sql_print_information("Slave SQL thread stopped because it reached its"
 
1765
                            " UNTIL position %s", llstr(rli->until_pos(), buf));
1767
1766
      /*
1768
1767
        Setting abort_slave flag because we do not want additional message about
1769
1768
        error in query execution to be printed.
1815
1814
        if (rli->trans_retries < slave_trans_retries)
1816
1815
        {
1817
1816
          if (init_master_info(rli->mi, 0, 0, 0, SLAVE_SQL))
1818
 
            sql_print_error(_("Failed to initialize the master info structure"));
 
1817
            sql_print_error("Failed to initialize the master info structure");
1819
1818
          else if (init_relay_log_pos(rli,
1820
1819
                                      rli->group_relay_log_name,
1821
1820
                                      rli->group_relay_log_pos,
1822
1821
                                      1, &errmsg, 1))
1823
 
            sql_print_error(_("Error initializing relay log position: %s"),
 
1822
            sql_print_error("Error initializing relay log position: %s",
1824
1823
                            errmsg);
1825
1824
          else
1826
1825
          {
1827
1826
            exec_res= 0;
1828
1827
            end_trans(thd, ROLLBACK);
1829
1828
            /* chance for concurrent connection to get more locks */
1830
 
            safe_sleep(thd, cmin(rli->trans_retries, (uint32_t)MAX_SLAVE_RETRY_PAUSE),
 
1829
            safe_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
1831
1830
                       (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);
1832
1831
            pthread_mutex_lock(&rli->data_lock); // because of SHOW STATUS
1833
1832
            rli->trans_retries++;
1836
1835
          }
1837
1836
        }
1838
1837
        else
1839
 
          sql_print_error(_("Slave SQL thread retried transaction %lu time(s) "
1840
 
                            "in vain, giving up. Consider raising the value of "
1841
 
                            "the slave_transaction_retries variable."),
 
1838
          sql_print_error("Slave SQL thread retried transaction %lu time(s) "
 
1839
                          "in vain, giving up. Consider raising the value of "
 
1840
                          "the slave_transaction_retries variable.",
1842
1841
                          slave_trans_retries);
1843
1842
      }
1844
1843
      else if ((exec_res && !temp_err) ||
1858
1857
  }
1859
1858
  pthread_mutex_unlock(&rli->data_lock);
1860
1859
  rli->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_READ_FAILURE,
1861
 
              ER(ER_SLAVE_RELAY_LOG_READ_FAILURE),
1862
 
              _("Could not parse relay log event entry. The possible reasons "
1863
 
                "are: the master's binary log is corrupted (you can check this "
1864
 
                "by running 'mysqlbinlog' on the binary log), the slave's "
1865
 
                "relay log is corrupted (you can check this by running "
1866
 
                "'mysqlbinlog' on the relay log), a network problem, or a bug "
1867
 
                "in the master's or slave's DRIZZLE code. If you want to check "
1868
 
                "the master's binary log or slave's relay log, you will be "
1869
 
                "able to know their names by issuing 'SHOW SLAVE STATUS' "
1870
 
                "on this slave."));
 
1860
              ER(ER_SLAVE_RELAY_LOG_READ_FAILURE), "\
 
1861
Could not parse relay log event entry. The possible reasons are: the master's \
 
1862
binary log is corrupted (you can check this by running 'mysqlbinlog' on the \
 
1863
binary log), the slave's relay log is corrupted (you can check this by running \
 
1864
'mysqlbinlog' on the relay log), a network problem, or a bug in the master's \
 
1865
or slave's MySQL code. If you want to check the master's binary log or slave's \
 
1866
relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' \
 
1867
on this slave.\
 
1868
");
1871
1869
  return(1);
1872
1870
}
1873
1871
 
1886
1884
  no messages are added to the log.
1887
1885
 
1888
1886
  @param[in]     thd                 Thread context.
1889
 
  @param[in]     DRIZZLE               DRIZZLE connection.
 
1887
  @param[in]     mysql               MySQL connection.
1890
1888
  @param[in]     mi                  Master connection information.
1891
1889
  @param[in,out] retry_count         Number of attempts to reconnect.
1892
1890
  @param[in]     suppress_warnings   TRUE when a normal net read timeout 
1898
1896
  @retval        1                   There was an error.
1899
1897
*/
1900
1898
 
1901
 
static int32_t try_to_reconnect(THD *thd, DRIZZLE *drizzle, Master_info *mi,
1902
 
                                uint32_t *retry_count, bool suppress_warnings,
1903
 
                                const char *messages[SLAVE_RECON_MSG_MAX])
 
1899
static int32_t try_to_reconnect(THD *thd, MYSQL *mysql, Master_info *mi,
 
1900
                            uint32_t *retry_count, bool suppress_warnings,
 
1901
                            const char *messages[SLAVE_RECON_MSG_MAX])
1904
1902
{
1905
 
  mi->slave_running= DRIZZLE_SLAVE_RUN_NOT_CONNECT;
1906
 
  thd->set_proc_info(_(messages[SLAVE_RECON_MSG_WAIT]));
1907
 
  drizzle_disconnect(drizzle);
 
1903
  mi->slave_running= MYSQL_SLAVE_RUN_NOT_CONNECT;
 
1904
  thd->proc_info= messages[SLAVE_RECON_MSG_WAIT];
 
1905
#ifdef SIGNAL_WITH_VIO_CLOSE  
 
1906
  thd->clear_active_vio();
 
1907
#endif
 
1908
  end_server(mysql);
1908
1909
  if ((*retry_count)++)
1909
1910
  {
1910
1911
    if (*retry_count > master_retry_count)
1912
1913
    safe_sleep(thd, mi->connect_retry, (CHECK_KILLED_FUNC) io_slave_killed,
1913
1914
               (void *) mi);
1914
1915
  }
1915
 
  if (check_io_slave_killed(thd, mi,
1916
 
                            _(messages[SLAVE_RECON_MSG_KILLED_WAITING])))
 
1916
  if (check_io_slave_killed(thd, mi, messages[SLAVE_RECON_MSG_KILLED_WAITING]))
1917
1917
    return 1;
1918
 
  thd->set_proc_info(_(messages[SLAVE_RECON_MSG_AFTER]));
1919
 
  if (!suppress_warnings)
 
1918
  thd->proc_info = messages[SLAVE_RECON_MSG_AFTER];
 
1919
  if (!suppress_warnings) 
1920
1920
  {
1921
1921
    char buf[256], llbuff[22];
1922
 
    snprintf(buf, sizeof(buf), _(messages[SLAVE_RECON_MSG_FAILED]),
 
1922
    snprintf(buf, sizeof(buf), messages[SLAVE_RECON_MSG_FAILED], 
1923
1923
             IO_RPL_LOG_NAME, llstr(mi->master_log_pos, llbuff));
1924
 
    /*
 
1924
    /* 
1925
1925
      Raise a warining during registering on master/requesting dump.
1926
1926
      Log a message reading event.
1927
1927
    */
1928
 
    if (_(messages[SLAVE_RECON_MSG_COMMAND])[0])
 
1928
    if (messages[SLAVE_RECON_MSG_COMMAND][0])
1929
1929
    {
1930
1930
      mi->report(WARNING_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
1931
 
                 ER(ER_SLAVE_MASTER_COM_FAILURE),
1932
 
                 _(messages[SLAVE_RECON_MSG_COMMAND]), buf);
 
1931
                 ER(ER_SLAVE_MASTER_COM_FAILURE), 
 
1932
                 messages[SLAVE_RECON_MSG_COMMAND], buf);
1933
1933
    }
1934
1934
    else
1935
1935
    {
1936
1936
      sql_print_information(buf);
1937
1937
    }
1938
1938
  }
1939
 
  if (safe_reconnect(thd, drizzle, mi, 1) || io_slave_killed(thd, mi))
 
1939
  if (safe_reconnect(thd, mysql, mi, 1) || io_slave_killed(thd, mi))
1940
1940
  {
1941
1941
    if (global_system_variables.log_warnings)
1942
 
      sql_print_information(_(messages[SLAVE_RECON_MSG_KILLED_AFTER]));
 
1942
      sql_print_information(messages[SLAVE_RECON_MSG_KILLED_AFTER]);
1943
1943
    return 1;
1944
1944
  }
1945
1945
  return 0;
1951
1951
pthread_handler_t handle_slave_io(void *arg)
1952
1952
{
1953
1953
  THD *thd; // needs to be first for thread_stack
1954
 
  DRIZZLE *drizzle;
 
1954
  MYSQL *mysql;
1955
1955
  Master_info *mi = (Master_info*)arg;
1956
1956
  Relay_log_info *rli= &mi->rli;
1957
1957
  char llbuff[22];
1961
1961
  my_thread_init();
1962
1962
 
1963
1963
  assert(mi->inited);
1964
 
  drizzle= NULL ;
 
1964
  mysql= NULL ;
1965
1965
  retry_count= 0;
1966
1966
 
1967
1967
  pthread_mutex_lock(&mi->run_lock);
1980
1980
  {
1981
1981
    pthread_cond_broadcast(&mi->start_cond);
1982
1982
    pthread_mutex_unlock(&mi->run_lock);
1983
 
    sql_print_error(_("Failed during slave I/O thread initialization"));
 
1983
    sql_print_error("Failed during slave I/O thread initialization");
1984
1984
    goto err;
1985
1985
  }
1986
1986
  pthread_mutex_lock(&LOCK_thread_count);
1991
1991
  pthread_mutex_unlock(&mi->run_lock);
1992
1992
  pthread_cond_broadcast(&mi->start_cond);
1993
1993
 
1994
 
  if (!(mi->drizzle= drizzle = drizzle_create(NULL)))
 
1994
  if (!(mi->mysql = mysql = mysql_init(NULL)))
1995
1995
  {
1996
1996
    mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
1997
 
               ER(ER_SLAVE_FATAL_ERROR), _("error in drizzle_create()"));
 
1997
               ER(ER_SLAVE_FATAL_ERROR), "error in mysql_init()");
1998
1998
    goto err;
1999
1999
  }
2000
2000
 
2001
2001
  thd_proc_info(thd, "Connecting to master");
2002
2002
  // we can get killed during safe_connect
2003
 
  if (!safe_connect(thd, drizzle, mi))
 
2003
  if (!safe_connect(thd, mysql, mi))
2004
2004
  {
2005
 
    sql_print_information(_("Slave I/O thread: connected to master '%s@%s:%d',"
2006
 
                            "replication started in log '%s' at position %s"),
 
2005
    sql_print_information("Slave I/O thread: connected to master '%s@%s:%d',"
 
2006
                          "replication started in log '%s' at position %s",
2007
2007
                          mi->user, mi->host, mi->port,
2008
2008
                          IO_RPL_LOG_NAME,
2009
2009
                          llstr(mi->master_log_pos,llbuff));
2012
2012
    thread, since a replication event can become this much larger than
2013
2013
    the corresponding packet (query) sent from client to master.
2014
2014
  */
2015
 
    drizzle->net.max_packet_size= thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER;
 
2015
    mysql->net.max_packet_size= thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER;
2016
2016
  }
2017
2017
  else
2018
2018
  {
2019
 
    sql_print_information(_("Slave I/O thread killed while connecting to master"));
 
2019
    sql_print_information("Slave I/O thread killed while connecting to master");
2020
2020
    goto err;
2021
2021
  }
2022
2022
 
2023
2023
connected:
2024
2024
 
2025
2025
  // TODO: the assignment below should be under mutex (5.0)
2026
 
  mi->slave_running= DRIZZLE_SLAVE_RUN_CONNECT;
2027
 
  thd->slave_net = &drizzle->net;
 
2026
  mi->slave_running= MYSQL_SLAVE_RUN_CONNECT;
 
2027
  thd->slave_net = &mysql->net;
2028
2028
  thd_proc_info(thd, "Checking master version");
2029
 
  if (get_master_version_and_clock(drizzle, mi))
 
2029
  if (get_master_version_and_clock(mysql, mi))
2030
2030
    goto err;
2031
 
  
 
2031
 
2032
2032
  if (mi->rli.relay_log.description_event_for_queue->binlog_version > 1)
2033
2033
  {
2034
2034
    /*
2035
2035
      Register ourselves with the master.
2036
2036
    */
2037
2037
    thd_proc_info(thd, "Registering slave on master");
2038
 
    if (register_slave_on_master(drizzle, mi, &suppress_warnings))
 
2038
    if (register_slave_on_master(mysql, mi, &suppress_warnings))
2039
2039
    {
2040
2040
      if (!check_io_slave_killed(thd, mi, "Slave I/O thread killed "
2041
 
                                 "while registering slave on master"))
 
2041
                                "while registering slave on master"))
2042
2042
      {
2043
 
        sql_print_error(_("Slave I/O thread couldn't register on master"));
2044
 
        if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
 
2043
        sql_print_error("Slave I/O thread couldn't register on master");
 
2044
        if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2045
2045
                             reconnect_messages[SLAVE_RECON_ACT_REG]))
2046
2046
          goto err;
2047
2047
      }
2052
2052
    if (!retry_count_reg)
2053
2053
    {
2054
2054
      retry_count_reg++;
2055
 
      sql_print_information(_("Forcing to reconnect slave I/O thread"));
2056
 
      if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2057
 
                           reconnect_messages[SLAVE_RECON_ACT_REG]))
 
2055
      sql_print_information("Forcing to reconnect slave I/O thread");
 
2056
      if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
 
2057
                         reconnect_messages[SLAVE_RECON_ACT_REG]))
2058
2058
        goto err;
2059
2059
      goto connected;
2060
2060
    }
2063
2063
  while (!io_slave_killed(thd,mi))
2064
2064
  {
2065
2065
    thd_proc_info(thd, "Requesting binlog dump");
2066
 
    if (request_dump(drizzle, mi, &suppress_warnings))
 
2066
    if (request_dump(mysql, mi, &suppress_warnings))
2067
2067
    {
2068
 
      sql_print_error(_("Failed on request_dump()"));
2069
 
      if (check_io_slave_killed(thd, mi, _("Slave I/O thread killed while \
2070
 
requesting master dump")) ||
2071
 
          try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
 
2068
      sql_print_error("Failed on request_dump()");
 
2069
      if (check_io_slave_killed(thd, mi, "Slave I/O thread killed while \
 
2070
requesting master dump") ||
 
2071
          try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2072
2072
                           reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2073
2073
        goto err;
2074
2074
      goto connected;
2076
2076
    if (!retry_count_dump)
2077
2077
    {
2078
2078
      retry_count_dump++;
2079
 
      sql_print_information(_("Forcing to reconnect slave I/O thread"));
2080
 
      if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
 
2079
      sql_print_information("Forcing to reconnect slave I/O thread");
 
2080
      if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2081
2081
                           reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2082
2082
        goto err;
2083
2083
      goto connected;
2087
2087
    {
2088
2088
      uint32_t event_len;
2089
2089
      /*
2090
 
        We say "waiting" because read_event() will wait if there's nothing to
2091
 
        read. But if there's something to read, it will not wait. The
2092
 
        important thing is to not confuse users by saying "reading" whereas
2093
 
        we're in fact receiving nothing.
 
2090
         We say "waiting" because read_event() will wait if there's nothing to
 
2091
         read. But if there's something to read, it will not wait. The
 
2092
         important thing is to not confuse users by saying "reading" whereas
 
2093
         we're in fact receiving nothing.
2094
2094
      */
2095
 
      thd_proc_info(thd, _("Waiting for master to send event"));
2096
 
      event_len= read_event(drizzle, mi, &suppress_warnings);
2097
 
      if (check_io_slave_killed(thd, mi, _("Slave I/O thread killed while "
2098
 
                                           "reading event")))
 
2095
      thd_proc_info(thd, "Waiting for master to send event");
 
2096
      event_len= read_event(mysql, mi, &suppress_warnings);
 
2097
      if (check_io_slave_killed(thd, mi, "Slave I/O thread killed while \
 
2098
reading event"))
2099
2099
        goto err;
2100
2100
      if (!retry_count_event)
2101
2101
      {
2102
2102
        retry_count_event++;
2103
 
        sql_print_information(_("Forcing to reconnect slave I/O thread"));
2104
 
        if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
 
2103
        sql_print_information("Forcing to reconnect slave I/O thread");
 
2104
        if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2105
2105
                             reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2106
2106
          goto err;
2107
2107
        goto connected;
2109
2109
 
2110
2110
      if (event_len == packet_error)
2111
2111
      {
2112
 
        uint32_t drizzle_error_number= drizzle_errno(drizzle);
2113
 
        switch (drizzle_error_number) {
 
2112
        uint32_t mysql_error_number= mysql_errno(mysql);
 
2113
        switch (mysql_error_number) {
2114
2114
        case CR_NET_PACKET_TOO_LARGE:
2115
 
          sql_print_error(_("Log entry on master is longer than "
2116
 
                            "max_allowed_packet (%ld) on "
2117
 
                            "slave. If the entry is correct, restart the "
2118
 
                            "server with a higher value of "
2119
 
                            "max_allowed_packet"),
 
2115
          sql_print_error("\
 
2116
Log entry on master is longer than max_allowed_packet (%ld) on \
 
2117
slave. If the entry is correct, restart the server with a higher value of \
 
2118
max_allowed_packet",
2120
2119
                          thd->variables.max_allowed_packet);
2121
2120
          goto err;
2122
2121
        case ER_MASTER_FATAL_ERROR_READING_BINLOG:
2123
 
          sql_print_error(ER(drizzle_error_number), drizzle_error_number,
2124
 
                          drizzle_error(drizzle));
 
2122
          sql_print_error(ER(mysql_error_number), mysql_error_number,
 
2123
                          mysql_error(mysql));
2125
2124
          goto err;
2126
2125
        case EE_OUTOFMEMORY:
2127
2126
        case ER_OUTOFMEMORY:
2128
 
          sql_print_error(
2129
 
       _("Stopping slave I/O thread due to out-of-memory error from master"));
 
2127
          sql_print_error("\
 
2128
Stopping slave I/O thread due to out-of-memory error from master");
2130
2129
          goto err;
2131
2130
        }
2132
 
        if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
 
2131
        if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2133
2132
                             reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2134
2133
          goto err;
2135
2134
        goto connected;
2136
2135
      } // if (event_len == packet_error)
2137
2136
 
2138
2137
      retry_count=0;                    // ok event, reset retry counter
2139
 
      thd_proc_info(thd, _("Queueing master event to the relay log"));
2140
 
      if (queue_event(mi,(const char*)drizzle->net.read_pos + 1, event_len))
 
2138
      thd_proc_info(thd, "Queueing master event to the relay log");
 
2139
      if (queue_event(mi,(const char*)mysql->net.read_pos + 1, event_len))
2141
2140
      {
2142
2141
        goto err;
2143
2142
      }
2144
2143
      if (flush_master_info(mi, 1))
2145
2144
      {
2146
 
        sql_print_error(_("Failed to flush master info file"));
 
2145
        sql_print_error("Failed to flush master info file");
2147
2146
        goto err;
2148
2147
      }
2149
2148
      /*
2163
2162
          !rli->ignore_log_space_limit)
2164
2163
        if (wait_for_relay_log_space(rli))
2165
2164
        {
2166
 
          sql_print_error(_("Slave I/O thread aborted while waiting for "
2167
 
                            "relay log space"));
 
2165
          sql_print_error("Slave I/O thread aborted while waiting for relay \
 
2166
log space");
2168
2167
          goto err;
2169
2168
        }
2170
2169
    }
2171
2170
  }
2172
2171
 
2173
 
// error = 0;
 
2172
  // error = 0;
2174
2173
err:
2175
 
// print the current replication position
2176
 
  sql_print_information(_("Slave I/O thread exiting, read up to log '%s', "
2177
 
                          "position %s"),
2178
 
                        IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
2179
 
  pthread_mutex_lock(&LOCK_thread_count);
 
2174
  // print the current replication position
 
2175
  sql_print_information("Slave I/O thread exiting, read up to log '%s', position %s",
 
2176
                  IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
 
2177
  VOID(pthread_mutex_lock(&LOCK_thread_count));
2180
2178
  thd->query = thd->db = 0; // extra safety
2181
2179
  thd->query_length= thd->db_length= 0;
2182
 
  pthread_mutex_unlock(&LOCK_thread_count);
2183
 
  if (drizzle)
 
2180
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
2181
  if (mysql)
2184
2182
  {
2185
2183
    /*
2186
2184
      Here we need to clear the active VIO before closing the
2190
2188
      can be called in the middle of closing the VIO associated with
2191
2189
      the 'mysql' object, causing a crash.
2192
2190
    */
2193
 
    drizzle_close(drizzle);
2194
 
    mi->drizzle=0;
 
2191
#ifdef SIGNAL_WITH_VIO_CLOSE
 
2192
    thd->clear_active_vio();
 
2193
#endif
 
2194
    mysql_close(mysql);
 
2195
    mi->mysql=0;
2195
2196
  }
2196
2197
  write_ignored_events_info_to_relay_log(thd, mi);
2197
 
  thd_proc_info(thd, _("Waiting for slave mutex on exit"));
 
2198
  thd_proc_info(thd, "Waiting for slave mutex on exit");
2198
2199
  pthread_mutex_lock(&mi->run_lock);
2199
2200
 
2200
2201
  /* Forget the relay log's format */
2260
2261
    */
2261
2262
    pthread_cond_broadcast(&rli->start_cond);
2262
2263
    pthread_mutex_unlock(&rli->run_lock);
2263
 
    sql_print_error(_("Failed during slave thread initialization"));
 
2264
    sql_print_error("Failed during slave thread initialization");
2264
2265
    goto err;
2265
2266
  }
2266
2267
  thd->init_for_queries();
2304
2305
                         1 /*need data lock*/, &errmsg,
2305
2306
                         1 /*look for a description_event*/))
2306
2307
  {
2307
 
    sql_print_error(_("Error initializing relay log position: %s"),
 
2308
    sql_print_error("Error initializing relay log position: %s",
2308
2309
                    errmsg);
2309
2310
    goto err;
2310
2311
  }
2326
2327
  assert(rli->sql_thd == thd);
2327
2328
 
2328
2329
  if (global_system_variables.log_warnings)
2329
 
    sql_print_information(_("Slave SQL thread initialized, "
2330
 
                            "starting replication in log '%s' at "
2331
 
                            "position %s, relay log '%s' position: %s"),
2332
 
                            RPL_LOG_NAME,
2333
 
                          llstr(rli->group_master_log_pos,llbuff),
2334
 
                          rli->group_relay_log_name,
2335
 
                          llstr(rli->group_relay_log_pos,llbuff1));
 
2330
    sql_print_information("Slave SQL thread initialized, starting replication in \
 
2331
log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME,
 
2332
                    llstr(rli->group_master_log_pos,llbuff),rli->group_relay_log_name,
 
2333
                    llstr(rli->group_relay_log_pos,llbuff1));
2336
2334
 
2337
2335
  /* execute init_slave variable */
2338
2336
  if (sys_init_slave.value_length)
2340
2338
    execute_init_command(thd, &sys_init_slave, &LOCK_sys_init_slave);
2341
2339
    if (thd->is_slave_error)
2342
2340
    {
2343
 
      sql_print_error(_("Slave SQL thread aborted. "
2344
 
                        "Can't execute init_slave query"));
 
2341
      sql_print_error("\
 
2342
Slave SQL thread aborted. Can't execute init_slave query");
2345
2343
      goto err;
2346
2344
    }
2347
2345
  }
2355
2353
      rli->is_until_satisfied(rli->group_master_log_pos))
2356
2354
  {
2357
2355
    char buf[22];
2358
 
    sql_print_information(_("Slave SQL thread stopped because it reached its"
2359
 
                            " UNTIL position %s"), llstr(rli->until_pos(), buf));
 
2356
    sql_print_information("Slave SQL thread stopped because it reached its"
 
2357
                          " UNTIL position %s", llstr(rli->until_pos(), buf));
2360
2358
    pthread_mutex_unlock(&rli->data_lock);
2361
2359
    goto err;
2362
2360
  }
2366
2364
 
2367
2365
  while (!sql_slave_killed(thd,rli))
2368
2366
  {
2369
 
    thd_proc_info(thd, _("Reading event from the relay log"));
 
2367
    thd_proc_info(thd, "Reading event from the relay log");
2370
2368
    assert(rli->sql_thd == thd);
2371
2369
    THD_CHECK_SENTRY(thd);
2372
2370
    if (exec_relay_log_event(thd,rli))
2379
2377
          codes and warnings and print this to the error log as to
2380
2378
          allow the user to locate the error
2381
2379
        */
2382
 
        uint32_t const last_errno= rli->last_error().number;
 
2380
        uint32 const last_errno= rli->last_error().number;
2383
2381
 
2384
2382
        if (thd->is_error())
2385
2383
        {
2391
2389
          }
2392
2390
          else if (last_errno != thd->main_da.sql_errno())
2393
2391
          {
2394
 
            sql_print_error(_("Slave (additional info): %s Error_code: %d"),
 
2392
            sql_print_error("Slave (additional info): %s Error_code: %d",
2395
2393
                            errmsg, thd->main_da.sql_errno());
2396
2394
          }
2397
2395
        }
2398
2396
 
2399
2397
        /* Print any warnings issued */
2400
 
        List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
2401
 
        DRIZZLE_ERROR *err;
 
2398
        List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
 
2399
        MYSQL_ERROR *err;
2402
2400
        /*
2403
2401
          Added controlled slave thread cancel for replication
2404
2402
          of user-defined variables.
2408
2406
        {
2409
2407
          if (err->code == ER_CANT_OPEN_LIBRARY)
2410
2408
            udf_error = true;
2411
 
          sql_print_warning(_("Slave: %s Error_code: %d"),err->msg, err->code);
 
2409
          sql_print_warning("Slave: %s Error_code: %d",err->msg, err->code);
2412
2410
        }
2413
2411
        if (udf_error)
2414
 
          sql_print_error(_("Error loading user-defined library, slave SQL "
2415
 
                            "thread aborted. Install the missing library, "
2416
 
                            "and restart the slave SQL thread with "
2417
 
                            "\"SLAVE START\". We stopped at log '%s' "
2418
 
                            "position %s"),
2419
 
                          RPL_LOG_NAME, llstr(rli->group_master_log_pos,
 
2412
          sql_print_error("Error loading user-defined library, slave SQL "
 
2413
            "thread aborted. Install the missing library, and restart the "
 
2414
            "slave SQL thread with \"SLAVE START\". We stopped at log '%s' "
 
2415
            "position %s", RPL_LOG_NAME, llstr(rli->group_master_log_pos, 
2420
2416
            llbuff));
2421
2417
        else
2422
 
          sql_print_error(_("Error running query, slave SQL thread aborted. "
2423
 
                            "Fix the problem, and restart "
2424
 
                            "the slave SQL thread with \"SLAVE START\". "
2425
 
                            "We stopped at log '%s' position %s"),
2426
 
                          RPL_LOG_NAME,
2427
 
                          llstr(rli->group_master_log_pos, llbuff));
 
2418
        sql_print_error("\
 
2419
Error running query, slave SQL thread aborted. Fix the problem, and restart \
 
2420
the slave SQL thread with \"SLAVE START\". We stopped at log \
 
2421
'%s' position %s", RPL_LOG_NAME, llstr(rli->group_master_log_pos, llbuff));
2428
2422
      }
2429
2423
      goto err;
2430
2424
    }
2431
2425
  }
2432
2426
 
2433
2427
  /* Thread stopped. Print the current replication position to the log */
2434
 
  sql_print_information(_("Slave SQL thread exiting, replication stopped in "
2435
 
                          "log '%s' at position %s"),
2436
 
                        RPL_LOG_NAME,
2437
 
                        llstr(rli->group_master_log_pos,llbuff));
 
2428
  sql_print_information("Slave SQL thread exiting, replication stopped in log "
 
2429
                        "'%s' at position %s",
 
2430
                        RPL_LOG_NAME, llstr(rli->group_master_log_pos,llbuff));
2438
2431
 
2439
2432
 err:
2440
2433
 
2445
2438
    must "proactively" clear playgrounds:
2446
2439
  */
2447
2440
  rli->cleanup_context(thd, 1);
2448
 
  pthread_mutex_lock(&LOCK_thread_count);
 
2441
  VOID(pthread_mutex_lock(&LOCK_thread_count));
2449
2442
  /*
2450
2443
    Some extra safety, which should not been needed (normally, event deletion
2451
2444
    should already have done these assignments (each event which sets these
2453
2446
  */
2454
2447
  thd->query= thd->db= thd->catalog= 0;
2455
2448
  thd->query_length= thd->db_length= 0;
2456
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
2449
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
2457
2450
  thd_proc_info(thd, "Waiting for slave mutex on exit");
2458
2451
  pthread_mutex_lock(&rli->run_lock);
2459
2452
  /* We need data_lock, at least to wake up any waiting master_pos_wait() */
2510
2503
  uint32_t num_bytes;
2511
2504
  bool cev_not_written;
2512
2505
  THD *thd = mi->io_thd;
2513
 
  NET *net = &mi->drizzle->net;
 
2506
  NET *net = &mi->mysql->net;
2514
2507
 
2515
2508
  if (unlikely(!cev->is_valid()))
2516
2509
    return(1);
2527
2520
 
2528
2521
  if (unlikely(net_request_file(net,cev->fname)))
2529
2522
  {
2530
 
    sql_print_error(_("Slave I/O: failed requesting download of '%s'"),
 
2523
    sql_print_error("Slave I/O: failed requesting download of '%s'",
2531
2524
                    cev->fname);
2532
2525
    goto err;
2533
2526
  }
2544
2537
    {
2545
2538
      if (unlikely((num_bytes=my_net_read(net)) == packet_error))
2546
2539
      {
2547
 
        sql_print_error(_("Network read error downloading '%s' from master"),
 
2540
        sql_print_error("Network read error downloading '%s' from master",
2548
2541
                        cev->fname);
2549
2542
        goto err;
2550
2543
      }
2551
2544
      if (unlikely(!num_bytes)) /* eof */
2552
2545
      {
2553
2546
        /* 3.23 master wants it */
2554
 
        net_write_command(net, 0, (unsigned char*) "", 0, (unsigned char*) "", 0);
 
2547
        net_write_command(net, 0, (uchar*) "", 0, (uchar*) "", 0);
2555
2548
        /*
2556
2549
          If we wrote Create_file_log_event, then we need to write
2557
2550
          Execute_load_log_event. If we did not write Create_file_log_event,
2566
2559
        {
2567
2560
          mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
2568
2561
                     ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
2569
 
                     _("error writing Exec_load event to relay log"));
 
2562
                     "error writing Exec_load event to relay log");
2570
2563
          goto err;
2571
2564
        }
2572
2565
        mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total);
2580
2573
        {
2581
2574
          mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
2582
2575
                     ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
2583
 
                     _("error writing Create_file event to relay log"));
 
2576
                     "error writing Create_file event to relay log");
2584
2577
          goto err;
2585
2578
        }
2586
2579
        cev_not_written=0;
2595
2588
        {
2596
2589
          mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
2597
2590
                     ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
2598
 
                     _("error writing Append_block event to relay log"));
 
2591
                     "error writing Append_block event to relay log");
2599
2592
          goto err;
2600
2593
        }
2601
2594
        mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total) ;
2657
2650
  if (mi->rli.relay_log.description_event_for_queue->binlog_version >= 4)
2658
2651
  {
2659
2652
    delete mi->rli.relay_log.description_event_for_queue;
2660
 
    /* start from format 3 (DRIZZLE 4.0) again */
 
2653
    /* start from format 3 (MySQL 4.0) again */
2661
2654
    mi->rli.relay_log.description_event_for_queue= new
2662
2655
      Format_description_log_event(3);
2663
2656
  }
2671
2664
 
2672
2665
/*
2673
2666
  Reads a 3.23 event and converts it to the slave's format. This code was
2674
 
  copied from DRIZZLE 4.0.
 
2667
  copied from MySQL 4.0.
2675
2668
*/
2676
2669
static int32_t queue_binlog_ver_1_event(Master_info *mi, const char *buf,
2677
2670
                           uint32_t event_len)
2691
2684
    if (unlikely(!(tmp_buf=(char*)my_malloc(event_len+1,MYF(MY_WME)))))
2692
2685
    {
2693
2686
      mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
2694
 
                 ER(ER_SLAVE_FATAL_ERROR), _("Memory allocation failed"));
 
2687
                 ER(ER_SLAVE_FATAL_ERROR), "Memory allocation failed");
2695
2688
      return(1);
2696
2689
    }
2697
2690
    memcpy(tmp_buf,buf,event_len);
2716
2709
                                            mi->rli.relay_log.description_event_for_queue);
2717
2710
  if (unlikely(!ev))
2718
2711
  {
2719
 
    sql_print_error(_("Read invalid event from master: '%s', "
2720
 
                      "master could be corrupt but a more likely cause "
2721
 
                      "of this is a bug"),
 
2712
    sql_print_error("Read invalid event from master: '%s',\
 
2713
 master could be corrupt but a more likely cause of this is a bug",
2722
2714
                    errmsg);
2723
 
    free((char*) tmp_buf);
 
2715
    my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
2724
2716
    return(1);
2725
2717
  }
2726
2718
 
2756
2748
    delete ev;
2757
2749
    mi->master_log_pos += inc_pos;
2758
2750
    pthread_mutex_unlock(&mi->data_lock);
2759
 
    free((char*)tmp_buf);
 
2751
    my_free((char*)tmp_buf, MYF(0));
2760
2752
    return(error);
2761
2753
  }
2762
2754
  default:
2802
2794
                                            mi->rli.relay_log.description_event_for_queue);
2803
2795
  if (unlikely(!ev))
2804
2796
  {
2805
 
    sql_print_error(_("Read invalid event from master: '%s', "
2806
 
                      "master could be corrupt but a more likely cause of "
2807
 
                      "this is a bug"),
 
2797
    sql_print_error("Read invalid event from master: '%s',\
 
2798
 master could be corrupt but a more likely cause of this is a bug",
2808
2799
                    errmsg);
2809
 
    free((char*) tmp_buf);
 
2800
    my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
2810
2801
    return(1);
2811
2802
  }
2812
2803
  pthread_mutex_lock(&mi->data_lock);
2880
2871
{
2881
2872
  int32_t error= 0;
2882
2873
  String error_msg;
2883
 
  uint32_t inc_pos= 0;
 
2874
  uint32_t inc_pos;
2884
2875
  Relay_log_info *rli= &mi->rli;
2885
2876
  pthread_mutex_t *log_lock= rli->relay_log.get_log_lock();
2886
2877
 
3073
3064
err:
3074
3065
  pthread_mutex_unlock(&mi->data_lock);
3075
3066
  if (error)
3076
 
    mi->report(ERROR_LEVEL, error, ER(error),
 
3067
    mi->report(ERROR_LEVEL, error, ER(error), 
3077
3068
               (error == ER_SLAVE_RELAY_LOG_WRITE_FAILURE)?
3078
 
               _("could not queue event from master") :
 
3069
               "could not queue event from master" :
3079
3070
               error_msg.ptr());
3080
3071
  return(error);
3081
3072
}
3115
3106
  SYNPOSIS
3116
3107
    safe_connect()
3117
3108
    thd                 Thread handler for slave
3118
 
    DRIZZLE               DRIZZLE connection handle
 
3109
    mysql               MySQL connection handle
3119
3110
    mi                  Replication handle
3120
3111
 
3121
3112
  RETURN
3123
3114
    #   Error
3124
3115
*/
3125
3116
 
3126
 
static int32_t safe_connect(THD* thd, DRIZZLE *drizzle, Master_info* mi)
 
3117
static int32_t safe_connect(THD* thd, MYSQL* mysql, Master_info* mi)
3127
3118
{
3128
 
  return(connect_to_master(thd, drizzle, mi, 0, 0));
 
3119
  return(connect_to_master(thd, mysql, mi, 0, 0));
3129
3120
}
3130
3121
 
3131
3122
 
3138
3129
    master_retry_count times
3139
3130
*/
3140
3131
 
3141
 
static int32_t connect_to_master(THD* thd, DRIZZLE *drizzle, Master_info* mi,
3142
 
                                 bool reconnect, bool suppress_warnings)
 
3132
static int32_t connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
 
3133
                             bool reconnect, bool suppress_warnings)
3143
3134
{
3144
3135
  int32_t slave_was_killed;
3145
3136
  int32_t last_errno= -2;                           // impossible error
3151
3142
  if (opt_slave_compressed_protocol)
3152
3143
    client_flag=CLIENT_COMPRESS;                /* We will use compression */
3153
3144
 
3154
 
  drizzle_options(drizzle, DRIZZLE_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
3155
 
  drizzle_options(drizzle, DRIZZLE_OPT_READ_TIMEOUT, (char *) &slave_net_timeout);
 
3145
  mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
 
3146
  mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout);
 
3147
 
 
3148
  mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset_info->csname);
 
3149
  /* This one is not strictly needed but we have it here for completeness */
 
3150
  mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
3156
3151
 
3157
3152
  while (!(slave_was_killed = io_slave_killed(thd,mi)) &&
3158
 
         (reconnect ? drizzle_reconnect(drizzle) != 0 :
3159
 
          drizzle_connect(drizzle, mi->host, mi->user, mi->password, 0,
 
3153
         (reconnect ? mysql_reconnect(mysql) != 0 :
 
3154
          mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
3160
3155
                             mi->port, 0, client_flag) == 0))
3161
3156
  {
3162
3157
    /* Don't repeat last error */
3163
 
    if ((int32_t)drizzle_errno(drizzle) != last_errno)
 
3158
    if ((int32_t)mysql_errno(mysql) != last_errno)
3164
3159
    {
3165
 
      last_errno=drizzle_errno(drizzle);
 
3160
      last_errno=mysql_errno(mysql);
3166
3161
      suppress_warnings= 0;
3167
3162
      mi->report(ERROR_LEVEL, last_errno,
3168
 
                 _("error %s to master '%s@%s:%d'"
3169
 
                   " - retry-time: %d  retries: %u"),
3170
 
                 (reconnect ? _("reconnecting") : _("connecting")),
 
3163
                 "error %s to master '%s@%s:%d'"
 
3164
                 " - retry-time: %d  retries: %u",
 
3165
                 (reconnect ? "reconnecting" : "connecting"),
3171
3166
                 mi->user, mi->host, mi->port,
3172
3167
                 mi->connect_retry, master_retry_count);
3173
3168
    }
3193
3188
    if (reconnect)
3194
3189
    {
3195
3190
      if (!suppress_warnings && global_system_variables.log_warnings)
3196
 
        sql_print_information(_("Slave: connected to master '%s@%s:%d', "
3197
 
                                "replication resumed in log '%s' at "
3198
 
                                "position %s"), mi->user,
3199
 
                                mi->host, mi->port,
3200
 
                                IO_RPL_LOG_NAME,
3201
 
                                llstr(mi->master_log_pos,llbuff));
 
3191
        sql_print_information("Slave: connected to master '%s@%s:%d',\
 
3192
replication resumed in log '%s' at position %s", mi->user,
 
3193
                        mi->host, mi->port,
 
3194
                        IO_RPL_LOG_NAME,
 
3195
                        llstr(mi->master_log_pos,llbuff));
3202
3196
    }
3203
3197
    else
3204
3198
    {
3205
3199
      change_rpl_status(RPL_IDLE_SLAVE,RPL_ACTIVE_SLAVE);
 
3200
      general_log_print(thd, COM_CONNECT_OUT, "%s@%s:%d",
 
3201
                        mi->user, mi->host, mi->port);
3206
3202
    }
 
3203
#ifdef SIGNAL_WITH_VIO_CLOSE
 
3204
    thd->set_active_vio(mysql->net.vio);
 
3205
#endif
3207
3206
  }
3208
 
  drizzle->reconnect= 1;
 
3207
  mysql->reconnect= 1;
3209
3208
  return(slave_was_killed);
3210
3209
}
3211
3210
 
3218
3217
    master_retry_count times
3219
3218
*/
3220
3219
 
3221
 
static int32_t safe_reconnect(THD* thd, DRIZZLE *drizzle, Master_info* mi,
 
3220
static int32_t safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
3222
3221
                          bool suppress_warnings)
3223
3222
{
3224
 
  return(connect_to_master(thd, drizzle, mi, 1, suppress_warnings));
 
3223
  return(connect_to_master(thd, mysql, mi, 1, suppress_warnings));
3225
3224
}
3226
3225
 
3227
3226
 
3265
3264
  char buff[FN_REFLEN*2+22*2+4], *pos;
3266
3265
 
3267
3266
  my_b_seek(file, 0L);
3268
 
  pos=my_stpcpy(buff, rli->group_relay_log_name);
 
3267
  pos=strmov(buff, rli->group_relay_log_name);
3269
3268
  *pos++='\n';
3270
3269
  pos=int64_t2str(rli->group_relay_log_pos, pos, 10);
3271
3270
  *pos++='\n';
3272
 
  pos=my_stpcpy(pos, rli->group_master_log_name);
 
3271
  pos=strmov(pos, rli->group_master_log_name);
3273
3272
  *pos++='\n';
3274
3273
  pos=int64_t2str(rli->group_master_log_pos, pos, 10);
3275
3274
  *pos='\n';
3276
 
  if (my_b_write(file, (unsigned char*) buff, (size_t) (pos-buff)+1))
 
3275
  if (my_b_write(file, (uchar*) buff, (size_t) (pos-buff)+1))
3277
3276
    error=1;
3278
3277
  if (flush_io_cache(file))
3279
3278
    error=1;
3301
3300
    relay_log_pos       Current log pos
3302
3301
    pending             Number of bytes already processed from the event
3303
3302
  */
3304
 
  rli->event_relay_log_pos= cmax(rli->event_relay_log_pos, (uint64_t)BIN_LOG_HEADER_SIZE);
 
3303
  rli->event_relay_log_pos= max(rli->event_relay_log_pos, BIN_LOG_HEADER_SIZE);
3305
3304
  my_b_seek(cur_log,rli->event_relay_log_pos);
3306
3305
  return(cur_log);
3307
3306
}
3382
3381
      When the relay log is created when the I/O thread starts, easy: the
3383
3382
      master will send the description event and we will queue it.
3384
3383
      But if the relay log is created by new_file(): then the solution is:
3385
 
      DRIZZLE_BIN_LOG::open() will write the buffered description event.
 
3384
      MYSQL_BIN_LOG::open() will write the buffered description event.
3386
3385
    */
3387
3386
    if ((ev=Log_event::read_log_event(cur_log,0,
3388
3387
                                      rli->relay_log.description_event_for_exec)))
3578
3577
      {
3579
3578
#ifdef EXTRA_DEBUG
3580
3579
        if (global_system_variables.log_warnings)
3581
 
          sql_print_information(_("next log '%s' is currently active"),
 
3580
          sql_print_information("next log '%s' is currently active",
3582
3581
                                rli->linfo.log_file_name);
3583
3582
#endif
3584
3583
        rli->cur_log= cur_log= rli->relay_log.get_log_file();
3608
3607
      */
3609
3608
#ifdef EXTRA_DEBUG
3610
3609
      if (global_system_variables.log_warnings)
3611
 
        sql_print_information(_("next log '%s' is not active"),
 
3610
        sql_print_information("next log '%s' is not active",
3612
3611
                              rli->linfo.log_file_name);
3613
3612
#endif
3614
3613
      // open_binlog() will check the magic header
3624
3623
      */
3625
3624
      if (hot_log)
3626
3625
        pthread_mutex_unlock(log_lock);
3627
 
      sql_print_error(_("Slave SQL thread: I/O error reading "
3628
 
                        "event(errno: %d  cur_log->error: %d)"),
 
3626
      sql_print_error("Slave SQL thread: I/O error reading \
 
3627
event(errno: %d  cur_log->error: %d)",
3629
3628
                      my_errno,cur_log->error);
3630
3629
      // set read position to the beginning of the event
3631
3630
      my_b_seek(cur_log,rli->event_relay_log_pos);
3632
3631
      /* otherwise, we have had a partial read */
3633
 
      errmsg = _("Aborting slave SQL thread because of partial event read");
 
3632
      errmsg = "Aborting slave SQL thread because of partial event read";
3634
3633
      break;                                    // To end of function
3635
3634
    }
3636
3635
  }
3637
3636
  if (!errmsg && global_system_variables.log_warnings)
3638
3637
  {
3639
 
    sql_print_information(_("Error reading relay log event: %s"),
3640
 
                          _("slave SQL thread was killed"));
 
3638
    sql_print_information("Error reading relay log event: %s",
 
3639
                          "slave SQL thread was killed");
3641
3640
    return(0);
3642
3641
  }
3643
3642
 
3644
3643
err:
3645
3644
  if (errmsg)
3646
 
    sql_print_error(_("Error reading relay log event: %s"), errmsg);
 
3645
    sql_print_error("Error reading relay log event: %s", errmsg);
3647
3646
  return(0);
3648
3647
}
3649
3648
 
3651
3650
  Rotate a relay log (this is used only by FLUSH LOGS; the automatic rotation
3652
3651
  because of size is simpler because when we do it we already have all relevant
3653
3652
  locks; here we don't, so this function is mainly taking locks).
3654
 
  Returns nothing as we cannot catch any error (DRIZZLE_BIN_LOG::new_file()
 
3653
  Returns nothing as we cannot catch any error (MYSQL_BIN_LOG::new_file()
3655
3654
  is void).
3656
3655
*/
3657
3656
 
3706
3705
{
3707
3706
  struct st_version_range_for_one_bug {
3708
3707
    uint32_t        bug_id;
3709
 
    const unsigned char introduced_in[3]; // first version with bug
3710
 
    const unsigned char fixed_in[3];      // first version with fix
 
3708
    const uchar introduced_in[3]; // first version with bug
 
3709
    const uchar fixed_in[3];      // first version with fix
3711
3710
  };
3712
3711
  static struct st_version_range_for_one_bug versions_for_all_bugs[]=
3713
3712
  {
3716
3715
    {33029, { 5, 0,  0 }, { 5, 0, 58 } },
3717
3716
    {33029, { 5, 1,  0 }, { 5, 1, 12 } },
3718
3717
  };
3719
 
  const unsigned char *master_ver=
 
3718
  const uchar *master_ver=
3720
3719
    rli->relay_log.description_event_for_exec->server_version_split;
3721
3720
 
3722
3721
  assert(sizeof(rli->relay_log.description_event_for_exec->server_version_split) == 3);
3724
3723
  for (uint32_t i= 0;
3725
3724
       i < sizeof(versions_for_all_bugs)/sizeof(*versions_for_all_bugs);i++)
3726
3725
  {
3727
 
    const unsigned char *introduced_in= versions_for_all_bugs[i].introduced_in,
 
3726
    const uchar *introduced_in= versions_for_all_bugs[i].introduced_in,
3728
3727
      *fixed_in= versions_for_all_bugs[i].fixed_in;
3729
3728
    if ((versions_for_all_bugs[i].bug_id == bug_id) &&
3730
3729
        (memcmp(introduced_in, master_ver, 3) <= 0) &&
3731
3730
        (memcmp(fixed_in,      master_ver, 3) >  0))
3732
3731
    {
3733
3732
      if (!report)
3734
 
        return true;
3735
 
 
 
3733
        return true;
 
3734
      
3736
3735
      // a short message for SHOW SLAVE STATUS (message length constraints)
3737
 
      my_printf_error(ER_UNKNOWN_ERROR,
3738
 
                      _("master may suffer from"
3739
 
                        " http://bugs.mysql.com/bug.php?id=%u"
3740
 
                        " so slave stops; check error log on slave"
3741
 
                        " for more info"), MYF(0), bug_id);
 
3736
      my_printf_error(ER_UNKNOWN_ERROR, "master may suffer from"
 
3737
                      " http://bugs.mysql.com/bug.php?id=%u"
 
3738
                      " so slave stops; check error log on slave"
 
3739
                      " for more info", MYF(0), bug_id);
3742
3740
      // a verbose message for the error log
3743
3741
      rli->report(ERROR_LEVEL, ER_UNKNOWN_ERROR,
3744
 
                  _("According to the master's version ('%s'),"
3745
 
                    " it is probable that master suffers from this bug:"
3746
 
                    " http://bugs.mysql.com/bug.php?id=%u"
3747
 
                    " and thus replicating the current binary log event"
3748
 
                    " may make the slave's data become different from the"
3749
 
                    " master's data."
3750
 
                    " To take no risk, slave refuses to replicate"
3751
 
                    " this event and stops."
3752
 
                    " We recommend that all updates be stopped on the"
3753
 
                    " master and slave, that the data of both be"
3754
 
                    " manually synchronized,"
3755
 
                    " that master's binary logs be deleted,"
3756
 
                    " that master be upgraded to a version at least"
3757
 
                    " equal to '%d.%d.%d'. Then replication can be"
3758
 
                    " restarted."),
3759
 
                  rli->relay_log.description_event_for_exec->server_version,
3760
 
                  bug_id,
3761
 
                  fixed_in[0], fixed_in[1], fixed_in[2]);
 
3742
                  "According to the master's version ('%s'),"
 
3743
                  " it is probable that master suffers from this bug:"
 
3744
                      " http://bugs.mysql.com/bug.php?id=%u"
 
3745
                      " and thus replicating the current binary log event"
 
3746
                      " may make the slave's data become different from the"
 
3747
                      " master's data."
 
3748
                      " To take no risk, slave refuses to replicate"
 
3749
                      " this event and stops."
 
3750
                      " We recommend that all updates be stopped on the"
 
3751
                      " master and slave, that the data of both be"
 
3752
                      " manually synchronized,"
 
3753
                      " that master's binary logs be deleted,"
 
3754
                      " that master be upgraded to a version at least"
 
3755
                      " equal to '%d.%d.%d'. Then replication can be"
 
3756
                      " restarted.",
 
3757
                      rli->relay_log.description_event_for_exec->server_version,
 
3758
                      bug_id,
 
3759
                      fixed_in[0], fixed_in[1], fixed_in[2]);
3762
3760
      return true;
3763
3761
    }
3764
3762
  }
3793
3791
/**
3794
3792
  @} (end of group Replication)
3795
3793
*/
 
3794
 
 
3795
#endif /* HAVE_REPLICATION */