95
88
static const char *reconnect_messages[SLAVE_RECON_ACT_MAX][SLAVE_RECON_MSG_MAX]=
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"
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"
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",
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 \
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,
621
613
if (difftime(time(0), rli->last_event_start_time) > 60)
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.");
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
653
645
bool net_request_file(NET* net, const char* fname)
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),
780
772
delete mi->rli.relay_log.description_event_for_queue;
781
773
mi->rli.relay_log.description_event_for_queue= 0;
783
if (!my_isdigit(&my_charset_bin,*drizzle->server_version))
775
if (!my_isdigit(&my_charset_bin,*mysql->server_version))
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);
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 ;)
795
switch (*drizzle->server_version)
787
switch (*mysql->server_version)
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);
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);
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);
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
850
842
unavailable (very old master not supporting UNIX_TIMESTAMP()?).
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)))
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))
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));
869
drizzle_free_result(master_res);
861
mysql_free_result(master_res);
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.
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)))
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)
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);
900
drizzle_free_result(master_res);
890
mysql_free_result(master_res);
922
912
/* redundant with rest of code but safer against later additions */
923
if (*drizzle->server_version == '3')
913
if (*mysql->server_version == '3')
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)))
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))
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);
942
drizzle_free_result(master_res);
932
mysql_free_result(master_res);
959
949
This check is only necessary for 4.x masters (and < 5.0.4 masters but
960
950
those were alpha).
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)))
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()))
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);
978
drizzle_free_result(master_res);
968
mysql_free_result(master_res);
990
980
the period is an uint64_t of nano-secs.
992
982
llstr((uint64_t) (mi->heartbeat_period*1000000000UL), llbuf);
993
sprintf(query, query_format, llbuf);
983
my_sprintf(query, (query, query_format, llbuf));
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))
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));
1010
drizzle_free_result(drizzle_store_result(drizzle));
1000
mysql_free_result(mysql_store_result(mysql));
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"
1072
"failed to write a Rotate event"
1073
" to the relay log, SHOW SLAVE STATUS may be"
1085
1075
rli->relay_log.harvest_bytes_written(&rli->log_space_total);
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");
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");
1097
1087
pthread_mutex_unlock(log_lock);
1119
1109
return(0); // safety
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;
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))
1132
if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
1122
if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1134
1124
*suppress_warnings= true; // Suppress reconnect warning
1136
1126
else if (!check_io_slave_killed(mi->io_thd, mi, NULL))
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);
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));
1164
1154
field_list.push_back(new Item_return_int("Connect_Retry", 10,
1165
DRIZZLE_TYPE_LONG));
1166
1156
field_list.push_back(new Item_empty_string("Master_Log_File",
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",
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",
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",
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));
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",
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));
1204
1207
if (protocol->send_fields(&field_list,
1215
1218
non-volotile members like mi->io_thd, which is guarded by the mutex.
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);
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());
1261
1264
protocol->store(mi->rli.until_log_name, &my_charset_bin);
1262
1265
protocol->store((uint64_t) mi->rli.until_log_pos);
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);
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).
1268
if ((mi->slave_running == DRIZZLE_SLAVE_RUN_CONNECT) &&
1278
if ((mi->slave_running == MYSQL_SLAVE_RUN_CONNECT) &&
1269
1279
mi->rli.slave_running)
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().
1290
1300
last_master_timestamp == 0 (an "impossible" timestamp 1970) is a
1291
1301
special marker to say "consider we have caught up".
1293
1303
protocol->store((int64_t)(mi->rli.last_master_timestamp ?
1294
cmax((long)0, time_diff) : 0));
1304
max(0, time_diff) : 0));
1298
1308
protocol->store_null();
1310
protocol->store(mi->ssl_verify_server_cert? "Yes":"No", &my_charset_bin);
1301
1312
// Last_IO_Errno
1302
1313
protocol->store(mi->last_error().number);
1353
void set_slave_thread_default_charset(THD* thd, Relay_log_info const *rli)
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();
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
1369
const_cast<Relay_log_info*>(rli)->cached_charset_invalidate();
1343
1374
init_slave_thread()
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)
1419
unsigned char buf[FN_REFLEN + 10];
1451
uchar buf[FN_REFLEN + 10];
1421
1453
int32_t binlog_flags = 0; // for now
1422
const char* logname = mi->getLogName();
1454
char* logname = mi->master_log_name;
1424
1456
*suppress_warnings= false;
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))
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 :-)
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
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);
1492
1524
*suppress_warnings= true;
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);
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)
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);
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));
1783
1814
if (rli->trans_retries < slave_trans_retries)
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",
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++;
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' "
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' \
1866
1896
@retval 1 There was an error.
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])
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();
1876
1909
if ((*retry_count)++)
1878
1911
if (*retry_count > master_retry_count)
1880
1913
safe_sleep(thd, mi->connect_retry, (CHECK_KILLED_FUNC) io_slave_killed,
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]))
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)
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));
1922
snprintf(buf, sizeof(buf), messages[SLAVE_RECON_MSG_FAILED],
1923
IO_RPL_LOG_NAME, llstr(mi->master_log_pos, llbuff));
1893
1925
Raise a warining during registering on master/requesting dump.
1894
1926
Log a message reading event.
1896
if (_(messages[SLAVE_RECON_MSG_COMMAND])[0])
1928
if (messages[SLAVE_RECON_MSG_COMMAND][0])
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);
1904
1936
sql_print_information(buf);
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))
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]);
1959
1991
pthread_mutex_unlock(&mi->run_lock);
1960
1992
pthread_cond_broadcast(&mi->start_cond);
1962
if (!(mi->drizzle= drizzle = drizzle_create(NULL)))
1994
if (!(mi->mysql = mysql = mysql_init(NULL)))
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()");
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))
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));
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.
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;
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");
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))
2000
2032
if (mi->rli.relay_log.description_event_for_queue->binlog_version > 1)
2003
2035
Register ourselves with the master.
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))
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"))
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]))
2031
2063
while (!io_slave_killed(thd,mi))
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))
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]))
2042
2074
goto connected;
2056
2088
uint32_t event_len;
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.
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 "
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 \
2068
2100
if (!retry_count_event)
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]))
2075
2107
goto connected;
2078
2110
if (event_len == packet_error)
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"),
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);
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));
2094
2125
case EE_OUTOFMEMORY:
2095
2126
case ER_OUTOFMEMORY:
2097
_("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");
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]))
2103
2134
goto connected;
2104
2135
} // if (event_len == packet_error)
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))
2143
if (flush_master_info(mi, 1))
2114
sql_print_error(_("Failed to flush master info file"));
2145
sql_print_error("Failed to flush master info file");
2131
2162
!rli->ignore_log_space_limit)
2132
2163
if (wait_for_relay_log_space(rli))
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 \
2143
// print the current replication position
2144
sql_print_information(_("Slave I/O thread exiting, read up to log '%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);
2180
VOID(pthread_mutex_unlock(&LOCK_thread_count));
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.
2161
drizzle_close(drizzle);
2191
#ifdef SIGNAL_WITH_VIO_CLOSE
2192
thd->clear_active_vio();
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);
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);
2265
2300
rli->trans_retries= 0; // start from "no error"
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*/))
2273
sql_print_error(_("Error initializing relay log position: %s"),
2308
sql_print_error("Error initializing relay log position: %s",
2292
2327
assert(rli->sql_thd == thd);
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"),
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));
2303
2335
/* execute init_slave variable */
2304
2336
if (sys_init_slave.value_length)
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);
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' "
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,
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"),
2393
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));
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"),
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));
2509
2538
if (unlikely((num_bytes=my_net_read(net)) == packet_error))
2511
sql_print_error(_("Network read error downloading '%s' from master"),
2540
sql_print_error("Network read error downloading '%s' from master",
2515
2544
if (unlikely(!num_bytes)) /* eof */
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);
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,
2680
2709
mi->rli.relay_log.description_event_for_queue);
2681
2710
if (unlikely(!ev))
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",
2687
free((char*) tmp_buf);
2715
my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
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;
3008
3036
buf[EVENT_TYPE_OFFSET]!=ROTATE_EVENT &&
3009
3037
buf[EVENT_TYPE_OFFSET]!=STOP_EVENT)
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;
3016
3044
rli->relay_log.signal_update(); // the slave SQL thread needs to re-check
3114
3142
if (opt_slave_compressed_protocol)
3115
3143
client_flag=CLIENT_COMPRESS; /* We will use compression */
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);
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);
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))
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)
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);
3138
3170
By default we try forever. The reason is that failure will trigger
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(),
3162
llstr(mi->getLogPosition(),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));
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);
3165
drizzle->reconnect= 1;
3207
mysql->reconnect= 1;
3166
3208
return(slave_was_killed);
3214
3256
bool flush_relay_log_info(Relay_log_info* rli)
3218
3260
if (unlikely(rli->no_storage))
3263
IO_CACHE *file = &rli->info_file;
3264
char buff[FN_REFLEN*2+22*2+4], *pos;
3266
my_b_seek(file, 0L);
3267
pos=strmov(buff, rli->group_relay_log_name);
3269
pos=int64_t2str(rli->group_relay_log_pos, pos, 10);
3271
pos=strmov(pos, rli->group_master_log_name);
3273
pos=int64_t2str(rli->group_master_log_pos, pos, 10);
3275
if (my_b_write(file, (uchar*) buff, (size_t) (pos-buff)+1))
3277
if (flush_io_cache(file))
3280
/* Flushing the relay log is done by the slave I/O thread */
3232
3292
assert(rli->cur_log_fd == -1);
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,
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
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);
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
3574
3636
if (!errmsg && global_system_variables.log_warnings)
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");
3583
sql_print_error(_("Error reading relay log event: %s"), errmsg);
3645
sql_print_error("Error reading relay log event: %s", errmsg);
3653
3715
{33029, { 5, 0, 0 }, { 5, 0, 58 } },
3654
3716
{33029, { 5, 1, 0 }, { 5, 1, 12 } },
3656
const unsigned char *master_ver=
3718
const uchar *master_ver=
3657
3719
rli->relay_log.description_event_for_exec->server_version_split;
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++)
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))
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"
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"
3696
rli->relay_log.description_event_for_exec->server_version,
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"
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]);