~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/slave.cc

  • Committer: Brian Aker
  • Date: 2008-07-14 22:40:46 UTC
  • Revision ID: brian@tangent.org-20080714224046-x183907w9wp1txwv
Removed sql_manager. Ever heard of just setting up the OS to sync when you
want it to?

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
 
#include <mysys/thr_alarm.h>
34
 
#include <libdrizzle/sql_common.h>
35
 
#include <libdrizzle/errmsg.h>
36
 
#include <mysys/mysys_err.h>
37
 
#include <drizzled/drizzled_error_messages.h>
38
 
 
39
 
#if TIME_WITH_SYS_TIME
40
 
# include <sys/time.h>
41
 
# include <time.h>
42
 
#else
43
 
# if HAVE_SYS_TIME_H
44
 
#  include <sys/time.h>
45
 
# else
46
 
#  include <time.h>
47
 
# endif
48
 
#endif
49
 
 
 
35
#include "repl_failsafe.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
50
43
 
51
44
#include "rpl_tblmap.h"
52
45
 
60
53
 
61
54
char* slave_load_tmpdir = 0;
62
55
Master_info *active_mi= 0;
63
 
bool replicate_same_server_id;
 
56
my_bool replicate_same_server_id;
64
57
uint64_t relay_log_space_limit = 0;
65
58
 
66
59
/*
95
88
static const char *reconnect_messages[SLAVE_RECON_ACT_MAX][SLAVE_RECON_MSG_MAX]=
96
89
{
97
90
  {
98
 
    N_("Waiting to reconnect after a failed registration on master"),
99
 
    N_("Slave I/O thread killed while waitnig to reconnect after a "
100
 
                 "failed registration on master"),
101
 
    N_("Reconnecting after a failed registration on master"),
102
 
    N_("failed registering on master, reconnecting to try again, "
103
 
                 "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",
104
97
    "COM_REGISTER_SLAVE",
105
 
    N_("Slave I/O thread killed during or after reconnect")
 
98
    "Slave I/O thread killed during or after reconnect"
106
99
  },
107
100
  {
108
 
    N_("Waiting to reconnect after a failed binlog dump request"),
109
 
    N_("Slave I/O thread killed while retrying master dump"),
110
 
    N_("Reconnecting after a failed binlog dump request"),
111
 
    N_("failed dump request, reconnecting to try again, "
112
 
                 "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",
113
105
    "COM_BINLOG_DUMP",
114
 
    N_("Slave I/O thread killed during or after reconnect")
 
106
    "Slave I/O thread killed during or after reconnect"
115
107
  },
116
108
  {
117
 
    N_("Waiting to reconnect after a failed master event read"),
118
 
    N_("Slave I/O thread killed while waiting to reconnect "
119
 
                 "after a failed read"),
120
 
    N_("Reconnecting after a failed master event read"),
121
 
    N_("Slave I/O thread: Failed reading log event, "
122
 
                 "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",
123
114
    "",
124
 
    N_("Slave I/O thread killed during or after a "
125
 
                 "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"
126
117
  }
127
118
};
128
119
 
135
126
static inline bool io_slave_killed(THD* thd,Master_info* mi);
136
127
static inline bool sql_slave_killed(THD* thd,Relay_log_info* rli);
137
128
static int32_t init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type);
138
 
static int32_t safe_connect(THD* thd, DRIZZLE *drizzle, Master_info* mi);
139
 
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,
140
131
                          bool suppress_warnings);
141
 
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,
142
133
                             bool reconnect, bool suppress_warnings);
143
134
static int32_t safe_sleep(THD* thd, int32_t sec, CHECK_KILLED_FUNC thread_killed,
144
135
                      void* thread_killed_arg);
145
 
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);
146
137
static Log_event* next_event(Relay_log_info* rli);
147
138
static int32_t queue_event(Master_info* mi,const char* buf,uint32_t event_len);
148
139
static int32_t terminate_slave_thread(THD *thd,
235
226
  */
236
227
  if (!active_mi)
237
228
  {
238
 
    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");
239
230
    goto err;
240
231
  }
241
232
 
242
 
  if (active_mi->init_master_info(master_info_file, relay_log_info_file, (SLAVE_IO | SLAVE_SQL)))
 
233
  if (init_master_info(active_mi,master_info_file,relay_log_info_file,
 
234
                       1, (SLAVE_IO | SLAVE_SQL)))
243
235
  {
244
 
    sql_print_error(_("Failed to initialize the master info structure"));
 
236
    sql_print_error("Failed to initialize the master info structure");
245
237
    goto err;
246
238
  }
247
239
 
256
248
                            relay_log_info_file,
257
249
                            SLAVE_IO | SLAVE_SQL))
258
250
    {
259
 
      sql_print_error(_("Failed to create slave threads"));
 
251
      sql_print_error("Failed to create slave threads");
260
252
      goto err;
261
253
    }
262
254
  }
292
284
  use_slave_mask = 1;
293
285
  for (;my_isspace(system_charset_info,*arg);++arg)
294
286
    /* empty */;
295
 
  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))
296
288
  {
297
289
    bitmap_set_all(&slave_error_mask);
298
290
    return;
453
445
      pthread_cond_broadcast(start_cond);
454
446
    if (start_lock)
455
447
      pthread_mutex_unlock(start_lock);
456
 
    sql_print_error(_("Server id not set, will not start slave"));
 
448
    sql_print_error("Server id not set, will not start slave");
457
449
    return(ER_BAD_SLAVE);
458
450
  }
459
451
 
511
503
 
512
504
int32_t start_slave_threads(bool need_slave_mutex, bool wait_for_start,
513
505
                        Master_info* mi,
514
 
                        const char* master_info_fname __attribute__((unused)),
515
 
                        const char* slave_info_fname __attribute__((unused)),
 
506
                        const char* master_info_fname __attribute__((__unused__)),
 
507
                        const char* slave_info_fname __attribute__((__unused__)),
516
508
                        int32_t thread_mask)
517
509
{
518
510
  pthread_mutex_t *lock_io=0,*lock_sql=0,*lock_cond_io=0,*lock_cond_sql=0;
551
543
 
552
544
 
553
545
#ifdef NOT_USED_YET
554
 
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*/)
555
547
{
556
548
  end_master_info(mi);
557
549
  return(0);
584
576
      once multi-master code is ready.
585
577
    */
586
578
    terminate_slave_threads(active_mi,SLAVE_FORCE_ALL);
587
 
    active_mi->end_master_info();
 
579
    end_master_info(active_mi);
588
580
    delete active_mi;
589
581
    active_mi= 0;
590
582
  }
621
613
    if (difftime(time(0), rli->last_event_start_time) > 60)
622
614
    {
623
615
      rli->report(ERROR_LEVEL, 0,
624
 
                  _("SQL thread had to stop in an unsafe situation, in "
 
616
                  "SQL thread had to stop in an unsafe situation, in "
625
617
                  "the middle of applying updates to a "
626
618
                  "non-transactional table without any primary key. "
627
619
                  "There is a risk of duplicate updates when the slave "
628
620
                  "SQL thread is restarted. Please check your tables' "
629
 
                  "contents after restart."));
 
621
                  "contents after restart.");
630
622
      return(1);
631
623
    }
632
624
  }
645
637
{
646
638
  (void)net_request_file(net, "/dev/null");
647
639
  (void)my_net_read(net);                               // discard response
648
 
  (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
649
641
  return;
650
642
}
651
643
 
652
644
 
653
645
bool net_request_file(NET* net, const char* fname)
654
646
{
655
 
  return(net_write_command(net, 251, (unsigned char*) fname, strlen(fname),
656
 
                                (unsigned char*) "", 0));
 
647
  return(net_write_command(net, 251, (uchar*) fname, strlen(fname),
 
648
                                (uchar*) "", 0));
657
649
}
658
650
 
659
651
/*
762
754
  1       error
763
755
*/
764
756
 
765
 
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)
766
758
{
767
759
  char error_buf[512];
768
760
  String err_msg(error_buf, sizeof(error_buf), &my_charset_bin);
769
761
  char err_buff[MAX_SLAVE_ERRMSG];
770
762
  const char* errmsg= 0;
771
763
  int32_t err_code= 0;
772
 
  DRIZZLE_RES *master_res= 0;
773
 
  DRIZZLE_ROW master_row;
 
764
  MYSQL_RES *master_res= 0;
 
765
  MYSQL_ROW master_row;
774
766
 
775
767
  err_msg.length(0);
776
768
  /*
780
772
  delete mi->rli.relay_log.description_event_for_queue;
781
773
  mi->rli.relay_log.description_event_for_queue= 0;
782
774
 
783
 
  if (!my_isdigit(&my_charset_bin,*drizzle->server_version))
 
775
  if (!my_isdigit(&my_charset_bin,*mysql->server_version))
784
776
  {
785
 
    errmsg = _("Master reported unrecognized DRIZZLE version");
 
777
    errmsg = "Master reported unrecognized MySQL version";
786
778
    err_code= ER_SLAVE_FATAL_ERROR;
787
779
    sprintf(err_buff, ER(err_code), errmsg);
788
780
    err_msg.append(err_buff);
790
782
  else
791
783
  {
792
784
    /*
793
 
      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 ;)
794
786
    */
795
 
    switch (*drizzle->server_version)
 
787
    switch (*mysql->server_version)
796
788
    {
797
789
    case '0':
798
790
    case '1':
799
791
    case '2':
800
 
      errmsg = _("Master reported unrecognized DRIZZLE version");
 
792
      errmsg = "Master reported unrecognized MySQL version";
801
793
      err_code= ER_SLAVE_FATAL_ERROR;
802
794
      sprintf(err_buff, ER(err_code), errmsg);
803
795
      err_msg.append(err_buff);
804
796
      break;
805
797
    case '3':
806
798
      mi->rli.relay_log.description_event_for_queue= new
807
 
        Format_description_log_event(1, drizzle->server_version);
 
799
        Format_description_log_event(1, mysql->server_version);
808
800
      break;
809
801
    case '4':
810
802
      mi->rli.relay_log.description_event_for_queue= new
811
 
        Format_description_log_event(3, drizzle->server_version);
 
803
        Format_description_log_event(3, mysql->server_version);
812
804
      break;
813
805
    default:
814
806
      /*
815
 
        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
816
808
        take the early steps (like tests for "is this a 3.23 master") which we
817
809
        have to take before we receive the real master's Format_desc which will
818
810
        override this one. Note that the Format_desc we create below is garbage
820
812
        master is 3.23, 4.0, etc.
821
813
      */
822
814
      mi->rli.relay_log.description_event_for_queue= new
823
 
        Format_description_log_event(4, drizzle->server_version);
 
815
        Format_description_log_event(4, mysql->server_version);
824
816
      break;
825
817
    }
826
818
  }
838
830
  /* as we are here, we tried to allocate the event */
839
831
  if (!mi->rli.relay_log.description_event_for_queue)
840
832
  {
841
 
    errmsg= _("default Format_description_log_event");
 
833
    errmsg= "default Format_description_log_event";
842
834
    err_code= ER_SLAVE_CREATE_EVENT_FAILURE;
843
835
    sprintf(err_buff, ER(err_code), errmsg);
844
836
    err_msg.append(err_buff);
850
842
    unavailable (very old master not supporting UNIX_TIMESTAMP()?).
851
843
  */
852
844
 
853
 
  if (!drizzle_real_query(drizzle, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) &&
854
 
      (master_res= drizzle_store_result(drizzle)) &&
855
 
      (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)))
856
848
  {
857
849
    mi->clock_diff_with_master=
858
850
      (long) (time((time_t*) 0) - strtoul(master_row[0], 0, 10));
860
852
  else if (!check_io_slave_killed(mi->io_thd, mi, NULL))
861
853
  {
862
854
    mi->clock_diff_with_master= 0; /* The "most sensible" value */
863
 
    sql_print_warning(_("\"SELECT UNIX_TIMESTAMP()\" failed on master, "
864
 
                        "do not trust column Seconds_Behind_Master of SHOW "
865
 
                        "SLAVE STATUS. Error: %s (%d)"),
866
 
                      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));
867
859
  }
868
860
  if (master_res)
869
 
    drizzle_free_result(master_res);
 
861
    mysql_free_result(master_res);
870
862
 
871
863
  /*
872
864
    Check that the master's server id and ours are different. Because if they
878
870
    Note: we could have put a @@SERVER_ID in the previous SELECT
879
871
    UNIX_TIMESTAMP() instead, but this would not have worked on 3.23 masters.
880
872
  */
881
 
  if (!drizzle_real_query(drizzle,
 
873
  if (!mysql_real_query(mysql,
882
874
                        STRING_WITH_LEN("SHOW VARIABLES LIKE 'SERVER_ID'")) &&
883
 
      (master_res= drizzle_store_result(drizzle)))
 
875
      (master_res= mysql_store_result(mysql)))
884
876
  {
885
 
    if ((master_row= drizzle_fetch_row(master_res)) &&
 
877
    if ((master_row= mysql_fetch_row(master_res)) &&
886
878
        (::server_id == strtoul(master_row[1], 0, 10)) &&
887
879
        !mi->rli.replicate_same_server_id)
888
880
    {
889
881
      errmsg=
890
 
        _("The slave I/O thread stops because master and slave have equal "
891
 
          "DRIZZLE server ids; these ids must be different "
892
 
          "for replication to work (or "
893
 
          "the --replicate-same-server-id option must be used "
894
 
          "on slave but this does"
895
 
          "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).";
896
886
      err_code= ER_SLAVE_FATAL_ERROR;
897
887
      sprintf(err_buff, ER(err_code), errmsg);
898
888
      err_msg.append(err_buff);
899
889
    }
900
 
    drizzle_free_result(master_res);
 
890
    mysql_free_result(master_res);
901
891
    if (errmsg)
902
892
      goto err;
903
893
  }
920
910
  */
921
911
 
922
912
  /* redundant with rest of code but safer against later additions */
923
 
  if (*drizzle->server_version == '3')
 
913
  if (*mysql->server_version == '3')
924
914
    goto err;
925
915
 
926
 
  if ((*drizzle->server_version == '4') &&
927
 
      !drizzle_real_query(drizzle,
 
916
  if ((*mysql->server_version == '4') &&
 
917
      !mysql_real_query(mysql,
928
918
                        STRING_WITH_LEN("SELECT @@GLOBAL.COLLATION_SERVER")) &&
929
 
      (master_res= drizzle_store_result(drizzle)))
 
919
      (master_res= mysql_store_result(mysql)))
930
920
  {
931
 
    if ((master_row= drizzle_fetch_row(master_res)) &&
 
921
    if ((master_row= mysql_fetch_row(master_res)) &&
932
922
        strcmp(master_row[0], global_system_variables.collation_server->name))
933
923
    {
934
924
      errmsg=
935
 
        _("The slave I/O thread stops because master and slave have"
936
 
          " different values for the COLLATION_SERVER global variable."
937
 
          " 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";
938
928
      err_code= ER_SLAVE_FATAL_ERROR;
939
929
      sprintf(err_buff, ER(err_code), errmsg);
940
930
      err_msg.append(err_buff);
941
931
    }
942
 
    drizzle_free_result(master_res);
 
932
    mysql_free_result(master_res);
943
933
    if (errmsg)
944
934
      goto err;
945
935
  }
959
949
    This check is only necessary for 4.x masters (and < 5.0.4 masters but
960
950
    those were alpha).
961
951
  */
962
 
  if ((*drizzle->server_version == '4') &&
963
 
      !drizzle_real_query(drizzle, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) &&
964
 
      (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)))
965
955
  {
966
 
    if ((master_row= drizzle_fetch_row(master_res)) &&
 
956
    if ((master_row= mysql_fetch_row(master_res)) &&
967
957
        strcmp(master_row[0],
968
958
               global_system_variables.time_zone->get_name()->ptr()))
969
959
    {
970
960
      errmsg=
971
 
        _("The slave I/O thread stops because master and slave have"
972
 
          " different values for the TIME_ZONE global variable."
973
 
          " 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";
974
964
      err_code= ER_SLAVE_FATAL_ERROR;
975
965
      sprintf(err_buff, ER(err_code), errmsg);
976
966
      err_msg.append(err_buff);
977
967
    }
978
 
    drizzle_free_result(master_res);
 
968
    mysql_free_result(master_res);
979
969
 
980
970
    if (errmsg)
981
971
      goto err;
990
980
       the period is an uint64_t of nano-secs. 
991
981
    */
992
982
    llstr((uint64_t) (mi->heartbeat_period*1000000000UL), llbuf);
993
 
    sprintf(query, query_format, llbuf);
 
983
    my_sprintf(query, (query, query_format, llbuf));
994
984
 
995
 
    if (drizzle_real_query(drizzle, query, strlen(query))
 
985
    if (mysql_real_query(mysql, query, strlen(query))
996
986
        && !check_io_slave_killed(mi->io_thd, mi, NULL))
997
987
    {
998
988
      err_msg.append("The slave I/O thread stops because querying master with '");
999
989
      err_msg.append(query);
1000
990
      err_msg.append("' failed;");
1001
991
      err_msg.append(" error: ");
1002
 
      err_code= drizzle_errno(drizzle);
 
992
      err_code= mysql_errno(mysql);
1003
993
      err_msg.qs_append(err_code);
1004
994
      err_msg.append("  '");
1005
 
      err_msg.append(drizzle_error(drizzle));
 
995
      err_msg.append(mysql_error(mysql));
1006
996
      err_msg.append("'");
1007
 
      drizzle_free_result(drizzle_store_result(drizzle));
 
997
      mysql_free_result(mysql_store_result(mysql));
1008
998
      goto err;
1009
999
    }
1010
 
    drizzle_free_result(drizzle_store_result(drizzle));
 
1000
    mysql_free_result(mysql_store_result(mysql));
1011
1001
  }
1012
1002
  
1013
1003
err:
1033
1023
  pthread_mutex_lock(&rli->log_space_lock);
1034
1024
  save_proc_info= thd->enter_cond(&rli->log_space_cond,
1035
1025
                                  &rli->log_space_lock,
1036
 
                                  _("Waiting for the slave SQL thread "
1037
 
                                    "to free enough relay log space"));
 
1026
                                  "\
 
1027
Waiting for the slave SQL thread to free enough relay log space");
1038
1028
  while (rli->log_space_limit < rli->log_space_total &&
1039
1029
         !(slave_killed=io_slave_killed(thd,mi)) &&
1040
1030
         !rli->ignore_log_space_limit)
1057
1047
    ignored events' end position for the use of the slave SQL thread, by
1058
1048
    calling this function. Only that thread can call it (see assertion).
1059
1049
 */
1060
 
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__)),
1061
1051
                                                   Master_info *mi)
1062
1052
{
1063
1053
  Relay_log_info *rli= &mi->rli;
1079
1069
      if (unlikely(rli->relay_log.append(ev)))
1080
1070
        mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
1081
1071
                   ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
1082
 
                   _("failed to write a Rotate event"
1083
 
                     " to the relay log, SHOW SLAVE STATUS may be"
1084
 
                     " inaccurate"));
 
1072
                   "failed to write a Rotate event"
 
1073
                   " to the relay log, SHOW SLAVE STATUS may be"
 
1074
                   " inaccurate");
1085
1075
      rli->relay_log.harvest_bytes_written(&rli->log_space_total);
1086
 
      if (mi->flush())
1087
 
        sql_print_error(_("Failed to flush master info file"));
 
1076
      if (flush_master_info(mi, 1))
 
1077
        sql_print_error("Failed to flush master info file");
1088
1078
      delete ev;
1089
1079
    }
1090
1080
    else
1091
1081
      mi->report(ERROR_LEVEL, ER_SLAVE_CREATE_EVENT_FAILURE,
1092
1082
                 ER(ER_SLAVE_CREATE_EVENT_FAILURE),
1093
 
                 _("Rotate_event (out of memory?),"
1094
 
                   " SHOW SLAVE STATUS may be inaccurate"));
 
1083
                 "Rotate_event (out of memory?),"
 
1084
                 " SHOW SLAVE STATUS may be inaccurate");
1095
1085
  }
1096
1086
  else
1097
1087
    pthread_mutex_unlock(log_lock);
1099
1089
}
1100
1090
 
1101
1091
 
1102
 
int32_t register_slave_on_master(DRIZZLE *drizzle, Master_info *mi,
 
1092
int32_t register_slave_on_master(MYSQL* mysql, Master_info *mi,
1103
1093
                             bool *suppress_warnings)
1104
1094
{
1105
 
  unsigned char buf[1024], *pos= buf;
 
1095
  uchar buf[1024], *pos= buf;
1106
1096
  uint32_t report_host_len, report_user_len=0, report_password_len=0;
1107
1097
 
1108
1098
  *suppress_warnings= false;
1119
1109
    return(0);                                     // safety
1120
1110
 
1121
1111
  int4store(pos, server_id); pos+= 4;
1122
 
  pos= net_store_data(pos, (unsigned char*) report_host, report_host_len);
1123
 
  pos= net_store_data(pos, (unsigned char*) report_user, report_user_len);
1124
 
  pos= net_store_data(pos, (unsigned char*) report_password, report_password_len);
1125
 
  int2store(pos, (uint16_t) report_port); pos+= 2;
1126
 
  int4store(pos, 0);    pos+= 4;
 
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
  int4store(pos, rpl_recovery_rank);    pos+= 4;
1127
1117
  /* The master will fill in master_id */
1128
1118
  int4store(pos, 0);                    pos+= 4;
1129
1119
 
1130
 
  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))
1131
1121
  {
1132
 
    if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
 
1122
    if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1133
1123
    {
1134
1124
      *suppress_warnings= true;                 // Suppress reconnect warning
1135
1125
    }
1136
1126
    else if (!check_io_slave_killed(mi->io_thd, mi, NULL))
1137
1127
    {
1138
1128
      char buf[256];
1139
 
      snprintf(buf, sizeof(buf), "%s (Errno: %d)", drizzle_error(drizzle), 
1140
 
               drizzle_errno(drizzle));
 
1129
      snprintf(buf, sizeof(buf), "%s (Errno: %d)", mysql_error(mysql), 
 
1130
               mysql_errno(mysql));
1141
1131
      mi->report(ERROR_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
1142
1132
                 ER(ER_SLAVE_MASTER_COM_FAILURE), "COM_REGISTER_SLAVE", buf);
1143
1133
    }
1160
1150
  field_list.push_back(new Item_empty_string("Master_User",
1161
1151
                                                     sizeof(mi->user)));
1162
1152
  field_list.push_back(new Item_return_int("Master_Port", 7,
1163
 
                                           DRIZZLE_TYPE_LONG));
 
1153
                                           MYSQL_TYPE_LONG));
1164
1154
  field_list.push_back(new Item_return_int("Connect_Retry", 10,
1165
 
                                           DRIZZLE_TYPE_LONG));
 
1155
                                           MYSQL_TYPE_LONG));
1166
1156
  field_list.push_back(new Item_empty_string("Master_Log_File",
1167
1157
                                             FN_REFLEN));
1168
1158
  field_list.push_back(new Item_return_int("Read_Master_Log_Pos", 10,
1169
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1159
                                           MYSQL_TYPE_LONGLONG));
1170
1160
  field_list.push_back(new Item_empty_string("Relay_Log_File",
1171
1161
                                             FN_REFLEN));
1172
1162
  field_list.push_back(new Item_return_int("Relay_Log_Pos", 10,
1173
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1163
                                           MYSQL_TYPE_LONGLONG));
1174
1164
  field_list.push_back(new Item_empty_string("Relay_Master_Log_File",
1175
1165
                                             FN_REFLEN));
1176
1166
  field_list.push_back(new Item_empty_string("Slave_IO_Running", 3));
1182
1172
  field_list.push_back(new Item_empty_string("Replicate_Wild_Do_Table", 24));
1183
1173
  field_list.push_back(new Item_empty_string("Replicate_Wild_Ignore_Table",
1184
1174
                                             28));
1185
 
  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));
1186
1176
  field_list.push_back(new Item_empty_string("Last_Error", 20));
1187
1177
  field_list.push_back(new Item_return_int("Skip_Counter", 10,
1188
 
                                           DRIZZLE_TYPE_LONG));
 
1178
                                           MYSQL_TYPE_LONG));
1189
1179
  field_list.push_back(new Item_return_int("Exec_Master_Log_Pos", 10,
1190
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1180
                                           MYSQL_TYPE_LONGLONG));
1191
1181
  field_list.push_back(new Item_return_int("Relay_Log_Space", 10,
1192
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1182
                                           MYSQL_TYPE_LONGLONG));
1193
1183
  field_list.push_back(new Item_empty_string("Until_Condition", 6));
1194
1184
  field_list.push_back(new Item_empty_string("Until_Log_File", FN_REFLEN));
1195
1185
  field_list.push_back(new Item_return_int("Until_Log_Pos", 10,
1196
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1186
                                           MYSQL_TYPE_LONGLONG));
 
1187
  field_list.push_back(new Item_empty_string("Master_SSL_Allowed", 7));
 
1188
  field_list.push_back(new Item_empty_string("Master_SSL_CA_File",
 
1189
                                             sizeof(mi->ssl_ca)));
 
1190
  field_list.push_back(new Item_empty_string("Master_SSL_CA_Path",
 
1191
                                             sizeof(mi->ssl_capath)));
 
1192
  field_list.push_back(new Item_empty_string("Master_SSL_Cert",
 
1193
                                             sizeof(mi->ssl_cert)));
 
1194
  field_list.push_back(new Item_empty_string("Master_SSL_Cipher",
 
1195
                                             sizeof(mi->ssl_cipher)));
 
1196
  field_list.push_back(new Item_empty_string("Master_SSL_Key",
 
1197
                                             sizeof(mi->ssl_key)));
1197
1198
  field_list.push_back(new Item_return_int("Seconds_Behind_Master", 10,
1198
 
                                           DRIZZLE_TYPE_LONGLONG));
1199
 
  field_list.push_back(new Item_return_int("Last_IO_Errno", 4, DRIZZLE_TYPE_LONG));
 
1199
                                           MYSQL_TYPE_LONGLONG));
 
1200
  field_list.push_back(new Item_empty_string("Master_SSL_Verify_Server_Cert",
 
1201
                                             3));
 
1202
  field_list.push_back(new Item_return_int("Last_IO_Errno", 4, MYSQL_TYPE_LONG));
1200
1203
  field_list.push_back(new Item_empty_string("Last_IO_Error", 20));
1201
 
  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));
1202
1205
  field_list.push_back(new Item_empty_string("Last_SQL_Error", 20));
1203
1206
 
1204
1207
  if (protocol->send_fields(&field_list,
1215
1218
      non-volotile members like mi->io_thd, which is guarded by the mutex.
1216
1219
    */
1217
1220
    pthread_mutex_lock(&mi->run_lock);
1218
 
    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);
1219
1222
    pthread_mutex_unlock(&mi->run_lock);
1220
1223
 
1221
1224
    pthread_mutex_lock(&mi->data_lock);
1222
1225
    pthread_mutex_lock(&mi->rli.data_lock);
1223
 
    protocol->store(mi->getHostname(), &my_charset_bin);
1224
 
    protocol->store(mi->getUsername(), &my_charset_bin);
1225
 
    protocol->store((uint32_t) mi->getPort());
1226
 
    protocol->store(mi->getConnectionRetry());
1227
 
    protocol->store(mi->getLogName(), &my_charset_bin);
1228
 
    protocol->store((uint64_t) mi->getLogPosition());
1229
 
    protocol->store(mi->rli.group_relay_log_name.c_str() +
1230
 
                    dirname_length(mi->rli.group_relay_log_name.c_str()),
 
1226
    protocol->store(mi->host, &my_charset_bin);
 
1227
    protocol->store(mi->user, &my_charset_bin);
 
1228
    protocol->store((uint32) mi->port);
 
1229
    protocol->store((uint32) mi->connect_retry);
 
1230
    protocol->store(mi->master_log_name, &my_charset_bin);
 
1231
    protocol->store((uint64_t) mi->master_log_pos);
 
1232
    protocol->store(mi->rli.group_relay_log_name +
 
1233
                    dirname_length(mi->rli.group_relay_log_name),
1231
1234
                    &my_charset_bin);
1232
1235
    protocol->store((uint64_t) mi->rli.group_relay_log_pos);
1233
 
    protocol->store(mi->rli.group_master_log_name.c_str(), &my_charset_bin);
1234
 
    protocol->store(mi->slave_running == DRIZZLE_SLAVE_RUN_CONNECT ?
 
1236
    protocol->store(mi->rli.group_master_log_name, &my_charset_bin);
 
1237
    protocol->store(mi->slave_running == MYSQL_SLAVE_RUN_CONNECT ?
1235
1238
                    "Yes" : "No", &my_charset_bin);
1236
1239
    protocol->store(mi->rli.slave_running ? "Yes":"No", &my_charset_bin);
1237
1240
    protocol->store(rpl_filter->get_do_db());
1250
1253
 
1251
1254
    protocol->store(mi->rli.last_error().number);
1252
1255
    protocol->store(mi->rli.last_error().message, &my_charset_bin);
1253
 
    protocol->store((uint32_t) mi->rli.slave_skip_counter);
 
1256
    protocol->store((uint32) mi->rli.slave_skip_counter);
1254
1257
    protocol->store((uint64_t) mi->rli.group_master_log_pos);
1255
1258
    protocol->store((uint64_t) mi->rli.log_space_total);
1256
1259
 
1261
1264
    protocol->store(mi->rli.until_log_name, &my_charset_bin);
1262
1265
    protocol->store((uint64_t) mi->rli.until_log_pos);
1263
1266
 
 
1267
    protocol->store(mi->ssl? "Ignored":"No", &my_charset_bin);
 
1268
    protocol->store(mi->ssl_ca, &my_charset_bin);
 
1269
    protocol->store(mi->ssl_capath, &my_charset_bin);
 
1270
    protocol->store(mi->ssl_cert, &my_charset_bin);
 
1271
    protocol->store(mi->ssl_cipher, &my_charset_bin);
 
1272
    protocol->store(mi->ssl_key, &my_charset_bin);
 
1273
 
1264
1274
    /*
1265
1275
      Seconds_Behind_Master: if SQL thread is running and I/O thread is
1266
1276
      connected, we can compute it otherwise show NULL (i.e. unknown).
1267
1277
    */
1268
 
    if ((mi->slave_running == DRIZZLE_SLAVE_RUN_CONNECT) &&
 
1278
    if ((mi->slave_running == MYSQL_SLAVE_RUN_CONNECT) &&
1269
1279
        mi->rli.slave_running)
1270
1280
    {
1271
1281
      long time_diff= ((long)(time(0) - mi->rli.last_master_timestamp)
1285
1295
        slave is 2. At SHOW SLAVE STATUS time, assume that the difference
1286
1296
        between timestamp of slave and rli->last_master_timestamp is 0
1287
1297
        (i.e. they are in the same second), then we get 0-(2-1)=-1 as a result.
1288
 
        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().
1289
1299
 
1290
1300
        last_master_timestamp == 0 (an "impossible" timestamp 1970) is a
1291
1301
        special marker to say "consider we have caught up".
1292
1302
      */
1293
1303
      protocol->store((int64_t)(mi->rli.last_master_timestamp ?
1294
 
                                 cmax((long)0, time_diff) : 0));
 
1304
                                 max(0, time_diff) : 0));
1295
1305
    }
1296
1306
    else
1297
1307
    {
1298
1308
      protocol->store_null();
1299
1309
    }
 
1310
    protocol->store(mi->ssl_verify_server_cert? "Yes":"No", &my_charset_bin);
1300
1311
 
1301
1312
    // Last_IO_Errno
1302
1313
    protocol->store(mi->last_error().number);
1310
1321
    pthread_mutex_unlock(&mi->rli.data_lock);
1311
1322
    pthread_mutex_unlock(&mi->data_lock);
1312
1323
 
1313
 
    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()))
1314
1325
      return(true);
1315
1326
  }
1316
1327
  my_eof(thd);
1339
1350
  return;
1340
1351
}
1341
1352
 
 
1353
void set_slave_thread_default_charset(THD* thd, Relay_log_info const *rli)
 
1354
{
 
1355
  thd->variables.character_set_client=
 
1356
    global_system_variables.character_set_client;
 
1357
  thd->variables.collation_connection=
 
1358
    global_system_variables.collation_connection;
 
1359
  thd->variables.collation_server=
 
1360
    global_system_variables.collation_server;
 
1361
  thd->update_charset();
 
1362
 
 
1363
  /*
 
1364
    We use a const cast here since the conceptual (and externally
 
1365
    visible) behavior of the function is to set the default charset of
 
1366
    the thread.  That the cache has to be invalidated is a secondary
 
1367
    effect.
 
1368
   */
 
1369
  const_cast<Relay_log_info*>(rli)->cached_charset_invalidate();
 
1370
  return;
 
1371
}
 
1372
 
1342
1373
/*
1343
1374
  init_slave_thread()
1344
1375
*/
1358
1389
  thd->variables.max_allowed_packet= global_system_variables.max_allowed_packet
1359
1390
    + MAX_LOG_EVENT_HEADER;  /* note, incr over the global not session var */
1360
1391
  thd->slave_thread = 1;
 
1392
  thd->enable_slow_log= opt_log_slow_slave_statements;
1361
1393
  set_slave_thread_options(thd);
1362
1394
  thd->client_capabilities = CLIENT_LOCAL_FILES;
1363
1395
  pthread_mutex_lock(&LOCK_thread_count);
1374
1406
  lex_start(thd);
1375
1407
 
1376
1408
  if (thd_type == SLAVE_THD_SQL)
1377
 
    thd->set_proc_info("Waiting for the next event in relay log");
 
1409
    thd_proc_info(thd, "Waiting for the next event in relay log");
1378
1410
  else
1379
 
    thd->set_proc_info("Waiting for master update");
 
1411
    thd_proc_info(thd, "Waiting for master update");
1380
1412
  thd->version=refresh_version;
1381
1413
  thd->set_time();
1382
1414
  return(0);
1413
1445
}
1414
1446
 
1415
1447
 
1416
 
static int32_t request_dump(DRIZZLE *drizzle, Master_info* mi,
 
1448
static int32_t request_dump(MYSQL* mysql, Master_info* mi,
1417
1449
                        bool *suppress_warnings)
1418
1450
{
1419
 
  unsigned char buf[FN_REFLEN + 10];
 
1451
  uchar buf[FN_REFLEN + 10];
1420
1452
  int32_t len;
1421
1453
  int32_t binlog_flags = 0; // for now
1422
 
  const char* logname = mi->getLogName();
 
1454
  char* logname = mi->master_log_name;
1423
1455
  
1424
1456
  *suppress_warnings= false;
1425
1457
 
1426
1458
  // TODO if big log files: Change next to int8store()
1427
 
  int4store(buf, (uint32_t) mi->getLogPosition());
 
1459
  int4store(buf, (uint32_t) mi->master_log_pos);
1428
1460
  int2store(buf + 4, binlog_flags);
1429
1461
  int4store(buf + 6, server_id);
1430
1462
  len = (uint32_t) strlen(logname);
1431
1463
  memcpy(buf + 10, logname,len);
1432
 
  if (simple_command(drizzle, COM_BINLOG_DUMP, buf, len + 10, 1))
 
1464
  if (simple_command(mysql, COM_BINLOG_DUMP, buf, len + 10, 1))
1433
1465
  {
1434
1466
    /*
1435
1467
      Something went wrong, so we will just reconnect and retry later
1436
1468
      in the future, we should do a better error analysis, but for
1437
1469
      now we just fill up the error log :-)
1438
1470
    */
1439
 
    if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
 
1471
    if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1440
1472
      *suppress_warnings= true;                 // Suppress reconnect warning
1441
1473
    else
1442
 
      sql_print_error(_("Error on COM_BINLOG_DUMP: %d  %s, will retry in %d secs"),
1443
 
                      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),
1444
1476
                      mi->connect_retry);
1445
1477
    return(1);
1446
1478
  }
1453
1485
 
1454
1486
  SYNOPSIS
1455
1487
    read_event()
1456
 
    DRIZZLE               DRIZZLE connection
 
1488
    mysql               MySQL connection
1457
1489
    mi                  Master connection information
1458
1490
    suppress_warnings   TRUE when a normal net read timeout has caused us to
1459
1491
                        try a reconnect.  We do not want to print anything to
1465
1497
    number              Length of packet
1466
1498
*/
1467
1499
 
1468
 
static uint32_t read_event(DRIZZLE *drizzle,
1469
 
                        Master_info *mi __attribute__((unused)),
 
1500
static uint32_t read_event(MYSQL* mysql,
 
1501
                        Master_info *mi __attribute__((__unused__)),
1470
1502
                        bool* suppress_warnings)
1471
1503
{
1472
1504
  uint32_t len;
1479
1511
  if (disconnect_slave_event_count && !(mi->events_till_disconnect--))
1480
1512
    return(packet_error);
1481
1513
 
1482
 
  len = cli_safe_read(drizzle);
 
1514
  len = cli_safe_read(mysql);
1483
1515
  if (len == packet_error || (int32_t) len < 1)
1484
1516
  {
1485
 
    if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
 
1517
    if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1486
1518
    {
1487
1519
      /*
1488
1520
        We are trying a normal reconnect after a read timeout;
1492
1524
      *suppress_warnings= true;
1493
1525
    }
1494
1526
    else
1495
 
      sql_print_error(_("Error reading packet from server: %s ( server_errno=%d)"),
1496
 
                      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));
1497
1529
    return(packet_error);
1498
1530
  }
1499
1531
 
1500
1532
  /* Check if eof packet */
1501
 
  if (len < 8 && drizzle->net.read_pos[0] == 254)
 
1533
  if (len < 8 && mysql->net.read_pos[0] == 254)
1502
1534
  {
1503
 
    sql_print_information(_("Slave: received end packet from server, apparent "
1504
 
                            "master shutdown: %s"),
1505
 
                     drizzle_error(drizzle));
 
1535
    sql_print_information("Slave: received end packet from server, apparent "
 
1536
                          "master shutdown: %s",
 
1537
                     mysql_error(mysql));
1506
1538
     return(packet_error);
1507
1539
  }
1508
1540
 
1510
1542
}
1511
1543
 
1512
1544
 
1513
 
int32_t check_expected_error(THD* thd __attribute__((unused)),
1514
 
                         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__)),
1515
1547
                         int32_t expected_error)
1516
1548
{
1517
1549
  switch (expected_error) {
1654
1686
    {
1655
1687
      char buf[22];
1656
1688
      rli->report(ERROR_LEVEL, ER_UNKNOWN_ERROR,
1657
 
                  _("It was not possible to update the positions"
 
1689
                  "It was not possible to update the positions"
1658
1690
                  " of the relay log information: the slave may"
1659
1691
                  " be in an inconsistent state."
1660
 
                  " Stopped in %s position %s"),
1661
 
                  rli->group_relay_log_name.c_str(),
 
1692
                  " Stopped in %s position %s",
 
1693
                  rli->group_relay_log_name,
1662
1694
                  llstr(rli->group_relay_log_pos, buf));
1663
1695
      return(2);
1664
1696
    }
1729
1761
                                ev->log_pos - ev->data_written))
1730
1762
    {
1731
1763
      char buf[22];
1732
 
      sql_print_information(_("Slave SQL thread stopped because it reached its"
1733
 
                              " UNTIL position %s"),
1734
 
                            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));
1735
1766
      /*
1736
1767
        Setting abort_slave flag because we do not want additional message about
1737
1768
        error in query execution to be printed.
1782
1813
        */
1783
1814
        if (rli->trans_retries < slave_trans_retries)
1784
1815
        {
1785
 
          if (rli->mi->init_master_info(0, 0, SLAVE_SQL))
1786
 
            sql_print_error(_("Failed to initialize the master info structure"));
 
1816
          if (init_master_info(rli->mi, 0, 0, 0, SLAVE_SQL))
 
1817
            sql_print_error("Failed to initialize the master info structure");
1787
1818
          else if (init_relay_log_pos(rli,
1788
 
                                      rli->group_relay_log_name.c_str(),
 
1819
                                      rli->group_relay_log_name,
1789
1820
                                      rli->group_relay_log_pos,
1790
1821
                                      1, &errmsg, 1))
1791
 
            sql_print_error(_("Error initializing relay log position: %s"),
 
1822
            sql_print_error("Error initializing relay log position: %s",
1792
1823
                            errmsg);
1793
1824
          else
1794
1825
          {
1795
1826
            exec_res= 0;
1796
1827
            end_trans(thd, ROLLBACK);
1797
1828
            /* chance for concurrent connection to get more locks */
1798
 
            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),
1799
1830
                       (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);
1800
1831
            pthread_mutex_lock(&rli->data_lock); // because of SHOW STATUS
1801
1832
            rli->trans_retries++;
1804
1835
          }
1805
1836
        }
1806
1837
        else
1807
 
          sql_print_error(_("Slave SQL thread retried transaction %lu time(s) "
1808
 
                            "in vain, giving up. Consider raising the value of "
1809
 
                            "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.",
1810
1841
                          slave_trans_retries);
1811
1842
      }
1812
1843
      else if ((exec_res && !temp_err) ||
1826
1857
  }
1827
1858
  pthread_mutex_unlock(&rli->data_lock);
1828
1859
  rli->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_READ_FAILURE,
1829
 
              ER(ER_SLAVE_RELAY_LOG_READ_FAILURE),
1830
 
              _("Could not parse relay log event entry. The possible reasons "
1831
 
                "are: the master's binary log is corrupted (you can check this "
1832
 
                "by running 'mysqlbinlog' on the binary log), the slave's "
1833
 
                "relay log is corrupted (you can check this by running "
1834
 
                "'mysqlbinlog' on the relay log), a network problem, or a bug "
1835
 
                "in the master's or slave's DRIZZLE code. If you want to check "
1836
 
                "the master's binary log or slave's relay log, you will be "
1837
 
                "able to know their names by issuing 'SHOW SLAVE STATUS' "
1838
 
                "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
");
1839
1869
  return(1);
1840
1870
}
1841
1871
 
1854
1884
  no messages are added to the log.
1855
1885
 
1856
1886
  @param[in]     thd                 Thread context.
1857
 
  @param[in]     DRIZZLE               DRIZZLE connection.
 
1887
  @param[in]     mysql               MySQL connection.
1858
1888
  @param[in]     mi                  Master connection information.
1859
1889
  @param[in,out] retry_count         Number of attempts to reconnect.
1860
1890
  @param[in]     suppress_warnings   TRUE when a normal net read timeout 
1866
1896
  @retval        1                   There was an error.
1867
1897
*/
1868
1898
 
1869
 
static int32_t try_to_reconnect(THD *thd, DRIZZLE *drizzle, Master_info *mi,
1870
 
                                uint32_t *retry_count, bool suppress_warnings,
1871
 
                                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])
1872
1902
{
1873
 
  mi->slave_running= DRIZZLE_SLAVE_RUN_NOT_CONNECT;
1874
 
  thd->set_proc_info(_(messages[SLAVE_RECON_MSG_WAIT]));
1875
 
  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);
1876
1909
  if ((*retry_count)++)
1877
1910
  {
1878
1911
    if (*retry_count > master_retry_count)
1880
1913
    safe_sleep(thd, mi->connect_retry, (CHECK_KILLED_FUNC) io_slave_killed,
1881
1914
               (void *) mi);
1882
1915
  }
1883
 
  if (check_io_slave_killed(thd, mi,
1884
 
                            _(messages[SLAVE_RECON_MSG_KILLED_WAITING])))
 
1916
  if (check_io_slave_killed(thd, mi, messages[SLAVE_RECON_MSG_KILLED_WAITING]))
1885
1917
    return 1;
1886
 
  thd->set_proc_info(_(messages[SLAVE_RECON_MSG_AFTER]));
1887
 
  if (!suppress_warnings)
 
1918
  thd->proc_info = messages[SLAVE_RECON_MSG_AFTER];
 
1919
  if (!suppress_warnings) 
1888
1920
  {
1889
1921
    char buf[256], llbuff[22];
1890
 
    snprintf(buf, sizeof(buf), _(messages[SLAVE_RECON_MSG_FAILED]),
1891
 
             IO_RPL_LOG_NAME, llstr(mi->getLogPosition(), llbuff));
1892
 
    /*
 
1922
    snprintf(buf, sizeof(buf), messages[SLAVE_RECON_MSG_FAILED], 
 
1923
             IO_RPL_LOG_NAME, llstr(mi->master_log_pos, llbuff));
 
1924
    /* 
1893
1925
      Raise a warining during registering on master/requesting dump.
1894
1926
      Log a message reading event.
1895
1927
    */
1896
 
    if (_(messages[SLAVE_RECON_MSG_COMMAND])[0])
 
1928
    if (messages[SLAVE_RECON_MSG_COMMAND][0])
1897
1929
    {
1898
1930
      mi->report(WARNING_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
1899
 
                 ER(ER_SLAVE_MASTER_COM_FAILURE),
1900
 
                 _(messages[SLAVE_RECON_MSG_COMMAND]), buf);
 
1931
                 ER(ER_SLAVE_MASTER_COM_FAILURE), 
 
1932
                 messages[SLAVE_RECON_MSG_COMMAND], buf);
1901
1933
    }
1902
1934
    else
1903
1935
    {
1904
1936
      sql_print_information(buf);
1905
1937
    }
1906
1938
  }
1907
 
  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))
1908
1940
  {
1909
1941
    if (global_system_variables.log_warnings)
1910
 
      sql_print_information(_(messages[SLAVE_RECON_MSG_KILLED_AFTER]));
 
1942
      sql_print_information(messages[SLAVE_RECON_MSG_KILLED_AFTER]);
1911
1943
    return 1;
1912
1944
  }
1913
1945
  return 0;
1919
1951
pthread_handler_t handle_slave_io(void *arg)
1920
1952
{
1921
1953
  THD *thd; // needs to be first for thread_stack
1922
 
  DRIZZLE *drizzle;
 
1954
  MYSQL *mysql;
1923
1955
  Master_info *mi = (Master_info*)arg;
1924
1956
  Relay_log_info *rli= &mi->rli;
1925
1957
  char llbuff[22];
1929
1961
  my_thread_init();
1930
1962
 
1931
1963
  assert(mi->inited);
1932
 
  drizzle= NULL ;
 
1964
  mysql= NULL ;
1933
1965
  retry_count= 0;
1934
1966
 
1935
1967
  pthread_mutex_lock(&mi->run_lock);
1948
1980
  {
1949
1981
    pthread_cond_broadcast(&mi->start_cond);
1950
1982
    pthread_mutex_unlock(&mi->run_lock);
1951
 
    sql_print_error(_("Failed during slave I/O thread initialization"));
 
1983
    sql_print_error("Failed during slave I/O thread initialization");
1952
1984
    goto err;
1953
1985
  }
1954
1986
  pthread_mutex_lock(&LOCK_thread_count);
1959
1991
  pthread_mutex_unlock(&mi->run_lock);
1960
1992
  pthread_cond_broadcast(&mi->start_cond);
1961
1993
 
1962
 
  if (!(mi->drizzle= drizzle = drizzle_create(NULL)))
 
1994
  if (!(mi->mysql = mysql = mysql_init(NULL)))
1963
1995
  {
1964
1996
    mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
1965
 
               ER(ER_SLAVE_FATAL_ERROR), _("error in drizzle_create()"));
 
1997
               ER(ER_SLAVE_FATAL_ERROR), "error in mysql_init()");
1966
1998
    goto err;
1967
1999
  }
1968
2000
 
1969
 
  thd->set_proc_info("Connecting to master");
 
2001
  thd_proc_info(thd, "Connecting to master");
1970
2002
  // we can get killed during safe_connect
1971
 
  if (!safe_connect(thd, drizzle, mi))
 
2003
  if (!safe_connect(thd, mysql, mi))
1972
2004
  {
1973
 
    sql_print_information(_("Slave I/O thread: connected to master '%s@%s:%d',"
1974
 
                            "replication started in log '%s' at position %s"),
1975
 
                          mi->getUsername(), mi->getHostname(), mi->getPort(),
 
2005
    sql_print_information("Slave I/O thread: connected to master '%s@%s:%d',"
 
2006
                          "replication started in log '%s' at position %s",
 
2007
                          mi->user, mi->host, mi->port,
1976
2008
                          IO_RPL_LOG_NAME,
1977
 
                          llstr(mi->getLogPosition(), llbuff));
 
2009
                          llstr(mi->master_log_pos,llbuff));
1978
2010
  /*
1979
2011
    Adding MAX_LOG_EVENT_HEADER_LEN to the max_packet_size on the I/O
1980
2012
    thread, since a replication event can become this much larger than
1981
2013
    the corresponding packet (query) sent from client to master.
1982
2014
  */
1983
 
    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;
1984
2016
  }
1985
2017
  else
1986
2018
  {
1987
 
    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");
1988
2020
    goto err;
1989
2021
  }
1990
2022
 
1991
2023
connected:
1992
2024
 
1993
2025
  // TODO: the assignment below should be under mutex (5.0)
1994
 
  mi->slave_running= DRIZZLE_SLAVE_RUN_CONNECT;
1995
 
  thd->slave_net = &drizzle->net;
1996
 
  thd->set_proc_info("Checking master version");
1997
 
  if (get_master_version_and_clock(drizzle, mi))
 
2026
  mi->slave_running= MYSQL_SLAVE_RUN_CONNECT;
 
2027
  thd->slave_net = &mysql->net;
 
2028
  thd_proc_info(thd, "Checking master version");
 
2029
  if (get_master_version_and_clock(mysql, mi))
1998
2030
    goto err;
1999
 
  
 
2031
 
2000
2032
  if (mi->rli.relay_log.description_event_for_queue->binlog_version > 1)
2001
2033
  {
2002
2034
    /*
2003
2035
      Register ourselves with the master.
2004
2036
    */
2005
 
    thd->set_proc_info("Registering slave on master");
2006
 
    if (register_slave_on_master(drizzle, mi, &suppress_warnings))
 
2037
    thd_proc_info(thd, "Registering slave on master");
 
2038
    if (register_slave_on_master(mysql, mi, &suppress_warnings))
2007
2039
    {
2008
2040
      if (!check_io_slave_killed(thd, mi, "Slave I/O thread killed "
2009
 
                                 "while registering slave on master"))
 
2041
                                "while registering slave on master"))
2010
2042
      {
2011
 
        sql_print_error(_("Slave I/O thread couldn't register on master"));
2012
 
        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,
2013
2045
                             reconnect_messages[SLAVE_RECON_ACT_REG]))
2014
2046
          goto err;
2015
2047
      }
2020
2052
    if (!retry_count_reg)
2021
2053
    {
2022
2054
      retry_count_reg++;
2023
 
      sql_print_information(_("Forcing to reconnect slave I/O thread"));
2024
 
      if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2025
 
                           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]))
2026
2058
        goto err;
2027
2059
      goto connected;
2028
2060
    }
2030
2062
 
2031
2063
  while (!io_slave_killed(thd,mi))
2032
2064
  {
2033
 
    thd->set_proc_info("Requesting binlog dump");
2034
 
    if (request_dump(drizzle, mi, &suppress_warnings))
 
2065
    thd_proc_info(thd, "Requesting binlog dump");
 
2066
    if (request_dump(mysql, mi, &suppress_warnings))
2035
2067
    {
2036
 
      sql_print_error(_("Failed on request_dump()"));
2037
 
      if (check_io_slave_killed(thd, mi, _("Slave I/O thread killed while \
2038
 
requesting master dump")) ||
2039
 
          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,
2040
2072
                           reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2041
2073
        goto err;
2042
2074
      goto connected;
2044
2076
    if (!retry_count_dump)
2045
2077
    {
2046
2078
      retry_count_dump++;
2047
 
      sql_print_information(_("Forcing to reconnect slave I/O thread"));
2048
 
      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,
2049
2081
                           reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2050
2082
        goto err;
2051
2083
      goto connected;
2055
2087
    {
2056
2088
      uint32_t event_len;
2057
2089
      /*
2058
 
        We say "waiting" because read_event() will wait if there's nothing to
2059
 
        read. But if there's something to read, it will not wait. The
2060
 
        important thing is to not confuse users by saying "reading" whereas
2061
 
        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.
2062
2094
      */
2063
 
      thd->set_proc_info(_("Waiting for master to send event"));
2064
 
      event_len= read_event(drizzle, mi, &suppress_warnings);
2065
 
      if (check_io_slave_killed(thd, mi, _("Slave I/O thread killed while "
2066
 
                                           "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"))
2067
2099
        goto err;
2068
2100
      if (!retry_count_event)
2069
2101
      {
2070
2102
        retry_count_event++;
2071
 
        sql_print_information(_("Forcing to reconnect slave I/O thread"));
2072
 
        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,
2073
2105
                             reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2074
2106
          goto err;
2075
2107
        goto connected;
2077
2109
 
2078
2110
      if (event_len == packet_error)
2079
2111
      {
2080
 
        uint32_t drizzle_error_number= drizzle_errno(drizzle);
2081
 
        switch (drizzle_error_number) {
 
2112
        uint32_t mysql_error_number= mysql_errno(mysql);
 
2113
        switch (mysql_error_number) {
2082
2114
        case CR_NET_PACKET_TOO_LARGE:
2083
 
          sql_print_error(_("Log entry on master is longer than "
2084
 
                            "max_allowed_packet (%ld) on "
2085
 
                            "slave. If the entry is correct, restart the "
2086
 
                            "server with a higher value of "
2087
 
                            "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",
2088
2119
                          thd->variables.max_allowed_packet);
2089
2120
          goto err;
2090
2121
        case ER_MASTER_FATAL_ERROR_READING_BINLOG:
2091
 
          sql_print_error(ER(drizzle_error_number), drizzle_error_number,
2092
 
                          drizzle_error(drizzle));
 
2122
          sql_print_error(ER(mysql_error_number), mysql_error_number,
 
2123
                          mysql_error(mysql));
2093
2124
          goto err;
2094
2125
        case EE_OUTOFMEMORY:
2095
2126
        case ER_OUTOFMEMORY:
2096
 
          sql_print_error(
2097
 
       _("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");
2098
2129
          goto err;
2099
2130
        }
2100
 
        if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
 
2131
        if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2101
2132
                             reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2102
2133
          goto err;
2103
2134
        goto connected;
2104
2135
      } // if (event_len == packet_error)
2105
2136
 
2106
2137
      retry_count=0;                    // ok event, reset retry counter
2107
 
      thd->set_proc_info(_("Queueing master event to the relay log"));
2108
 
      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))
2109
2140
      {
2110
2141
        goto err;
2111
2142
      }
2112
 
      if (mi->flush())
 
2143
      if (flush_master_info(mi, 1))
2113
2144
      {
2114
 
        sql_print_error(_("Failed to flush master info file"));
 
2145
        sql_print_error("Failed to flush master info file");
2115
2146
        goto err;
2116
2147
      }
2117
2148
      /*
2131
2162
          !rli->ignore_log_space_limit)
2132
2163
        if (wait_for_relay_log_space(rli))
2133
2164
        {
2134
 
          sql_print_error(_("Slave I/O thread aborted while waiting for "
2135
 
                            "relay log space"));
 
2165
          sql_print_error("Slave I/O thread aborted while waiting for relay \
 
2166
log space");
2136
2167
          goto err;
2137
2168
        }
2138
2169
    }
2139
2170
  }
2140
2171
 
2141
 
// error = 0;
 
2172
  // error = 0;
2142
2173
err:
2143
 
// print the current replication position
2144
 
  sql_print_information(_("Slave I/O thread exiting, read up to log '%s', "
2145
 
                          "position %s"),
2146
 
                        IO_RPL_LOG_NAME, llstr(mi->getLogPosition(), llbuff));
2147
 
  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));
2148
2178
  thd->query = thd->db = 0; // extra safety
2149
2179
  thd->query_length= thd->db_length= 0;
2150
 
  pthread_mutex_unlock(&LOCK_thread_count);
2151
 
  if (drizzle)
 
2180
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
2181
  if (mysql)
2152
2182
  {
2153
2183
    /*
2154
2184
      Here we need to clear the active VIO before closing the
2158
2188
      can be called in the middle of closing the VIO associated with
2159
2189
      the 'mysql' object, causing a crash.
2160
2190
    */
2161
 
    drizzle_close(drizzle);
2162
 
    mi->drizzle=0;
 
2191
#ifdef SIGNAL_WITH_VIO_CLOSE
 
2192
    thd->clear_active_vio();
 
2193
#endif
 
2194
    mysql_close(mysql);
 
2195
    mi->mysql=0;
2163
2196
  }
2164
2197
  write_ignored_events_info_to_relay_log(thd, mi);
2165
 
  thd->set_proc_info(_("Waiting for slave mutex on exit"));
 
2198
  thd_proc_info(thd, "Waiting for slave mutex on exit");
2166
2199
  pthread_mutex_lock(&mi->run_lock);
2167
2200
 
2168
2201
  /* Forget the relay log's format */
2169
2202
  delete mi->rli.relay_log.description_event_for_queue;
2170
2203
  mi->rli.relay_log.description_event_for_queue= 0;
 
2204
  // TODO: make rpl_status part of Master_info
 
2205
  change_rpl_status(RPL_ACTIVE_SLAVE,RPL_IDLE_SLAVE);
2171
2206
  assert(thd->net.buff != 0);
2172
2207
  net_end(&thd->net); // destructor will not free it, because net.vio is 0
2173
2208
  close_thread_tables(thd);
2226
2261
    */
2227
2262
    pthread_cond_broadcast(&rli->start_cond);
2228
2263
    pthread_mutex_unlock(&rli->run_lock);
2229
 
    sql_print_error(_("Failed during slave thread initialization"));
 
2264
    sql_print_error("Failed during slave thread initialization");
2230
2265
    goto err;
2231
2266
  }
2232
2267
  thd->init_for_queries();
2265
2300
  rli->trans_retries= 0; // start from "no error"
2266
2301
 
2267
2302
  if (init_relay_log_pos(rli,
2268
 
                         rli->group_relay_log_name.c_str(),
 
2303
                         rli->group_relay_log_name,
2269
2304
                         rli->group_relay_log_pos,
2270
2305
                         1 /*need data lock*/, &errmsg,
2271
2306
                         1 /*look for a description_event*/))
2272
2307
  {
2273
 
    sql_print_error(_("Error initializing relay log position: %s"),
 
2308
    sql_print_error("Error initializing relay log position: %s",
2274
2309
                    errmsg);
2275
2310
    goto err;
2276
2311
  }
2292
2327
  assert(rli->sql_thd == thd);
2293
2328
 
2294
2329
  if (global_system_variables.log_warnings)
2295
 
    sql_print_information(_("Slave SQL thread initialized, "
2296
 
                            "starting replication in log '%s' at "
2297
 
                            "position %s, relay log '%s' position: %s"),
2298
 
                            RPL_LOG_NAME,
2299
 
                          llstr(rli->group_master_log_pos,llbuff),
2300
 
                          rli->group_relay_log_name.c_str(),
2301
 
                          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));
2302
2334
 
2303
2335
  /* execute init_slave variable */
2304
2336
  if (sys_init_slave.value_length)
2306
2338
    execute_init_command(thd, &sys_init_slave, &LOCK_sys_init_slave);
2307
2339
    if (thd->is_slave_error)
2308
2340
    {
2309
 
      sql_print_error(_("Slave SQL thread aborted. "
2310
 
                        "Can't execute init_slave query"));
 
2341
      sql_print_error("\
 
2342
Slave SQL thread aborted. Can't execute init_slave query");
2311
2343
      goto err;
2312
2344
    }
2313
2345
  }
2321
2353
      rli->is_until_satisfied(rli->group_master_log_pos))
2322
2354
  {
2323
2355
    char buf[22];
2324
 
    sql_print_information(_("Slave SQL thread stopped because it reached its"
2325
 
                            " 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));
2326
2358
    pthread_mutex_unlock(&rli->data_lock);
2327
2359
    goto err;
2328
2360
  }
2332
2364
 
2333
2365
  while (!sql_slave_killed(thd,rli))
2334
2366
  {
2335
 
    thd->set_proc_info(_("Reading event from the relay log"));
 
2367
    thd_proc_info(thd, "Reading event from the relay log");
2336
2368
    assert(rli->sql_thd == thd);
2337
2369
    THD_CHECK_SENTRY(thd);
2338
2370
    if (exec_relay_log_event(thd,rli))
2345
2377
          codes and warnings and print this to the error log as to
2346
2378
          allow the user to locate the error
2347
2379
        */
2348
 
        uint32_t const last_errno= rli->last_error().number;
 
2380
        uint32 const last_errno= rli->last_error().number;
2349
2381
 
2350
2382
        if (thd->is_error())
2351
2383
        {
2357
2389
          }
2358
2390
          else if (last_errno != thd->main_da.sql_errno())
2359
2391
          {
2360
 
            sql_print_error(_("Slave (additional info): %s Error_code: %d"),
 
2392
            sql_print_error("Slave (additional info): %s Error_code: %d",
2361
2393
                            errmsg, thd->main_da.sql_errno());
2362
2394
          }
2363
2395
        }
2364
2396
 
2365
2397
        /* Print any warnings issued */
2366
 
        List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
2367
 
        DRIZZLE_ERROR *err;
 
2398
        List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
 
2399
        MYSQL_ERROR *err;
2368
2400
        /*
2369
2401
          Added controlled slave thread cancel for replication
2370
2402
          of user-defined variables.
2374
2406
        {
2375
2407
          if (err->code == ER_CANT_OPEN_LIBRARY)
2376
2408
            udf_error = true;
2377
 
          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);
2378
2410
        }
2379
2411
        if (udf_error)
2380
 
          sql_print_error(_("Error loading user-defined library, slave SQL "
2381
 
                            "thread aborted. Install the missing library, "
2382
 
                            "and restart the slave SQL thread with "
2383
 
                            "\"SLAVE START\". We stopped at log '%s' "
2384
 
                            "position %s"),
2385
 
                          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, 
2386
2416
            llbuff));
2387
2417
        else
2388
 
          sql_print_error(_("Error running query, slave SQL thread aborted. "
2389
 
                            "Fix the problem, and restart "
2390
 
                            "the slave SQL thread with \"SLAVE START\". "
2391
 
                            "We stopped at log '%s' position %s"),
2392
 
                          RPL_LOG_NAME,
2393
 
                          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));
2394
2422
      }
2395
2423
      goto err;
2396
2424
    }
2397
2425
  }
2398
2426
 
2399
2427
  /* Thread stopped. Print the current replication position to the log */
2400
 
  sql_print_information(_("Slave SQL thread exiting, replication stopped in "
2401
 
                          "log '%s' at position %s"),
2402
 
                        RPL_LOG_NAME,
2403
 
                        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));
2404
2431
 
2405
2432
 err:
2406
2433
 
2411
2438
    must "proactively" clear playgrounds:
2412
2439
  */
2413
2440
  rli->cleanup_context(thd, 1);
2414
 
  pthread_mutex_lock(&LOCK_thread_count);
 
2441
  VOID(pthread_mutex_lock(&LOCK_thread_count));
2415
2442
  /*
2416
2443
    Some extra safety, which should not been needed (normally, event deletion
2417
2444
    should already have done these assignments (each event which sets these
2419
2446
  */
2420
2447
  thd->query= thd->db= thd->catalog= 0;
2421
2448
  thd->query_length= thd->db_length= 0;
2422
 
  pthread_mutex_unlock(&LOCK_thread_count);
2423
 
  thd->set_proc_info("Waiting for slave mutex on exit");
 
2449
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
2450
  thd_proc_info(thd, "Waiting for slave mutex on exit");
2424
2451
  pthread_mutex_lock(&rli->run_lock);
2425
2452
  /* We need data_lock, at least to wake up any waiting master_pos_wait() */
2426
2453
  pthread_mutex_lock(&rli->data_lock);
2434
2461
  pthread_mutex_unlock(&rli->data_lock);
2435
2462
  pthread_cond_broadcast(&rli->data_cond);
2436
2463
  rli->ignore_log_space_limit= 0; /* don't need any lock */
 
2464
  /* we die so won't remember charset - re-update them on next thread start */
 
2465
  rli->cached_charset_invalidate();
2437
2466
  rli->save_temporary_tables = thd->temporary_tables;
2438
2467
 
2439
2468
  /*
2474
2503
  uint32_t num_bytes;
2475
2504
  bool cev_not_written;
2476
2505
  THD *thd = mi->io_thd;
2477
 
  NET *net = &mi->drizzle->net;
 
2506
  NET *net = &mi->mysql->net;
2478
2507
 
2479
2508
  if (unlikely(!cev->is_valid()))
2480
2509
    return(1);
2491
2520
 
2492
2521
  if (unlikely(net_request_file(net,cev->fname)))
2493
2522
  {
2494
 
    sql_print_error(_("Slave I/O: failed requesting download of '%s'"),
 
2523
    sql_print_error("Slave I/O: failed requesting download of '%s'",
2495
2524
                    cev->fname);
2496
2525
    goto err;
2497
2526
  }
2508
2537
    {
2509
2538
      if (unlikely((num_bytes=my_net_read(net)) == packet_error))
2510
2539
      {
2511
 
        sql_print_error(_("Network read error downloading '%s' from master"),
 
2540
        sql_print_error("Network read error downloading '%s' from master",
2512
2541
                        cev->fname);
2513
2542
        goto err;
2514
2543
      }
2515
2544
      if (unlikely(!num_bytes)) /* eof */
2516
2545
      {
2517
2546
        /* 3.23 master wants it */
2518
 
        net_write_command(net, 0, (unsigned char*) "", 0, (unsigned char*) "", 0);
 
2547
        net_write_command(net, 0, (uchar*) "", 0, (uchar*) "", 0);
2519
2548
        /*
2520
2549
          If we wrote Create_file_log_event, then we need to write
2521
2550
          Execute_load_log_event. If we did not write Create_file_log_event,
2530
2559
        {
2531
2560
          mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
2532
2561
                     ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
2533
 
                     _("error writing Exec_load event to relay log"));
 
2562
                     "error writing Exec_load event to relay log");
2534
2563
          goto err;
2535
2564
        }
2536
2565
        mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total);
2544
2573
        {
2545
2574
          mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
2546
2575
                     ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
2547
 
                     _("error writing Create_file event to relay log"));
 
2576
                     "error writing Create_file event to relay log");
2548
2577
          goto err;
2549
2578
        }
2550
2579
        cev_not_written=0;
2559
2588
        {
2560
2589
          mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
2561
2590
                     ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
2562
 
                     _("error writing Append_block event to relay log"));
 
2591
                     "error writing Append_block event to relay log");
2563
2592
          goto err;
2564
2593
        }
2565
2594
        mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total) ;
2602
2631
    return(1);
2603
2632
 
2604
2633
  /* Safe copy as 'rev' has been "sanitized" in Rotate_log_event's ctor */
2605
 
  mi->setLogName(rev->new_log_ident);
2606
 
  mi->setLogPosition(rev->pos);
 
2634
  memcpy(mi->master_log_name, rev->new_log_ident, rev->ident_len+1);
 
2635
  mi->master_log_pos= rev->pos;
2607
2636
  /*
2608
2637
    If we do not do this, we will be getting the first
2609
2638
    rotate event forever, so we need to not disconnect after one.
2621
2650
  if (mi->rli.relay_log.description_event_for_queue->binlog_version >= 4)
2622
2651
  {
2623
2652
    delete mi->rli.relay_log.description_event_for_queue;
2624
 
    /* start from format 3 (DRIZZLE 4.0) again */
 
2653
    /* start from format 3 (MySQL 4.0) again */
2625
2654
    mi->rli.relay_log.description_event_for_queue= new
2626
2655
      Format_description_log_event(3);
2627
2656
  }
2635
2664
 
2636
2665
/*
2637
2666
  Reads a 3.23 event and converts it to the slave's format. This code was
2638
 
  copied from DRIZZLE 4.0.
 
2667
  copied from MySQL 4.0.
2639
2668
*/
2640
2669
static int32_t queue_binlog_ver_1_event(Master_info *mi, const char *buf,
2641
2670
                           uint32_t event_len)
2655
2684
    if (unlikely(!(tmp_buf=(char*)my_malloc(event_len+1,MYF(MY_WME)))))
2656
2685
    {
2657
2686
      mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
2658
 
                 ER(ER_SLAVE_FATAL_ERROR), _("Memory allocation failed"));
 
2687
                 ER(ER_SLAVE_FATAL_ERROR), "Memory allocation failed");
2659
2688
      return(1);
2660
2689
    }
2661
2690
    memcpy(tmp_buf,buf,event_len);
2680
2709
                                            mi->rli.relay_log.description_event_for_queue);
2681
2710
  if (unlikely(!ev))
2682
2711
  {
2683
 
    sql_print_error(_("Read invalid event from master: '%s', "
2684
 
                      "master could be corrupt but a more likely cause "
2685
 
                      "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",
2686
2714
                    errmsg);
2687
 
    free((char*) tmp_buf);
 
2715
    my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
2688
2716
    return(1);
2689
2717
  }
2690
2718
 
2691
2719
  pthread_mutex_lock(&mi->data_lock);
2692
 
  ev->log_pos= mi->getLogPosition(); /* 3.23 events don't contain log_pos */
 
2720
  ev->log_pos= mi->master_log_pos; /* 3.23 events don't contain log_pos */
2693
2721
  switch (ev->get_type_code()) {
2694
2722
  case STOP_EVENT:
2695
2723
    ignore_event= 1;
2718
2746
    ev->log_pos+= inc_pos;
2719
2747
    int32_t error = process_io_create_file(mi,(Create_file_log_event*)ev);
2720
2748
    delete ev;
2721
 
    mi->incrementLogPosition(inc_pos);
 
2749
    mi->master_log_pos += inc_pos;
2722
2750
    pthread_mutex_unlock(&mi->data_lock);
2723
 
    free((char*)tmp_buf);
 
2751
    my_free((char*)tmp_buf, MYF(0));
2724
2752
    return(error);
2725
2753
  }
2726
2754
  default:
2744
2772
    rli->relay_log.harvest_bytes_written(&rli->log_space_total);
2745
2773
  }
2746
2774
  delete ev;
2747
 
  mi->incrementLogPosition(inc_pos);
 
2775
  mi->master_log_pos+= inc_pos;
2748
2776
  pthread_mutex_unlock(&mi->data_lock);
2749
2777
  return(0);
2750
2778
}
2766
2794
                                            mi->rli.relay_log.description_event_for_queue);
2767
2795
  if (unlikely(!ev))
2768
2796
  {
2769
 
    sql_print_error(_("Read invalid event from master: '%s', "
2770
 
                      "master could be corrupt but a more likely cause of "
2771
 
                      "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",
2772
2799
                    errmsg);
2773
 
    free((char*) tmp_buf);
 
2800
    my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
2774
2801
    return(1);
2775
2802
  }
2776
2803
  pthread_mutex_lock(&mi->data_lock);
2798
2825
  }
2799
2826
  rli->relay_log.harvest_bytes_written(&rli->log_space_total);
2800
2827
  delete ev;
2801
 
  mi->incrementLogPosition(inc_pos);
 
2828
  mi->master_log_pos+= inc_pos;
2802
2829
err:
2803
2830
  pthread_mutex_unlock(&mi->data_lock);
2804
2831
  return(0);
2844
2871
{
2845
2872
  int32_t error= 0;
2846
2873
  String error_msg;
2847
 
  uint32_t inc_pos= 0;
 
2874
  uint32_t inc_pos;
2848
2875
  Relay_log_info *rli= &mi->rli;
2849
2876
  pthread_mutex_t *log_lock= rli->relay_log.get_log_lock();
2850
2877
 
2950
2977
 
2951
2978
       TODO: handling `when' for SHOW SLAVE STATUS' snds behind
2952
2979
    */
2953
 
    if ((mi->setLogName(hb.get_log_ident()) && mi->getLogName() != NULL)
2954
 
        || mi->getLogPosition() != hb.log_pos)
 
2980
    if ((memcmp(mi->master_log_name, hb.get_log_ident(), hb.get_ident_len())
 
2981
         && mi->master_log_name != NULL)
 
2982
        || mi->master_log_pos != hb.log_pos)
2955
2983
    {
2956
2984
      /* missed events of heartbeat from the past */
2957
2985
      error= ER_SLAVE_HEARTBEAT_FAILURE;
3008
3036
        buf[EVENT_TYPE_OFFSET]!=ROTATE_EVENT &&
3009
3037
        buf[EVENT_TYPE_OFFSET]!=STOP_EVENT)
3010
3038
    {
3011
 
      mi->incrementLogPosition(inc_pos);
3012
 
      memcpy(rli->ign_master_log_name_end, mi->getLogName(), FN_REFLEN);
 
3039
      mi->master_log_pos+= inc_pos;
 
3040
      memcpy(rli->ign_master_log_name_end, mi->master_log_name, FN_REFLEN);
3013
3041
      assert(rli->ign_master_log_name_end[0]);
3014
 
      rli->ign_master_log_pos_end= mi->getLogPosition();
 
3042
      rli->ign_master_log_pos_end= mi->master_log_pos;
3015
3043
    }
3016
3044
    rli->relay_log.signal_update(); // the slave SQL thread needs to re-check
3017
3045
  }
3020
3048
    /* write the event to the relay log */
3021
3049
    if (likely(!(rli->relay_log.appendv(buf,event_len,0))))
3022
3050
    {
3023
 
      mi->incrementLogPosition(inc_pos);
 
3051
      mi->master_log_pos+= inc_pos;
3024
3052
      rli->relay_log.harvest_bytes_written(&rli->log_space_total);
3025
3053
    }
3026
3054
    else
3036
3064
err:
3037
3065
  pthread_mutex_unlock(&mi->data_lock);
3038
3066
  if (error)
3039
 
    mi->report(ERROR_LEVEL, error, ER(error),
 
3067
    mi->report(ERROR_LEVEL, error, ER(error), 
3040
3068
               (error == ER_SLAVE_RELAY_LOG_WRITE_FAILURE)?
3041
 
               _("could not queue event from master") :
 
3069
               "could not queue event from master" :
3042
3070
               error_msg.ptr());
3043
3071
  return(error);
3044
3072
}
3078
3106
  SYNPOSIS
3079
3107
    safe_connect()
3080
3108
    thd                 Thread handler for slave
3081
 
    DRIZZLE               DRIZZLE connection handle
 
3109
    mysql               MySQL connection handle
3082
3110
    mi                  Replication handle
3083
3111
 
3084
3112
  RETURN
3086
3114
    #   Error
3087
3115
*/
3088
3116
 
3089
 
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)
3090
3118
{
3091
 
  return(connect_to_master(thd, drizzle, mi, 0, 0));
 
3119
  return(connect_to_master(thd, mysql, mi, 0, 0));
3092
3120
}
3093
3121
 
3094
3122
 
3101
3129
    master_retry_count times
3102
3130
*/
3103
3131
 
3104
 
static int32_t connect_to_master(THD* thd, DRIZZLE *drizzle, Master_info* mi,
3105
 
                                 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)
3106
3134
{
3107
3135
  int32_t slave_was_killed;
3108
3136
  int32_t last_errno= -2;                           // impossible error
3114
3142
  if (opt_slave_compressed_protocol)
3115
3143
    client_flag=CLIENT_COMPRESS;                /* We will use compression */
3116
3144
 
3117
 
  drizzle_options(drizzle, DRIZZLE_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
3118
 
  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);
3119
3151
 
3120
3152
  while (!(slave_was_killed = io_slave_killed(thd,mi)) &&
3121
 
         (reconnect ? drizzle_reconnect(drizzle) != 0 :
3122
 
          drizzle_connect(drizzle, mi->getHostname(), mi->getUsername(), mi->getPassword(), 0,
3123
 
                             mi->getPort(), 0, client_flag) == 0))
 
3153
         (reconnect ? mysql_reconnect(mysql) != 0 :
 
3154
          mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
 
3155
                             mi->port, 0, client_flag) == 0))
3124
3156
  {
3125
3157
    /* Don't repeat last error */
3126
 
    if ((int32_t)drizzle_errno(drizzle) != last_errno)
 
3158
    if ((int32_t)mysql_errno(mysql) != last_errno)
3127
3159
    {
3128
 
      last_errno=drizzle_errno(drizzle);
 
3160
      last_errno=mysql_errno(mysql);
3129
3161
      suppress_warnings= 0;
3130
3162
      mi->report(ERROR_LEVEL, last_errno,
3131
 
                 _("error %s to master '%s@%s:%d'"
3132
 
                   " - retry-time: %d  retries: %u"),
3133
 
                 (reconnect ? _("reconnecting") : _("connecting")),
3134
 
                 mi->getUsername(), mi->getHostname(), mi->getPort(),
3135
 
                 mi->getConnectionRetry(), master_retry_count);
 
3163
                 "error %s to master '%s@%s:%d'"
 
3164
                 " - retry-time: %d  retries: %u",
 
3165
                 (reconnect ? "reconnecting" : "connecting"),
 
3166
                 mi->user, mi->host, mi->port,
 
3167
                 mi->connect_retry, master_retry_count);
3136
3168
    }
3137
3169
    /*
3138
3170
      By default we try forever. The reason is that failure will trigger
3143
3175
    if (++err_count == master_retry_count)
3144
3176
    {
3145
3177
      slave_was_killed=1;
 
3178
      if (reconnect)
 
3179
        change_rpl_status(RPL_ACTIVE_SLAVE,RPL_LOST_SOLDIER);
3146
3180
      break;
3147
3181
    }
3148
3182
    safe_sleep(thd,mi->connect_retry,(CHECK_KILLED_FUNC)io_slave_killed,
3154
3188
    if (reconnect)
3155
3189
    {
3156
3190
      if (!suppress_warnings && global_system_variables.log_warnings)
3157
 
        sql_print_information(_("Slave: connected to master '%s@%s:%d', "
3158
 
                                "replication resumed in log '%s' at "
3159
 
                                "position %s"), mi->getUsername(),
3160
 
                                mi->getHostname(), mi->getPort(),
3161
 
                                IO_RPL_LOG_NAME,
3162
 
                                llstr(mi->getLogPosition(),llbuff));
3163
 
    }
 
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));
 
3196
    }
 
3197
    else
 
3198
    {
 
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);
 
3202
    }
 
3203
#ifdef SIGNAL_WITH_VIO_CLOSE
 
3204
    thd->set_active_vio(mysql->net.vio);
 
3205
#endif
3164
3206
  }
3165
 
  drizzle->reconnect= 1;
 
3207
  mysql->reconnect= 1;
3166
3208
  return(slave_was_killed);
3167
3209
}
3168
3210
 
3175
3217
    master_retry_count times
3176
3218
*/
3177
3219
 
3178
 
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,
3179
3221
                          bool suppress_warnings)
3180
3222
{
3181
 
  return(connect_to_master(thd, drizzle, mi, 1, suppress_warnings));
 
3223
  return(connect_to_master(thd, mysql, mi, 1, suppress_warnings));
3182
3224
}
3183
3225
 
3184
3226
 
3213
3255
 
3214
3256
bool flush_relay_log_info(Relay_log_info* rli)
3215
3257
{
3216
 
  bool error= 0;
 
3258
  bool error=0;
3217
3259
 
3218
3260
  if (unlikely(rli->no_storage))
3219
3261
    return(0);
3220
3262
 
 
3263
  IO_CACHE *file = &rli->info_file;
 
3264
  char buff[FN_REFLEN*2+22*2+4], *pos;
 
3265
 
 
3266
  my_b_seek(file, 0L);
 
3267
  pos=strmov(buff, rli->group_relay_log_name);
 
3268
  *pos++='\n';
 
3269
  pos=int64_t2str(rli->group_relay_log_pos, pos, 10);
 
3270
  *pos++='\n';
 
3271
  pos=strmov(pos, rli->group_master_log_name);
 
3272
  *pos++='\n';
 
3273
  pos=int64_t2str(rli->group_master_log_pos, pos, 10);
 
3274
  *pos='\n';
 
3275
  if (my_b_write(file, (uchar*) buff, (size_t) (pos-buff)+1))
 
3276
    error=1;
 
3277
  if (flush_io_cache(file))
 
3278
    error=1;
 
3279
 
 
3280
  /* Flushing the relay log is done by the slave I/O thread */
3221
3281
  return(error);
3222
3282
}
3223
3283
 
3232
3292
  assert(rli->cur_log_fd == -1);
3233
3293
 
3234
3294
  IO_CACHE *cur_log = rli->cur_log=&rli->cache_buf;
3235
 
  if ((rli->cur_log_fd=open_binlog(cur_log, rli->event_relay_log_name.c_str(), errmsg)) < 0)
 
3295
  if ((rli->cur_log_fd=open_binlog(cur_log,rli->event_relay_log_name,
 
3296
                                   errmsg)) <0)
3236
3297
    return(0);
3237
3298
  /*
3238
3299
    We want to start exactly where we was before:
3239
3300
    relay_log_pos       Current log pos
3240
3301
    pending             Number of bytes already processed from the event
3241
3302
  */
3242
 
  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);
3243
3304
  my_b_seek(cur_log,rli->event_relay_log_pos);
3244
3305
  return(cur_log);
3245
3306
}
3320
3381
      When the relay log is created when the I/O thread starts, easy: the
3321
3382
      master will send the description event and we will queue it.
3322
3383
      But if the relay log is created by new_file(): then the solution is:
3323
 
      DRIZZLE_BIN_LOG::open() will write the buffered description event.
 
3384
      MYSQL_BIN_LOG::open() will write the buffered description event.
3324
3385
    */
3325
3386
    if ((ev=Log_event::read_log_event(cur_log,0,
3326
3387
                                      rli->relay_log.description_event_for_exec)))
3474
3535
        if (rli->relay_log.purge_first_log
3475
3536
            (rli,
3476
3537
             rli->group_relay_log_pos == rli->event_relay_log_pos
3477
 
             && !strcmp(rli->group_relay_log_name.c_str(), rli->event_relay_log_name.c_str())))
 
3538
             && !strcmp(rli->group_relay_log_name,rli->event_relay_log_name)))
3478
3539
        {
3479
3540
          errmsg = "Error purging processed logs";
3480
3541
          goto err;
3495
3556
          goto err;
3496
3557
        }
3497
3558
        rli->event_relay_log_pos = BIN_LOG_HEADER_SIZE;
3498
 
        rli->event_relay_log_name.assign(rli->linfo.log_file_name);
 
3559
        strmake(rli->event_relay_log_name,rli->linfo.log_file_name,
 
3560
                sizeof(rli->event_relay_log_name)-1);
3499
3561
        flush_relay_log_info(rli);
3500
3562
      }
3501
3563
 
3515
3577
      {
3516
3578
#ifdef EXTRA_DEBUG
3517
3579
        if (global_system_variables.log_warnings)
3518
 
          sql_print_information(_("next log '%s' is currently active"),
 
3580
          sql_print_information("next log '%s' is currently active",
3519
3581
                                rli->linfo.log_file_name);
3520
3582
#endif
3521
3583
        rli->cur_log= cur_log= rli->relay_log.get_log_file();
3545
3607
      */
3546
3608
#ifdef EXTRA_DEBUG
3547
3609
      if (global_system_variables.log_warnings)
3548
 
        sql_print_information(_("next log '%s' is not active"),
 
3610
        sql_print_information("next log '%s' is not active",
3549
3611
                              rli->linfo.log_file_name);
3550
3612
#endif
3551
3613
      // open_binlog() will check the magic header
3561
3623
      */
3562
3624
      if (hot_log)
3563
3625
        pthread_mutex_unlock(log_lock);
3564
 
      sql_print_error(_("Slave SQL thread: I/O error reading "
3565
 
                        "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)",
3566
3628
                      my_errno,cur_log->error);
3567
3629
      // set read position to the beginning of the event
3568
3630
      my_b_seek(cur_log,rli->event_relay_log_pos);
3569
3631
      /* otherwise, we have had a partial read */
3570
 
      errmsg = _("Aborting slave SQL thread because of partial event read");
 
3632
      errmsg = "Aborting slave SQL thread because of partial event read";
3571
3633
      break;                                    // To end of function
3572
3634
    }
3573
3635
  }
3574
3636
  if (!errmsg && global_system_variables.log_warnings)
3575
3637
  {
3576
 
    sql_print_information(_("Error reading relay log event: %s"),
3577
 
                          _("slave SQL thread was killed"));
 
3638
    sql_print_information("Error reading relay log event: %s",
 
3639
                          "slave SQL thread was killed");
3578
3640
    return(0);
3579
3641
  }
3580
3642
 
3581
3643
err:
3582
3644
  if (errmsg)
3583
 
    sql_print_error(_("Error reading relay log event: %s"), errmsg);
 
3645
    sql_print_error("Error reading relay log event: %s", errmsg);
3584
3646
  return(0);
3585
3647
}
3586
3648
 
3588
3650
  Rotate a relay log (this is used only by FLUSH LOGS; the automatic rotation
3589
3651
  because of size is simpler because when we do it we already have all relevant
3590
3652
  locks; here we don't, so this function is mainly taking locks).
3591
 
  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()
3592
3654
  is void).
3593
3655
*/
3594
3656
 
3643
3705
{
3644
3706
  struct st_version_range_for_one_bug {
3645
3707
    uint32_t        bug_id;
3646
 
    const unsigned char introduced_in[3]; // first version with bug
3647
 
    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
3648
3710
  };
3649
3711
  static struct st_version_range_for_one_bug versions_for_all_bugs[]=
3650
3712
  {
3653
3715
    {33029, { 5, 0,  0 }, { 5, 0, 58 } },
3654
3716
    {33029, { 5, 1,  0 }, { 5, 1, 12 } },
3655
3717
  };
3656
 
  const unsigned char *master_ver=
 
3718
  const uchar *master_ver=
3657
3719
    rli->relay_log.description_event_for_exec->server_version_split;
3658
3720
 
3659
3721
  assert(sizeof(rli->relay_log.description_event_for_exec->server_version_split) == 3);
3661
3723
  for (uint32_t i= 0;
3662
3724
       i < sizeof(versions_for_all_bugs)/sizeof(*versions_for_all_bugs);i++)
3663
3725
  {
3664
 
    const unsigned char *introduced_in= versions_for_all_bugs[i].introduced_in,
 
3726
    const uchar *introduced_in= versions_for_all_bugs[i].introduced_in,
3665
3727
      *fixed_in= versions_for_all_bugs[i].fixed_in;
3666
3728
    if ((versions_for_all_bugs[i].bug_id == bug_id) &&
3667
3729
        (memcmp(introduced_in, master_ver, 3) <= 0) &&
3668
3730
        (memcmp(fixed_in,      master_ver, 3) >  0))
3669
3731
    {
3670
3732
      if (!report)
3671
 
        return true;
3672
 
 
 
3733
        return true;
 
3734
      
3673
3735
      // a short message for SHOW SLAVE STATUS (message length constraints)
3674
 
      my_printf_error(ER_UNKNOWN_ERROR,
3675
 
                      _("master may suffer from"
3676
 
                        " http://bugs.mysql.com/bug.php?id=%u"
3677
 
                        " so slave stops; check error log on slave"
3678
 
                        " 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);
3679
3740
      // a verbose message for the error log
3680
3741
      rli->report(ERROR_LEVEL, ER_UNKNOWN_ERROR,
3681
 
                  _("According to the master's version ('%s'),"
3682
 
                    " it is probable that master suffers from this bug:"
3683
 
                    " http://bugs.mysql.com/bug.php?id=%u"
3684
 
                    " and thus replicating the current binary log event"
3685
 
                    " may make the slave's data become different from the"
3686
 
                    " master's data."
3687
 
                    " To take no risk, slave refuses to replicate"
3688
 
                    " this event and stops."
3689
 
                    " We recommend that all updates be stopped on the"
3690
 
                    " master and slave, that the data of both be"
3691
 
                    " manually synchronized,"
3692
 
                    " that master's binary logs be deleted,"
3693
 
                    " that master be upgraded to a version at least"
3694
 
                    " equal to '%d.%d.%d'. Then replication can be"
3695
 
                    " restarted."),
3696
 
                  rli->relay_log.description_event_for_exec->server_version,
3697
 
                  bug_id,
3698
 
                  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]);
3699
3760
      return true;
3700
3761
    }
3701
3762
  }
3730
3791
/**
3731
3792
  @} (end of group Replication)
3732
3793
*/
 
3794
 
 
3795
#endif /* HAVE_REPLICATION */