23
23
@brief Code to run the io thread and the sql thread on the
26
#include <drizzled/server_includes.h>
28
#include <storage/myisam/myisam.h>
27
#include "mysql_priv.h"
29
31
#include "rpl_mi.h"
30
32
#include "rpl_rli.h"
31
33
#include "sql_repl.h"
32
34
#include "rpl_filter.h"
33
35
#include "repl_failsafe.h"
34
#include <mysys/thr_alarm.h>
35
#include <libdrizzle/sql_common.h>
36
#include <libdrizzle/errmsg.h>
37
#include <mysys/mysys_err.h>
38
#include <drizzled/drizzled_error_messages.h>
36
#include <thr_alarm.h>
38
#include <sql_common.h>
40
#include <mysys_err.h>
42
#ifdef HAVE_REPLICATION
40
44
#include "rpl_tblmap.h"
84
88
static const char *reconnect_messages[SLAVE_RECON_ACT_MAX][SLAVE_RECON_MSG_MAX]=
87
N_("Waiting to reconnect after a failed registration on master"),
88
N_("Slave I/O thread killed while waitnig to reconnect after a "
89
"failed registration on master"),
90
N_("Reconnecting after a failed registration on master"),
91
N_("failed registering on master, reconnecting to try again, "
92
"log '%s' at postion %s"),
91
"Waiting to reconnect after a failed registration on master",
92
"Slave I/O thread killed while waitnig to reconnect after a failed \
93
registration on master",
94
"Reconnecting after a failed registration on master",
95
"failed registering on master, reconnecting to try again, \
96
log '%s' at postion %s",
93
97
"COM_REGISTER_SLAVE",
94
N_("Slave I/O thread killed during or after reconnect")
98
"Slave I/O thread killed during or after reconnect"
97
N_("Waiting to reconnect after a failed binlog dump request"),
98
N_("Slave I/O thread killed while retrying master dump"),
99
N_("Reconnecting after a failed binlog dump request"),
100
N_("failed dump request, reconnecting to try again, "
101
"log '%s' at postion %s"),
101
"Waiting to reconnect after a failed binlog dump request",
102
"Slave I/O thread killed while retrying master dump",
103
"Reconnecting after a failed binlog dump request",
104
"failed dump request, reconnecting to try again, log '%s' at postion %s",
102
105
"COM_BINLOG_DUMP",
103
N_("Slave I/O thread killed during or after reconnect")
106
"Slave I/O thread killed during or after reconnect"
106
N_("Waiting to reconnect after a failed master event read"),
107
N_("Slave I/O thread killed while waiting to reconnect "
108
"after a failed read"),
109
N_("Reconnecting after a failed master event read"),
110
N_("Slave I/O thread: Failed reading log event, "
111
"reconnecting to retry, log '%s' at postion %s"),
109
"Waiting to reconnect after a failed master event read",
110
"Slave I/O thread killed while waiting to reconnect after a failed read",
111
"Reconnecting after a failed master event read",
112
"Slave I/O thread: Failed reading log event, reconnecting to retry, \
113
log '%s' at postion %s",
113
N_("Slave I/O thread killed during or after a "
114
"reconnect done to recover from failed read")
115
"Slave I/O thread killed during or after a reconnect done to recover from \
124
126
static inline bool io_slave_killed(THD* thd,Master_info* mi);
125
127
static inline bool sql_slave_killed(THD* thd,Relay_log_info* rli);
126
128
static int32_t init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type);
127
static int32_t safe_connect(THD* thd, DRIZZLE *drizzle, Master_info* mi);
128
static int32_t safe_reconnect(THD* thd, DRIZZLE *drizzle, Master_info* mi,
129
static int32_t safe_connect(THD* thd, MYSQL* mysql, Master_info* mi);
130
static int32_t safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
129
131
bool suppress_warnings);
130
static int32_t connect_to_master(THD* thd, DRIZZLE *drizzle, Master_info* mi,
132
static int32_t connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
131
133
bool reconnect, bool suppress_warnings);
132
134
static int32_t safe_sleep(THD* thd, int32_t sec, CHECK_KILLED_FUNC thread_killed,
133
135
void* thread_killed_arg);
134
static int32_t get_master_version_and_clock(DRIZZLE *drizzle, Master_info* mi);
136
static int32_t get_master_version_and_clock(MYSQL* mysql, Master_info* mi);
135
137
static Log_event* next_event(Relay_log_info* rli);
136
138
static int32_t queue_event(Master_info* mi,const char* buf,uint32_t event_len);
137
139
static int32_t terminate_slave_thread(THD *thd,
502
504
int32_t start_slave_threads(bool need_slave_mutex, bool wait_for_start,
504
const char* master_info_fname __attribute__((unused)),
505
const char* slave_info_fname __attribute__((unused)),
506
const char* master_info_fname __attribute__((__unused__)),
507
const char* slave_info_fname __attribute__((__unused__)),
506
508
int32_t thread_mask)
508
510
pthread_mutex_t *lock_io=0,*lock_sql=0,*lock_cond_io=0,*lock_cond_sql=0;
611
613
if (difftime(time(0), rli->last_event_start_time) > 60)
613
615
rli->report(ERROR_LEVEL, 0,
614
_("SQL thread had to stop in an unsafe situation, in "
616
"SQL thread had to stop in an unsafe situation, in "
615
617
"the middle of applying updates to a "
616
618
"non-transactional table without any primary key. "
617
619
"There is a risk of duplicate updates when the slave "
618
620
"SQL thread is restarted. Please check your tables' "
619
"contents after restart."));
621
"contents after restart.");
636
638
(void)net_request_file(net, "/dev/null");
637
639
(void)my_net_read(net); // discard response
638
(void)net_write_command(net, 0, (unsigned char*) "", 0, (unsigned char*) "", 0); // ok
640
(void)net_write_command(net, 0, (uchar*) "", 0, (uchar*) "", 0); // ok
643
645
bool net_request_file(NET* net, const char* fname)
645
return(net_write_command(net, 251, (unsigned char*) fname, strlen(fname),
646
(unsigned char*) "", 0));
647
return(net_write_command(net, 251, (uchar*) fname, strlen(fname),
770
772
delete mi->rli.relay_log.description_event_for_queue;
771
773
mi->rli.relay_log.description_event_for_queue= 0;
773
if (!my_isdigit(&my_charset_bin,*drizzle->server_version))
775
if (!my_isdigit(&my_charset_bin,*mysql->server_version))
775
errmsg = _("Master reported unrecognized DRIZZLE version");
777
errmsg = "Master reported unrecognized MySQL version";
776
778
err_code= ER_SLAVE_FATAL_ERROR;
777
779
sprintf(err_buff, ER(err_code), errmsg);
778
780
err_msg.append(err_buff);
783
Note the following switch will bug when we have DRIZZLE branch 30 ;)
785
Note the following switch will bug when we have MySQL branch 30 ;)
785
switch (*drizzle->server_version)
787
switch (*mysql->server_version)
790
errmsg = _("Master reported unrecognized DRIZZLE version");
792
errmsg = "Master reported unrecognized MySQL version";
791
793
err_code= ER_SLAVE_FATAL_ERROR;
792
794
sprintf(err_buff, ER(err_code), errmsg);
793
795
err_msg.append(err_buff);
796
798
mi->rli.relay_log.description_event_for_queue= new
797
Format_description_log_event(1, drizzle->server_version);
799
Format_description_log_event(1, mysql->server_version);
800
802
mi->rli.relay_log.description_event_for_queue= new
801
Format_description_log_event(3, drizzle->server_version);
803
Format_description_log_event(3, mysql->server_version);
805
Master is DRIZZLE >=5.0. Give a default Format_desc event, so that we can
807
Master is MySQL >=5.0. Give a default Format_desc event, so that we can
806
808
take the early steps (like tests for "is this a 3.23 master") which we
807
809
have to take before we receive the real master's Format_desc which will
808
810
override this one. Note that the Format_desc we create below is garbage
840
842
unavailable (very old master not supporting UNIX_TIMESTAMP()?).
843
if (!drizzle_real_query(drizzle, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) &&
844
(master_res= drizzle_store_result(drizzle)) &&
845
(master_row= drizzle_fetch_row(master_res)))
845
if (!mysql_real_query(mysql, STRING_WITH_LEN("SELECT UNIX_TIMESTAMP()")) &&
846
(master_res= mysql_store_result(mysql)) &&
847
(master_row= mysql_fetch_row(master_res)))
847
849
mi->clock_diff_with_master=
848
850
(long) (time((time_t*) 0) - strtoul(master_row[0], 0, 10));
850
852
else if (!check_io_slave_killed(mi->io_thd, mi, NULL))
852
854
mi->clock_diff_with_master= 0; /* The "most sensible" value */
853
sql_print_warning(_("\"SELECT UNIX_TIMESTAMP()\" failed on master, "
854
"do not trust column Seconds_Behind_Master of SHOW "
855
"SLAVE STATUS. Error: %s (%d)"),
856
drizzle_error(drizzle), drizzle_errno(drizzle));
855
sql_print_warning("\"SELECT UNIX_TIMESTAMP()\" failed on master, "
856
"do not trust column Seconds_Behind_Master of SHOW "
857
"SLAVE STATUS. Error: %s (%d)",
858
mysql_error(mysql), mysql_errno(mysql));
859
drizzle_free_result(master_res);
861
mysql_free_result(master_res);
862
864
Check that the master's server id and ours are different. Because if they
868
870
Note: we could have put a @@SERVER_ID in the previous SELECT
869
871
UNIX_TIMESTAMP() instead, but this would not have worked on 3.23 masters.
871
if (!drizzle_real_query(drizzle,
873
if (!mysql_real_query(mysql,
872
874
STRING_WITH_LEN("SHOW VARIABLES LIKE 'SERVER_ID'")) &&
873
(master_res= drizzle_store_result(drizzle)))
875
(master_res= mysql_store_result(mysql)))
875
if ((master_row= drizzle_fetch_row(master_res)) &&
877
if ((master_row= mysql_fetch_row(master_res)) &&
876
878
(::server_id == strtoul(master_row[1], 0, 10)) &&
877
879
!mi->rli.replicate_same_server_id)
880
_("The slave I/O thread stops because master and slave have equal "
881
"DRIZZLE server ids; these ids must be different "
882
"for replication to work (or "
883
"the --replicate-same-server-id option must be used "
884
"on slave but this does"
885
"not always make sense; please check the manual before using it).");
882
"The slave I/O thread stops because master and slave have equal"
883
" MySQL server ids; these ids must be different for replication to work (or"
884
" the --replicate-same-server-id option must be used on slave but this does"
885
" not always make sense; please check the manual before using it).";
886
886
err_code= ER_SLAVE_FATAL_ERROR;
887
887
sprintf(err_buff, ER(err_code), errmsg);
888
888
err_msg.append(err_buff);
890
drizzle_free_result(master_res);
890
mysql_free_result(master_res);
912
912
/* redundant with rest of code but safer against later additions */
913
if (*drizzle->server_version == '3')
913
if (*mysql->server_version == '3')
916
if ((*drizzle->server_version == '4') &&
917
!drizzle_real_query(drizzle,
916
if ((*mysql->server_version == '4') &&
917
!mysql_real_query(mysql,
918
918
STRING_WITH_LEN("SELECT @@GLOBAL.COLLATION_SERVER")) &&
919
(master_res= drizzle_store_result(drizzle)))
919
(master_res= mysql_store_result(mysql)))
921
if ((master_row= drizzle_fetch_row(master_res)) &&
921
if ((master_row= mysql_fetch_row(master_res)) &&
922
922
strcmp(master_row[0], global_system_variables.collation_server->name))
925
_("The slave I/O thread stops because master and slave have"
926
" different values for the COLLATION_SERVER global variable."
927
" The values must be equal for replication to work");
925
"The slave I/O thread stops because master and slave have"
926
" different values for the COLLATION_SERVER global variable."
927
" The values must be equal for replication to work";
928
928
err_code= ER_SLAVE_FATAL_ERROR;
929
929
sprintf(err_buff, ER(err_code), errmsg);
930
930
err_msg.append(err_buff);
932
drizzle_free_result(master_res);
932
mysql_free_result(master_res);
949
949
This check is only necessary for 4.x masters (and < 5.0.4 masters but
950
950
those were alpha).
952
if ((*drizzle->server_version == '4') &&
953
!drizzle_real_query(drizzle, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) &&
954
(master_res= drizzle_store_result(drizzle)))
952
if ((*mysql->server_version == '4') &&
953
!mysql_real_query(mysql, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) &&
954
(master_res= mysql_store_result(mysql)))
956
if ((master_row= drizzle_fetch_row(master_res)) &&
956
if ((master_row= mysql_fetch_row(master_res)) &&
957
957
strcmp(master_row[0],
958
958
global_system_variables.time_zone->get_name()->ptr()))
961
_("The slave I/O thread stops because master and slave have"
962
" different values for the TIME_ZONE global variable."
963
" The values must be equal for replication to work");
961
"The slave I/O thread stops because master and slave have"
962
" different values for the TIME_ZONE global variable."
963
" The values must be equal for replication to work";
964
964
err_code= ER_SLAVE_FATAL_ERROR;
965
965
sprintf(err_buff, ER(err_code), errmsg);
966
966
err_msg.append(err_buff);
968
drizzle_free_result(master_res);
968
mysql_free_result(master_res);
980
980
the period is an uint64_t of nano-secs.
982
982
llstr((uint64_t) (mi->heartbeat_period*1000000000UL), llbuf);
983
sprintf(query, query_format, llbuf);
983
my_sprintf(query, (query, query_format, llbuf));
985
if (drizzle_real_query(drizzle, query, strlen(query))
985
if (mysql_real_query(mysql, query, strlen(query))
986
986
&& !check_io_slave_killed(mi->io_thd, mi, NULL))
988
988
err_msg.append("The slave I/O thread stops because querying master with '");
989
989
err_msg.append(query);
990
990
err_msg.append("' failed;");
991
991
err_msg.append(" error: ");
992
err_code= drizzle_errno(drizzle);
992
err_code= mysql_errno(mysql);
993
993
err_msg.qs_append(err_code);
994
994
err_msg.append(" '");
995
err_msg.append(drizzle_error(drizzle));
995
err_msg.append(mysql_error(mysql));
996
996
err_msg.append("'");
997
drizzle_free_result(drizzle_store_result(drizzle));
997
mysql_free_result(mysql_store_result(mysql));
1000
drizzle_free_result(drizzle_store_result(drizzle));
1000
mysql_free_result(mysql_store_result(mysql));
1023
1023
pthread_mutex_lock(&rli->log_space_lock);
1024
1024
save_proc_info= thd->enter_cond(&rli->log_space_cond,
1025
1025
&rli->log_space_lock,
1026
_("Waiting for the slave SQL thread "
1027
"to free enough relay log space"));
1027
Waiting for the slave SQL thread to free enough relay log space");
1028
1028
while (rli->log_space_limit < rli->log_space_total &&
1029
1029
!(slave_killed=io_slave_killed(thd,mi)) &&
1030
1030
!rli->ignore_log_space_limit)
1069
1069
if (unlikely(rli->relay_log.append(ev)))
1070
1070
mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
1071
1071
ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
1072
_("failed to write a Rotate event"
1073
" to the relay log, SHOW SLAVE STATUS may be"
1072
"failed to write a Rotate event"
1073
" to the relay log, SHOW SLAVE STATUS may be"
1075
1075
rli->relay_log.harvest_bytes_written(&rli->log_space_total);
1076
1076
if (flush_master_info(mi, 1))
1077
sql_print_error(_("Failed to flush master info file"));
1077
sql_print_error("Failed to flush master info file");
1081
1081
mi->report(ERROR_LEVEL, ER_SLAVE_CREATE_EVENT_FAILURE,
1082
1082
ER(ER_SLAVE_CREATE_EVENT_FAILURE),
1083
_("Rotate_event (out of memory?),"
1084
" SHOW SLAVE STATUS may be inaccurate"));
1083
"Rotate_event (out of memory?),"
1084
" SHOW SLAVE STATUS may be inaccurate");
1087
1087
pthread_mutex_unlock(log_lock);
1092
int32_t register_slave_on_master(DRIZZLE *drizzle, Master_info *mi,
1092
int32_t register_slave_on_master(MYSQL* mysql, Master_info *mi,
1093
1093
bool *suppress_warnings)
1095
unsigned char buf[1024], *pos= buf;
1095
uchar buf[1024], *pos= buf;
1096
1096
uint32_t report_host_len, report_user_len=0, report_password_len=0;
1098
1098
*suppress_warnings= false;
1109
1109
return(0); // safety
1111
1111
int4store(pos, server_id); pos+= 4;
1112
pos= net_store_data(pos, (unsigned char*) report_host, report_host_len);
1113
pos= net_store_data(pos, (unsigned char*) report_user, report_user_len);
1114
pos= net_store_data(pos, (unsigned char*) report_password, report_password_len);
1115
int2store(pos, (uint16_t) report_port); pos+= 2;
1112
pos= net_store_data(pos, (uchar*) report_host, report_host_len);
1113
pos= net_store_data(pos, (uchar*) report_user, report_user_len);
1114
pos= net_store_data(pos, (uchar*) report_password, report_password_len);
1115
int2store(pos, (uint16) report_port); pos+= 2;
1116
1116
int4store(pos, rpl_recovery_rank); pos+= 4;
1117
1117
/* The master will fill in master_id */
1118
1118
int4store(pos, 0); pos+= 4;
1120
if (simple_command(drizzle, COM_REGISTER_SLAVE, buf, (size_t) (pos- buf), 0))
1120
if (simple_command(mysql, COM_REGISTER_SLAVE, buf, (size_t) (pos- buf), 0))
1122
if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
1122
if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1124
1124
*suppress_warnings= true; // Suppress reconnect warning
1126
1126
else if (!check_io_slave_killed(mi->io_thd, mi, NULL))
1129
snprintf(buf, sizeof(buf), "%s (Errno: %d)", drizzle_error(drizzle),
1130
drizzle_errno(drizzle));
1129
snprintf(buf, sizeof(buf), "%s (Errno: %d)", mysql_error(mysql),
1130
mysql_errno(mysql));
1131
1131
mi->report(ERROR_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
1132
1132
ER(ER_SLAVE_MASTER_COM_FAILURE), "COM_REGISTER_SLAVE", buf);
1150
1150
field_list.push_back(new Item_empty_string("Master_User",
1151
1151
sizeof(mi->user)));
1152
1152
field_list.push_back(new Item_return_int("Master_Port", 7,
1153
DRIZZLE_TYPE_LONG));
1154
1154
field_list.push_back(new Item_return_int("Connect_Retry", 10,
1155
DRIZZLE_TYPE_LONG));
1156
1156
field_list.push_back(new Item_empty_string("Master_Log_File",
1158
1158
field_list.push_back(new Item_return_int("Read_Master_Log_Pos", 10,
1159
DRIZZLE_TYPE_LONGLONG));
1159
MYSQL_TYPE_LONGLONG));
1160
1160
field_list.push_back(new Item_empty_string("Relay_Log_File",
1162
1162
field_list.push_back(new Item_return_int("Relay_Log_Pos", 10,
1163
DRIZZLE_TYPE_LONGLONG));
1163
MYSQL_TYPE_LONGLONG));
1164
1164
field_list.push_back(new Item_empty_string("Relay_Master_Log_File",
1166
1166
field_list.push_back(new Item_empty_string("Slave_IO_Running", 3));
1172
1172
field_list.push_back(new Item_empty_string("Replicate_Wild_Do_Table", 24));
1173
1173
field_list.push_back(new Item_empty_string("Replicate_Wild_Ignore_Table",
1175
field_list.push_back(new Item_return_int("Last_Errno", 4, DRIZZLE_TYPE_LONG));
1175
field_list.push_back(new Item_return_int("Last_Errno", 4, MYSQL_TYPE_LONG));
1176
1176
field_list.push_back(new Item_empty_string("Last_Error", 20));
1177
1177
field_list.push_back(new Item_return_int("Skip_Counter", 10,
1178
DRIZZLE_TYPE_LONG));
1179
1179
field_list.push_back(new Item_return_int("Exec_Master_Log_Pos", 10,
1180
DRIZZLE_TYPE_LONGLONG));
1180
MYSQL_TYPE_LONGLONG));
1181
1181
field_list.push_back(new Item_return_int("Relay_Log_Space", 10,
1182
DRIZZLE_TYPE_LONGLONG));
1182
MYSQL_TYPE_LONGLONG));
1183
1183
field_list.push_back(new Item_empty_string("Until_Condition", 6));
1184
1184
field_list.push_back(new Item_empty_string("Until_Log_File", FN_REFLEN));
1185
1185
field_list.push_back(new Item_return_int("Until_Log_Pos", 10,
1186
DRIZZLE_TYPE_LONGLONG));
1186
MYSQL_TYPE_LONGLONG));
1187
1187
field_list.push_back(new Item_empty_string("Master_SSL_Allowed", 7));
1188
1188
field_list.push_back(new Item_empty_string("Master_SSL_CA_File",
1189
1189
sizeof(mi->ssl_ca)));
1196
1196
field_list.push_back(new Item_empty_string("Master_SSL_Key",
1197
1197
sizeof(mi->ssl_key)));
1198
1198
field_list.push_back(new Item_return_int("Seconds_Behind_Master", 10,
1199
DRIZZLE_TYPE_LONGLONG));
1199
MYSQL_TYPE_LONGLONG));
1200
1200
field_list.push_back(new Item_empty_string("Master_SSL_Verify_Server_Cert",
1202
field_list.push_back(new Item_return_int("Last_IO_Errno", 4, DRIZZLE_TYPE_LONG));
1202
field_list.push_back(new Item_return_int("Last_IO_Errno", 4, MYSQL_TYPE_LONG));
1203
1203
field_list.push_back(new Item_empty_string("Last_IO_Error", 20));
1204
field_list.push_back(new Item_return_int("Last_SQL_Errno", 4, DRIZZLE_TYPE_LONG));
1204
field_list.push_back(new Item_return_int("Last_SQL_Errno", 4, MYSQL_TYPE_LONG));
1205
1205
field_list.push_back(new Item_empty_string("Last_SQL_Error", 20));
1207
1207
if (protocol->send_fields(&field_list,
1218
1218
non-volotile members like mi->io_thd, which is guarded by the mutex.
1220
1220
pthread_mutex_lock(&mi->run_lock);
1221
protocol->store(mi->io_thd ? mi->io_thd->get_proc_info() : "", &my_charset_bin);
1221
protocol->store(mi->io_thd ? mi->io_thd->proc_info : "", &my_charset_bin);
1222
1222
pthread_mutex_unlock(&mi->run_lock);
1224
1224
pthread_mutex_lock(&mi->data_lock);
1225
1225
pthread_mutex_lock(&mi->rli.data_lock);
1226
1226
protocol->store(mi->host, &my_charset_bin);
1227
1227
protocol->store(mi->user, &my_charset_bin);
1228
protocol->store((uint32_t) mi->port);
1229
protocol->store((uint32_t) mi->connect_retry);
1228
protocol->store((uint32) mi->port);
1229
protocol->store((uint32) mi->connect_retry);
1230
1230
protocol->store(mi->master_log_name, &my_charset_bin);
1231
1231
protocol->store((uint64_t) mi->master_log_pos);
1232
1232
protocol->store(mi->rli.group_relay_log_name +
1295
1295
slave is 2. At SHOW SLAVE STATUS time, assume that the difference
1296
1296
between timestamp of slave and rli->last_master_timestamp is 0
1297
1297
(i.e. they are in the same second), then we get 0-(2-1)=-1 as a result.
1298
This confuses users, so we don't go below 0: hence the cmax().
1298
This confuses users, so we don't go below 0: hence the max().
1300
1300
last_master_timestamp == 0 (an "impossible" timestamp 1970) is a
1301
1301
special marker to say "consider we have caught up".
1303
1303
protocol->store((int64_t)(mi->rli.last_master_timestamp ?
1304
cmax((long)0, time_diff) : 0));
1304
max(0, time_diff) : 0));
1461
1461
int4store(buf + 6, server_id);
1462
1462
len = (uint32_t) strlen(logname);
1463
1463
memcpy(buf + 10, logname,len);
1464
if (simple_command(drizzle, COM_BINLOG_DUMP, buf, len + 10, 1))
1464
if (simple_command(mysql, COM_BINLOG_DUMP, buf, len + 10, 1))
1467
1467
Something went wrong, so we will just reconnect and retry later
1468
1468
in the future, we should do a better error analysis, but for
1469
1469
now we just fill up the error log :-)
1471
if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
1471
if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1472
1472
*suppress_warnings= true; // Suppress reconnect warning
1474
sql_print_error(_("Error on COM_BINLOG_DUMP: %d %s, will retry in %d secs"),
1475
drizzle_errno(drizzle), drizzle_error(drizzle),
1474
sql_print_error("Error on COM_BINLOG_DUMP: %d %s, will retry in %d secs",
1475
mysql_errno(mysql), mysql_error(mysql),
1476
1476
mi->connect_retry);
1524
1524
*suppress_warnings= true;
1527
sql_print_error(_("Error reading packet from server: %s ( server_errno=%d)"),
1528
drizzle_error(drizzle), drizzle_errno(drizzle));
1527
sql_print_error("Error reading packet from server: %s ( server_errno=%d)",
1528
mysql_error(mysql), mysql_errno(mysql));
1529
1529
return(packet_error);
1532
1532
/* Check if eof packet */
1533
if (len < 8 && drizzle->net.read_pos[0] == 254)
1533
if (len < 8 && mysql->net.read_pos[0] == 254)
1535
sql_print_information(_("Slave: received end packet from server, apparent "
1536
"master shutdown: %s"),
1537
drizzle_error(drizzle));
1535
sql_print_information("Slave: received end packet from server, apparent "
1536
"master shutdown: %s",
1537
mysql_error(mysql));
1538
1538
return(packet_error);
1688
1688
rli->report(ERROR_LEVEL, ER_UNKNOWN_ERROR,
1689
_("It was not possible to update the positions"
1689
"It was not possible to update the positions"
1690
1690
" of the relay log information: the slave may"
1691
1691
" be in an inconsistent state."
1692
" Stopped in %s position %s"),
1692
" Stopped in %s position %s",
1693
1693
rli->group_relay_log_name,
1694
1694
llstr(rli->group_relay_log_pos, buf));
1815
1814
if (rli->trans_retries < slave_trans_retries)
1817
1816
if (init_master_info(rli->mi, 0, 0, 0, SLAVE_SQL))
1818
sql_print_error(_("Failed to initialize the master info structure"));
1817
sql_print_error("Failed to initialize the master info structure");
1819
1818
else if (init_relay_log_pos(rli,
1820
1819
rli->group_relay_log_name,
1821
1820
rli->group_relay_log_pos,
1822
1821
1, &errmsg, 1))
1823
sql_print_error(_("Error initializing relay log position: %s"),
1822
sql_print_error("Error initializing relay log position: %s",
1828
1827
end_trans(thd, ROLLBACK);
1829
1828
/* chance for concurrent connection to get more locks */
1830
safe_sleep(thd, cmin(rli->trans_retries, (uint32_t)MAX_SLAVE_RETRY_PAUSE),
1829
safe_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
1831
1830
(CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);
1832
1831
pthread_mutex_lock(&rli->data_lock); // because of SHOW STATUS
1833
1832
rli->trans_retries++;
1839
sql_print_error(_("Slave SQL thread retried transaction %lu time(s) "
1840
"in vain, giving up. Consider raising the value of "
1841
"the slave_transaction_retries variable."),
1838
sql_print_error("Slave SQL thread retried transaction %lu time(s) "
1839
"in vain, giving up. Consider raising the value of "
1840
"the slave_transaction_retries variable.",
1842
1841
slave_trans_retries);
1844
1843
else if ((exec_res && !temp_err) ||
1859
1858
pthread_mutex_unlock(&rli->data_lock);
1860
1859
rli->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_READ_FAILURE,
1861
ER(ER_SLAVE_RELAY_LOG_READ_FAILURE),
1862
_("Could not parse relay log event entry. The possible reasons "
1863
"are: the master's binary log is corrupted (you can check this "
1864
"by running 'mysqlbinlog' on the binary log), the slave's "
1865
"relay log is corrupted (you can check this by running "
1866
"'mysqlbinlog' on the relay log), a network problem, or a bug "
1867
"in the master's or slave's DRIZZLE code. If you want to check "
1868
"the master's binary log or slave's relay log, you will be "
1869
"able to know their names by issuing 'SHOW SLAVE STATUS' "
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' \
1898
1896
@retval 1 There was an error.
1901
static int32_t try_to_reconnect(THD *thd, DRIZZLE *drizzle, Master_info *mi,
1902
uint32_t *retry_count, bool suppress_warnings,
1903
const char *messages[SLAVE_RECON_MSG_MAX])
1899
static int32_t try_to_reconnect(THD *thd, MYSQL *mysql, Master_info *mi,
1900
uint32_t *retry_count, bool suppress_warnings,
1901
const char *messages[SLAVE_RECON_MSG_MAX])
1905
mi->slave_running= DRIZZLE_SLAVE_RUN_NOT_CONNECT;
1906
thd->set_proc_info(_(messages[SLAVE_RECON_MSG_WAIT]));
1907
drizzle_disconnect(drizzle);
1903
mi->slave_running= MYSQL_SLAVE_RUN_NOT_CONNECT;
1904
thd->proc_info= messages[SLAVE_RECON_MSG_WAIT];
1905
#ifdef SIGNAL_WITH_VIO_CLOSE
1906
thd->clear_active_vio();
1908
1909
if ((*retry_count)++)
1910
1911
if (*retry_count > master_retry_count)
1912
1913
safe_sleep(thd, mi->connect_retry, (CHECK_KILLED_FUNC) io_slave_killed,
1915
if (check_io_slave_killed(thd, mi,
1916
_(messages[SLAVE_RECON_MSG_KILLED_WAITING])))
1916
if (check_io_slave_killed(thd, mi, messages[SLAVE_RECON_MSG_KILLED_WAITING]))
1918
thd->set_proc_info(_(messages[SLAVE_RECON_MSG_AFTER]));
1919
if (!suppress_warnings)
1918
thd->proc_info = messages[SLAVE_RECON_MSG_AFTER];
1919
if (!suppress_warnings)
1921
1921
char buf[256], llbuff[22];
1922
snprintf(buf, sizeof(buf), _(messages[SLAVE_RECON_MSG_FAILED]),
1922
snprintf(buf, sizeof(buf), messages[SLAVE_RECON_MSG_FAILED],
1923
1923
IO_RPL_LOG_NAME, llstr(mi->master_log_pos, llbuff));
1925
1925
Raise a warining during registering on master/requesting dump.
1926
1926
Log a message reading event.
1928
if (_(messages[SLAVE_RECON_MSG_COMMAND])[0])
1928
if (messages[SLAVE_RECON_MSG_COMMAND][0])
1930
1930
mi->report(WARNING_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
1931
ER(ER_SLAVE_MASTER_COM_FAILURE),
1932
_(messages[SLAVE_RECON_MSG_COMMAND]), buf);
1931
ER(ER_SLAVE_MASTER_COM_FAILURE),
1932
messages[SLAVE_RECON_MSG_COMMAND], buf);
1936
1936
sql_print_information(buf);
1939
if (safe_reconnect(thd, drizzle, mi, 1) || io_slave_killed(thd, mi))
1939
if (safe_reconnect(thd, mysql, mi, 1) || io_slave_killed(thd, mi))
1941
1941
if (global_system_variables.log_warnings)
1942
sql_print_information(_(messages[SLAVE_RECON_MSG_KILLED_AFTER]));
1942
sql_print_information(messages[SLAVE_RECON_MSG_KILLED_AFTER]);
1991
1991
pthread_mutex_unlock(&mi->run_lock);
1992
1992
pthread_cond_broadcast(&mi->start_cond);
1994
if (!(mi->drizzle= drizzle = drizzle_create(NULL)))
1994
if (!(mi->mysql = mysql = mysql_init(NULL)))
1996
1996
mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
1997
ER(ER_SLAVE_FATAL_ERROR), _("error in drizzle_create()"));
1997
ER(ER_SLAVE_FATAL_ERROR), "error in mysql_init()");
2001
2001
thd_proc_info(thd, "Connecting to master");
2002
2002
// we can get killed during safe_connect
2003
if (!safe_connect(thd, drizzle, mi))
2003
if (!safe_connect(thd, mysql, mi))
2005
sql_print_information(_("Slave I/O thread: connected to master '%s@%s:%d',"
2006
"replication started in log '%s' at position %s"),
2005
sql_print_information("Slave I/O thread: connected to master '%s@%s:%d',"
2006
"replication started in log '%s' at position %s",
2007
2007
mi->user, mi->host, mi->port,
2008
2008
IO_RPL_LOG_NAME,
2009
2009
llstr(mi->master_log_pos,llbuff));
2012
2012
thread, since a replication event can become this much larger than
2013
2013
the corresponding packet (query) sent from client to master.
2015
drizzle->net.max_packet_size= thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER;
2015
mysql->net.max_packet_size= thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER;
2019
sql_print_information(_("Slave I/O thread killed while connecting to master"));
2019
sql_print_information("Slave I/O thread killed while connecting to master");
2025
2025
// TODO: the assignment below should be under mutex (5.0)
2026
mi->slave_running= DRIZZLE_SLAVE_RUN_CONNECT;
2027
thd->slave_net = &drizzle->net;
2026
mi->slave_running= MYSQL_SLAVE_RUN_CONNECT;
2027
thd->slave_net = &mysql->net;
2028
2028
thd_proc_info(thd, "Checking master version");
2029
if (get_master_version_and_clock(drizzle, mi))
2029
if (get_master_version_and_clock(mysql, mi))
2032
2032
if (mi->rli.relay_log.description_event_for_queue->binlog_version > 1)
2035
2035
Register ourselves with the master.
2037
2037
thd_proc_info(thd, "Registering slave on master");
2038
if (register_slave_on_master(drizzle, mi, &suppress_warnings))
2038
if (register_slave_on_master(mysql, mi, &suppress_warnings))
2040
2040
if (!check_io_slave_killed(thd, mi, "Slave I/O thread killed "
2041
"while registering slave on master"))
2041
"while registering slave on master"))
2043
sql_print_error(_("Slave I/O thread couldn't register on master"));
2044
if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2043
sql_print_error("Slave I/O thread couldn't register on master");
2044
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2045
2045
reconnect_messages[SLAVE_RECON_ACT_REG]))
2052
2052
if (!retry_count_reg)
2054
2054
retry_count_reg++;
2055
sql_print_information(_("Forcing to reconnect slave I/O thread"));
2056
if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2057
reconnect_messages[SLAVE_RECON_ACT_REG]))
2055
sql_print_information("Forcing to reconnect slave I/O thread");
2056
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2057
reconnect_messages[SLAVE_RECON_ACT_REG]))
2059
2059
goto connected;
2063
2063
while (!io_slave_killed(thd,mi))
2065
2065
thd_proc_info(thd, "Requesting binlog dump");
2066
if (request_dump(drizzle, mi, &suppress_warnings))
2066
if (request_dump(mysql, mi, &suppress_warnings))
2068
sql_print_error(_("Failed on request_dump()"));
2069
if (check_io_slave_killed(thd, mi, _("Slave I/O thread killed while \
2070
requesting master dump")) ||
2071
try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2068
sql_print_error("Failed on request_dump()");
2069
if (check_io_slave_killed(thd, mi, "Slave I/O thread killed while \
2070
requesting master dump") ||
2071
try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2072
2072
reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2074
2074
goto connected;
2076
2076
if (!retry_count_dump)
2078
2078
retry_count_dump++;
2079
sql_print_information(_("Forcing to reconnect slave I/O thread"));
2080
if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2079
sql_print_information("Forcing to reconnect slave I/O thread");
2080
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2081
2081
reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2083
2083
goto connected;
2088
2088
uint32_t event_len;
2090
We say "waiting" because read_event() will wait if there's nothing to
2091
read. But if there's something to read, it will not wait. The
2092
important thing is to not confuse users by saying "reading" whereas
2093
we're in fact receiving nothing.
2090
We say "waiting" because read_event() will wait if there's nothing to
2091
read. But if there's something to read, it will not wait. The
2092
important thing is to not confuse users by saying "reading" whereas
2093
we're in fact receiving nothing.
2095
thd_proc_info(thd, _("Waiting for master to send event"));
2096
event_len= read_event(drizzle, mi, &suppress_warnings);
2097
if (check_io_slave_killed(thd, mi, _("Slave I/O thread killed while "
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 \
2100
2100
if (!retry_count_event)
2102
2102
retry_count_event++;
2103
sql_print_information(_("Forcing to reconnect slave I/O thread"));
2104
if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2103
sql_print_information("Forcing to reconnect slave I/O thread");
2104
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2105
2105
reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2107
2107
goto connected;
2110
2110
if (event_len == packet_error)
2112
uint32_t drizzle_error_number= drizzle_errno(drizzle);
2113
switch (drizzle_error_number) {
2112
uint32_t mysql_error_number= mysql_errno(mysql);
2113
switch (mysql_error_number) {
2114
2114
case CR_NET_PACKET_TOO_LARGE:
2115
sql_print_error(_("Log entry on master is longer than "
2116
"max_allowed_packet (%ld) on "
2117
"slave. If the entry is correct, restart the "
2118
"server with a higher value of "
2119
"max_allowed_packet"),
2116
Log entry on master is longer than max_allowed_packet (%ld) on \
2117
slave. If the entry is correct, restart the server with a higher value of \
2118
max_allowed_packet",
2120
2119
thd->variables.max_allowed_packet);
2122
2121
case ER_MASTER_FATAL_ERROR_READING_BINLOG:
2123
sql_print_error(ER(drizzle_error_number), drizzle_error_number,
2124
drizzle_error(drizzle));
2122
sql_print_error(ER(mysql_error_number), mysql_error_number,
2123
mysql_error(mysql));
2126
2125
case EE_OUTOFMEMORY:
2127
2126
case ER_OUTOFMEMORY:
2129
_("Stopping slave I/O thread due to out-of-memory error from master"));
2128
Stopping slave I/O thread due to out-of-memory error from master");
2132
if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2131
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2133
2132
reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2135
2134
goto connected;
2136
2135
} // if (event_len == packet_error)
2138
2137
retry_count=0; // ok event, reset retry counter
2139
thd_proc_info(thd, _("Queueing master event to the relay log"));
2140
if (queue_event(mi,(const char*)drizzle->net.read_pos + 1, event_len))
2138
thd_proc_info(thd, "Queueing master event to the relay log");
2139
if (queue_event(mi,(const char*)mysql->net.read_pos + 1, event_len))
2144
2143
if (flush_master_info(mi, 1))
2146
sql_print_error(_("Failed to flush master info file"));
2145
sql_print_error("Failed to flush master info file");
2163
2162
!rli->ignore_log_space_limit)
2164
2163
if (wait_for_relay_log_space(rli))
2166
sql_print_error(_("Slave I/O thread aborted while waiting for "
2167
"relay log space"));
2165
sql_print_error("Slave I/O thread aborted while waiting for relay \
2175
// print the current replication position
2176
sql_print_information(_("Slave I/O thread exiting, read up to log '%s', "
2178
IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
2179
pthread_mutex_lock(&LOCK_thread_count);
2174
// print the current replication position
2175
sql_print_information("Slave I/O thread exiting, read up to log '%s', position %s",
2176
IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
2177
VOID(pthread_mutex_lock(&LOCK_thread_count));
2180
2178
thd->query = thd->db = 0; // extra safety
2181
2179
thd->query_length= thd->db_length= 0;
2182
pthread_mutex_unlock(&LOCK_thread_count);
2180
VOID(pthread_mutex_unlock(&LOCK_thread_count));
2186
2184
Here we need to clear the active VIO before closing the
2190
2188
can be called in the middle of closing the VIO associated with
2191
2189
the 'mysql' object, causing a crash.
2193
drizzle_close(drizzle);
2191
#ifdef SIGNAL_WITH_VIO_CLOSE
2192
thd->clear_active_vio();
2196
2197
write_ignored_events_info_to_relay_log(thd, mi);
2197
thd_proc_info(thd, _("Waiting for slave mutex on exit"));
2198
thd_proc_info(thd, "Waiting for slave mutex on exit");
2198
2199
pthread_mutex_lock(&mi->run_lock);
2200
2201
/* Forget the relay log's format */
2326
2327
assert(rli->sql_thd == thd);
2328
2329
if (global_system_variables.log_warnings)
2329
sql_print_information(_("Slave SQL thread initialized, "
2330
"starting replication in log '%s' at "
2331
"position %s, relay log '%s' position: %s"),
2333
llstr(rli->group_master_log_pos,llbuff),
2334
rli->group_relay_log_name,
2335
llstr(rli->group_relay_log_pos,llbuff1));
2330
sql_print_information("Slave SQL thread initialized, starting replication in \
2331
log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME,
2332
llstr(rli->group_master_log_pos,llbuff),rli->group_relay_log_name,
2333
llstr(rli->group_relay_log_pos,llbuff1));
2337
2335
/* execute init_slave variable */
2338
2336
if (sys_init_slave.value_length)
2392
2390
else if (last_errno != thd->main_da.sql_errno())
2394
sql_print_error(_("Slave (additional info): %s Error_code: %d"),
2392
sql_print_error("Slave (additional info): %s Error_code: %d",
2395
2393
errmsg, thd->main_da.sql_errno());
2399
2397
/* Print any warnings issued */
2400
List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
2398
List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
2403
2401
Added controlled slave thread cancel for replication
2404
2402
of user-defined variables.
2409
2407
if (err->code == ER_CANT_OPEN_LIBRARY)
2410
2408
udf_error = true;
2411
sql_print_warning(_("Slave: %s Error_code: %d"),err->msg, err->code);
2409
sql_print_warning("Slave: %s Error_code: %d",err->msg, err->code);
2414
sql_print_error(_("Error loading user-defined library, slave SQL "
2415
"thread aborted. Install the missing library, "
2416
"and restart the slave SQL thread with "
2417
"\"SLAVE START\". We stopped at log '%s' "
2419
RPL_LOG_NAME, llstr(rli->group_master_log_pos,
2412
sql_print_error("Error loading user-defined library, slave SQL "
2413
"thread aborted. Install the missing library, and restart the "
2414
"slave SQL thread with \"SLAVE START\". We stopped at log '%s' "
2415
"position %s", RPL_LOG_NAME, llstr(rli->group_master_log_pos,
2422
sql_print_error(_("Error running query, slave SQL thread aborted. "
2423
"Fix the problem, and restart "
2424
"the slave SQL thread with \"SLAVE START\". "
2425
"We stopped at log '%s' position %s"),
2427
llstr(rli->group_master_log_pos, llbuff));
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));
2433
2427
/* Thread stopped. Print the current replication position to the log */
2434
sql_print_information(_("Slave SQL thread exiting, replication stopped in "
2435
"log '%s' at position %s"),
2437
llstr(rli->group_master_log_pos,llbuff));
2428
sql_print_information("Slave SQL thread exiting, replication stopped in log "
2429
"'%s' at position %s",
2430
RPL_LOG_NAME, llstr(rli->group_master_log_pos,llbuff));
2545
2538
if (unlikely((num_bytes=my_net_read(net)) == packet_error))
2547
sql_print_error(_("Network read error downloading '%s' from master"),
2540
sql_print_error("Network read error downloading '%s' from master",
2551
2544
if (unlikely(!num_bytes)) /* eof */
2553
2546
/* 3.23 master wants it */
2554
net_write_command(net, 0, (unsigned char*) "", 0, (unsigned char*) "", 0);
2547
net_write_command(net, 0, (uchar*) "", 0, (uchar*) "", 0);
2556
2549
If we wrote Create_file_log_event, then we need to write
2557
2550
Execute_load_log_event. If we did not write Create_file_log_event,
2802
2794
mi->rli.relay_log.description_event_for_queue);
2803
2795
if (unlikely(!ev))
2805
sql_print_error(_("Read invalid event from master: '%s', "
2806
"master could be corrupt but a more likely cause of "
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",
2809
free((char*) tmp_buf);
2800
my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
2812
2803
pthread_mutex_lock(&mi->data_lock);
3126
static int32_t safe_connect(THD* thd, DRIZZLE *drizzle, Master_info* mi)
3117
static int32_t safe_connect(THD* thd, MYSQL* mysql, Master_info* mi)
3128
return(connect_to_master(thd, drizzle, mi, 0, 0));
3119
return(connect_to_master(thd, mysql, mi, 0, 0));
3138
3129
master_retry_count times
3141
static int32_t connect_to_master(THD* thd, DRIZZLE *drizzle, Master_info* mi,
3142
bool reconnect, bool suppress_warnings)
3132
static int32_t connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
3133
bool reconnect, bool suppress_warnings)
3144
3135
int32_t slave_was_killed;
3145
3136
int32_t last_errno= -2; // impossible error
3151
3142
if (opt_slave_compressed_protocol)
3152
3143
client_flag=CLIENT_COMPRESS; /* We will use compression */
3154
drizzle_options(drizzle, DRIZZLE_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
3155
drizzle_options(drizzle, DRIZZLE_OPT_READ_TIMEOUT, (char *) &slave_net_timeout);
3145
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
3146
mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout);
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);
3157
3152
while (!(slave_was_killed = io_slave_killed(thd,mi)) &&
3158
(reconnect ? drizzle_reconnect(drizzle) != 0 :
3159
drizzle_connect(drizzle, mi->host, mi->user, mi->password, 0,
3153
(reconnect ? mysql_reconnect(mysql) != 0 :
3154
mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
3160
3155
mi->port, 0, client_flag) == 0))
3162
3157
/* Don't repeat last error */
3163
if ((int32_t)drizzle_errno(drizzle) != last_errno)
3158
if ((int32_t)mysql_errno(mysql) != last_errno)
3165
last_errno=drizzle_errno(drizzle);
3160
last_errno=mysql_errno(mysql);
3166
3161
suppress_warnings= 0;
3167
3162
mi->report(ERROR_LEVEL, last_errno,
3168
_("error %s to master '%s@%s:%d'"
3169
" - retry-time: %d retries: %u"),
3170
(reconnect ? _("reconnecting") : _("connecting")),
3163
"error %s to master '%s@%s:%d'"
3164
" - retry-time: %d retries: %u",
3165
(reconnect ? "reconnecting" : "connecting"),
3171
3166
mi->user, mi->host, mi->port,
3172
3167
mi->connect_retry, master_retry_count);
3195
3190
if (!suppress_warnings && global_system_variables.log_warnings)
3196
sql_print_information(_("Slave: connected to master '%s@%s:%d', "
3197
"replication resumed in log '%s' at "
3198
"position %s"), mi->user,
3201
llstr(mi->master_log_pos,llbuff));
3191
sql_print_information("Slave: connected to master '%s@%s:%d',\
3192
replication resumed in log '%s' at position %s", mi->user,
3195
llstr(mi->master_log_pos,llbuff));
3205
3199
change_rpl_status(RPL_IDLE_SLAVE,RPL_ACTIVE_SLAVE);
3200
general_log_print(thd, COM_CONNECT_OUT, "%s@%s:%d",
3201
mi->user, mi->host, mi->port);
3203
#ifdef SIGNAL_WITH_VIO_CLOSE
3204
thd->set_active_vio(mysql->net.vio);
3208
drizzle->reconnect= 1;
3207
mysql->reconnect= 1;
3209
3208
return(slave_was_killed);
3218
3217
master_retry_count times
3221
static int32_t safe_reconnect(THD* thd, DRIZZLE *drizzle, Master_info* mi,
3220
static int32_t safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
3222
3221
bool suppress_warnings)
3224
return(connect_to_master(thd, drizzle, mi, 1, suppress_warnings));
3223
return(connect_to_master(thd, mysql, mi, 1, suppress_warnings));
3265
3264
char buff[FN_REFLEN*2+22*2+4], *pos;
3267
3266
my_b_seek(file, 0L);
3268
pos=my_stpcpy(buff, rli->group_relay_log_name);
3267
pos=strmov(buff, rli->group_relay_log_name);
3270
3269
pos=int64_t2str(rli->group_relay_log_pos, pos, 10);
3272
pos=my_stpcpy(pos, rli->group_master_log_name);
3271
pos=strmov(pos, rli->group_master_log_name);
3274
3273
pos=int64_t2str(rli->group_master_log_pos, pos, 10);
3276
if (my_b_write(file, (unsigned char*) buff, (size_t) (pos-buff)+1))
3275
if (my_b_write(file, (uchar*) buff, (size_t) (pos-buff)+1))
3278
3277
if (flush_io_cache(file))
3382
3381
When the relay log is created when the I/O thread starts, easy: the
3383
3382
master will send the description event and we will queue it.
3384
3383
But if the relay log is created by new_file(): then the solution is:
3385
DRIZZLE_BIN_LOG::open() will write the buffered description event.
3384
MYSQL_BIN_LOG::open() will write the buffered description event.
3387
3386
if ((ev=Log_event::read_log_event(cur_log,0,
3388
3387
rli->relay_log.description_event_for_exec)))
3626
3625
pthread_mutex_unlock(log_lock);
3627
sql_print_error(_("Slave SQL thread: I/O error reading "
3628
"event(errno: %d cur_log->error: %d)"),
3626
sql_print_error("Slave SQL thread: I/O error reading \
3627
event(errno: %d cur_log->error: %d)",
3629
3628
my_errno,cur_log->error);
3630
3629
// set read position to the beginning of the event
3631
3630
my_b_seek(cur_log,rli->event_relay_log_pos);
3632
3631
/* otherwise, we have had a partial read */
3633
errmsg = _("Aborting slave SQL thread because of partial event read");
3632
errmsg = "Aborting slave SQL thread because of partial event read";
3634
3633
break; // To end of function
3637
3636
if (!errmsg && global_system_variables.log_warnings)
3639
sql_print_information(_("Error reading relay log event: %s"),
3640
_("slave SQL thread was killed"));
3638
sql_print_information("Error reading relay log event: %s",
3639
"slave SQL thread was killed");
3646
sql_print_error(_("Error reading relay log event: %s"), errmsg);
3645
sql_print_error("Error reading relay log event: %s", errmsg);
3716
3715
{33029, { 5, 0, 0 }, { 5, 0, 58 } },
3717
3716
{33029, { 5, 1, 0 }, { 5, 1, 12 } },
3719
const unsigned char *master_ver=
3718
const uchar *master_ver=
3720
3719
rli->relay_log.description_event_for_exec->server_version_split;
3722
3721
assert(sizeof(rli->relay_log.description_event_for_exec->server_version_split) == 3);
3724
3723
for (uint32_t i= 0;
3725
3724
i < sizeof(versions_for_all_bugs)/sizeof(*versions_for_all_bugs);i++)
3727
const unsigned char *introduced_in= versions_for_all_bugs[i].introduced_in,
3726
const uchar *introduced_in= versions_for_all_bugs[i].introduced_in,
3728
3727
*fixed_in= versions_for_all_bugs[i].fixed_in;
3729
3728
if ((versions_for_all_bugs[i].bug_id == bug_id) &&
3730
3729
(memcmp(introduced_in, master_ver, 3) <= 0) &&
3731
3730
(memcmp(fixed_in, master_ver, 3) > 0))
3736
3735
// a short message for SHOW SLAVE STATUS (message length constraints)
3737
my_printf_error(ER_UNKNOWN_ERROR,
3738
_("master may suffer from"
3739
" http://bugs.mysql.com/bug.php?id=%u"
3740
" so slave stops; check error log on slave"
3741
" for more info"), MYF(0), bug_id);
3736
my_printf_error(ER_UNKNOWN_ERROR, "master may suffer from"
3737
" http://bugs.mysql.com/bug.php?id=%u"
3738
" so slave stops; check error log on slave"
3739
" for more info", MYF(0), bug_id);
3742
3740
// a verbose message for the error log
3743
3741
rli->report(ERROR_LEVEL, ER_UNKNOWN_ERROR,
3744
_("According to the master's version ('%s'),"
3745
" it is probable that master suffers from this bug:"
3746
" http://bugs.mysql.com/bug.php?id=%u"
3747
" and thus replicating the current binary log event"
3748
" may make the slave's data become different from the"
3750
" To take no risk, slave refuses to replicate"
3751
" this event and stops."
3752
" We recommend that all updates be stopped on the"
3753
" master and slave, that the data of both be"
3754
" manually synchronized,"
3755
" that master's binary logs be deleted,"
3756
" that master be upgraded to a version at least"
3757
" equal to '%d.%d.%d'. Then replication can be"
3759
rli->relay_log.description_event_for_exec->server_version,
3761
fixed_in[0], fixed_in[1], fixed_in[2]);
3742
"According to the master's version ('%s'),"
3743
" it is probable that master suffers from this bug:"
3744
" http://bugs.mysql.com/bug.php?id=%u"
3745
" and thus replicating the current binary log event"
3746
" may make the slave's data become different from the"
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"
3757
rli->relay_log.description_event_for_exec->server_version,
3759
fixed_in[0], fixed_in[1], fixed_in[2]);