95
89
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"),
92
"Waiting to reconnect after a failed registration on master",
93
"Slave I/O thread killed while waitnig to reconnect after a failed \
94
registration on master",
95
"Reconnecting after a failed registration on master",
96
"failed registering on master, reconnecting to try again, \
97
log '%s' at postion %s",
104
98
"COM_REGISTER_SLAVE",
105
N_("Slave I/O thread killed during or after reconnect")
99
"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"),
102
"Waiting to reconnect after a failed binlog dump request",
103
"Slave I/O thread killed while retrying master dump",
104
"Reconnecting after a failed binlog dump request",
105
"failed dump request, reconnecting to try again, log '%s' at postion %s",
113
106
"COM_BINLOG_DUMP",
114
N_("Slave I/O thread killed during or after reconnect")
107
"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"),
110
"Waiting to reconnect after a failed master event read",
111
"Slave I/O thread killed while waiting to reconnect after a failed read",
112
"Reconnecting after a failed master event read",
113
"Slave I/O thread: Failed reading log event, reconnecting to retry, \
114
log '%s' at postion %s",
124
N_("Slave I/O thread killed during or after a "
125
"reconnect done to recover from failed read")
116
"Slave I/O thread killed during or after a reconnect done to recover from \
130
122
typedef enum { SLAVE_THD_IO, SLAVE_THD_SQL} SLAVE_THD_TYPE;
132
static int32_t process_io_rotate(Master_info* mi, Rotate_log_event* rev);
133
static int32_t process_io_create_file(Master_info* mi, Create_file_log_event* cev);
124
static int process_io_rotate(Master_info* mi, Rotate_log_event* rev);
125
static int process_io_create_file(Master_info* mi, Create_file_log_event* cev);
134
126
static bool wait_for_relay_log_space(Relay_log_info* rli);
135
127
static inline bool io_slave_killed(THD* thd,Master_info* mi);
136
128
static inline bool sql_slave_killed(THD* thd,Relay_log_info* rli);
137
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 int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type);
130
static int safe_connect(THD* thd, MYSQL* mysql, Master_info* mi);
131
static int safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
140
132
bool suppress_warnings);
141
static int32_t connect_to_master(THD* thd, DRIZZLE *drizzle, Master_info* mi,
133
static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
142
134
bool reconnect, bool suppress_warnings);
143
static int32_t safe_sleep(THD* thd, int32_t sec, CHECK_KILLED_FUNC thread_killed,
135
static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed,
144
136
void* thread_killed_arg);
145
static int32_t get_master_version_and_clock(DRIZZLE *drizzle, Master_info* mi);
137
static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi);
146
138
static Log_event* next_event(Relay_log_info* rli);
147
static int32_t queue_event(Master_info* mi,const char* buf,uint32_t event_len);
148
static int32_t terminate_slave_thread(THD *thd,
139
static int queue_event(Master_info* mi,const char* buf,ulong event_len);
140
static int terminate_slave_thread(THD *thd,
149
141
pthread_mutex_t* term_lock,
150
142
pthread_cond_t* term_cond,
151
volatile uint32_t *slave_running,
143
volatile uint *slave_running,
153
145
static bool check_io_slave_killed(THD *thd, Master_info *mi, const char *info);
303
304
if (!(p= str2int(p, 10, 0, LONG_MAX, &err_code)))
305
306
if (err_code < MAX_SLAVE_ERROR)
306
bitmap_set_bit(&slave_error_mask,(uint32_t)err_code);
307
bitmap_set_bit(&slave_error_mask,(uint)err_code);
307
308
while (!my_isdigit(system_charset_info,*p) && *p)
314
int32_t terminate_slave_threads(Master_info* mi,int32_t thread_mask,bool skip_lock)
315
int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock)
317
DBUG_ENTER("terminate_slave_threads");
317
return(0); /* successfully do nothing */
318
int32_t error,force_all = (thread_mask & SLAVE_FORCE_ALL);
320
DBUG_RETURN(0); /* successfully do nothing */
321
int error,force_all = (thread_mask & SLAVE_FORCE_ALL);
319
322
pthread_mutex_t *sql_lock = &mi->rli.run_lock, *io_lock = &mi->run_lock;
321
324
if ((thread_mask & (SLAVE_IO|SLAVE_FORCE_ALL)))
326
DBUG_PRINT("info",("Terminating IO thread"));
323
327
mi->abort_slave=1;
324
328
if ((error=terminate_slave_thread(mi->io_thd,io_lock,
326
330
&mi->slave_running,
331
335
if ((thread_mask & (SLAVE_SQL|SLAVE_FORCE_ALL)))
337
DBUG_PRINT("info",("Terminating SQL thread"));
333
338
mi->rli.abort_slave=1;
334
339
if ((error=terminate_slave_thread(mi->rli.sql_thd,sql_lock,
335
340
&mi->rli.stop_cond,
336
341
&mi->rli.slave_running,
421
430
struct timespec abstime;
422
431
set_timespec(abstime,2);
423
432
error= pthread_cond_timedwait(term_cond, term_lock, &abstime);
424
assert(error == ETIMEDOUT || error == 0);
433
DBUG_ASSERT(error == ETIMEDOUT || error == 0);
427
assert(*slave_running == 0);
436
DBUG_ASSERT(*slave_running == 0);
430
439
pthread_mutex_unlock(term_lock);
435
int32_t start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock,
436
pthread_mutex_t *cond_lock,
437
pthread_cond_t *start_cond,
438
volatile uint32_t *slave_running,
439
volatile uint32_t *slave_run_id,
444
int start_slave_thread(pthread_handler h_func, pthread_mutex_t *start_lock,
445
pthread_mutex_t *cond_lock,
446
pthread_cond_t *start_cond,
447
volatile uint *slave_running,
448
volatile ulong *slave_run_id,
454
DBUG_ENTER("start_slave_thread");
456
DBUG_ASSERT(mi->inited);
449
459
pthread_mutex_lock(start_lock);
535
546
if (thread_mask & SLAVE_IO)
536
error= start_slave_thread(handle_slave_io,lock_io,lock_cond_io,
538
&mi->slave_running, &mi->slave_run_id,
539
mi, 1); //high priority, to read the most possible
547
error=start_slave_thread(handle_slave_io,lock_io,lock_cond_io,
549
&mi->slave_running, &mi->slave_run_id,
550
mi, 1); //high priority, to read the most possible
540
551
if (!error && (thread_mask & SLAVE_SQL))
542
error= start_slave_thread(handle_slave_sql,lock_sql,lock_cond_sql,
544
&mi->rli.slave_running, &mi->rli.slave_run_id,
553
error=start_slave_thread(handle_slave_sql,lock_sql,lock_cond_sql,
555
&mi->rli.slave_running, &mi->rli.slave_run_id,
547
558
terminate_slave_threads(mi, thread_mask & SLAVE_IO, 0);
553
564
#ifdef NOT_USED_YET
554
static int32_t end_slave_on_walk(Master_info* mi, unsigned char* /*unused*/)
565
static int end_slave_on_walk(Master_info* mi, uchar* /*unused*/)
567
DBUG_ENTER("end_slave_on_walk");
556
569
end_master_info(mi);
584
599
once multi-master code is ready.
586
601
terminate_slave_threads(active_mi,SLAVE_FORCE_ALL);
587
active_mi->end_master_info();
602
end_master_info(active_mi);
588
603
delete active_mi;
591
606
pthread_mutex_unlock(&LOCK_active_mi);
596
611
static bool io_slave_killed(THD* thd, Master_info* mi)
598
assert(mi->io_thd == thd);
599
assert(mi->slave_running); // tracking buffer overrun
600
return(mi->abort_slave || abort_loop || thd->killed);
613
DBUG_ENTER("io_slave_killed");
615
DBUG_ASSERT(mi->io_thd == thd);
616
DBUG_ASSERT(mi->slave_running); // tracking buffer overrun
617
DBUG_RETURN(mi->abort_slave || abort_loop || thd->killed);
604
621
static bool sql_slave_killed(THD* thd, Relay_log_info* rli)
606
assert(rli->sql_thd == thd);
607
assert(rli->slave_running == 1);// tracking buffer overrun
623
DBUG_ENTER("sql_slave_killed");
625
DBUG_ASSERT(rli->sql_thd == thd);
626
DBUG_ASSERT(rli->slave_running == 1);// tracking buffer overrun
608
627
if (abort_loop || thd->killed || rli->abort_slave)
684
711
If we truncated a line or stopped on last char, remove all chars
685
712
up to and including newline.
688
while (((c=my_b_get(f)) != '\n' && c != my_b_EOF)) {};
715
while (((c=my_b_get(f)) != '\n' && c != my_b_EOF));
692
719
else if (default_val)
694
721
strmake(var, default_val, max_size-1);
701
int32_t init_intvar_from_file(int32_t* var, IO_CACHE* f, int32_t default_val)
728
int init_intvar_from_file(int* var, IO_CACHE* f, int default_val)
731
DBUG_ENTER("init_intvar_from_file");
706
734
if (my_b_gets(f, buf, sizeof(buf)))
708
736
*var = atoi(buf);
711
739
else if (default_val)
713
741
*var = default_val;
719
int32_t init_floatvar_from_file(float* var, IO_CACHE* f, float default_val)
747
int init_floatvar_from_file(float* var, IO_CACHE* f, float default_val)
750
DBUG_ENTER("init_floatvar_from_file");
724
753
if (my_b_gets(f, buf, sizeof(buf)))
726
755
if (sscanf(buf, "%f", var) != 1)
731
760
else if (default_val != 0.0)
733
762
*var = default_val;
739
768
static bool check_io_slave_killed(THD *thd, Master_info *mi, const char *info)
793
Note the following switch will bug when we have DRIZZLE branch 30 ;)
823
Note the following switch will bug when we have MySQL branch 30 ;)
795
switch (*drizzle->server_version)
825
switch (*mysql->server_version)
800
errmsg = _("Master reported unrecognized DRIZZLE version");
830
errmsg = "Master reported unrecognized MySQL version";
801
831
err_code= ER_SLAVE_FATAL_ERROR;
802
832
sprintf(err_buff, ER(err_code), errmsg);
803
833
err_msg.append(err_buff);
806
836
mi->rli.relay_log.description_event_for_queue= new
807
Format_description_log_event(1, drizzle->server_version);
837
Format_description_log_event(1, mysql->server_version);
810
840
mi->rli.relay_log.description_event_for_queue= new
811
Format_description_log_event(3, drizzle->server_version);
841
Format_description_log_event(3, mysql->server_version);
815
Master is DRIZZLE >=5.0. Give a default Format_desc event, so that we can
845
Master is MySQL >=5.0. Give a default Format_desc event, so that we can
816
846
take the early steps (like tests for "is this a 3.23 master") which we
817
847
have to take before we receive the real master's Format_desc which will
818
848
override this one. Note that the Format_desc we create below is garbage
878
908
Note: we could have put a @@SERVER_ID in the previous SELECT
879
909
UNIX_TIMESTAMP() instead, but this would not have worked on 3.23 masters.
881
if (!drizzle_real_query(drizzle,
911
if (!mysql_real_query(mysql,
882
912
STRING_WITH_LEN("SHOW VARIABLES LIKE 'SERVER_ID'")) &&
883
(master_res= drizzle_store_result(drizzle)))
913
(master_res= mysql_store_result(mysql)))
885
if ((master_row= drizzle_fetch_row(master_res)) &&
915
if ((master_row= mysql_fetch_row(master_res)) &&
886
916
(::server_id == strtoul(master_row[1], 0, 10)) &&
887
917
!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).");
920
"The slave I/O thread stops because master and slave have equal"
921
" MySQL server ids; these ids must be different for replication to work (or"
922
" the --replicate-same-server-id option must be used on slave but this does"
923
" not always make sense; please check the manual before using it).";
896
924
err_code= ER_SLAVE_FATAL_ERROR;
897
925
sprintf(err_buff, ER(err_code), errmsg);
898
926
err_msg.append(err_buff);
900
drizzle_free_result(master_res);
928
mysql_free_result(master_res);
922
950
/* redundant with rest of code but safer against later additions */
923
if (*drizzle->server_version == '3')
951
if (*mysql->server_version == '3')
926
if ((*drizzle->server_version == '4') &&
927
!drizzle_real_query(drizzle,
954
if ((*mysql->server_version == '4') &&
955
!mysql_real_query(mysql,
928
956
STRING_WITH_LEN("SELECT @@GLOBAL.COLLATION_SERVER")) &&
929
(master_res= drizzle_store_result(drizzle)))
957
(master_res= mysql_store_result(mysql)))
931
if ((master_row= drizzle_fetch_row(master_res)) &&
959
if ((master_row= mysql_fetch_row(master_res)) &&
932
960
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");
963
"The slave I/O thread stops because master and slave have"
964
" different values for the COLLATION_SERVER global variable."
965
" The values must be equal for replication to work";
938
966
err_code= ER_SLAVE_FATAL_ERROR;
939
967
sprintf(err_buff, ER(err_code), errmsg);
940
968
err_msg.append(err_buff);
942
drizzle_free_result(master_res);
970
mysql_free_result(master_res);
959
987
This check is only necessary for 4.x masters (and < 5.0.4 masters but
960
988
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)))
990
if ((*mysql->server_version == '4') &&
991
!mysql_real_query(mysql, STRING_WITH_LEN("SELECT @@GLOBAL.TIME_ZONE")) &&
992
(master_res= mysql_store_result(mysql)))
966
if ((master_row= drizzle_fetch_row(master_res)) &&
994
if ((master_row= mysql_fetch_row(master_res)) &&
967
995
strcmp(master_row[0],
968
996
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");
999
"The slave I/O thread stops because master and slave have"
1000
" different values for the TIME_ZONE global variable."
1001
" The values must be equal for replication to work";
974
1002
err_code= ER_SLAVE_FATAL_ERROR;
975
1003
sprintf(err_buff, ER(err_code), errmsg);
976
1004
err_msg.append(err_buff);
978
drizzle_free_result(master_res);
1006
mysql_free_result(master_res);
987
1015
const char query_format[]= "SET @master_heartbeat_period= %s";
988
1016
char query[sizeof(query_format) - 2 + sizeof(llbuf)];
990
the period is an uint64_t of nano-secs.
1018
the period is an ulonglong of nano-secs.
992
llstr((uint64_t) (mi->heartbeat_period*1000000000UL), llbuf);
993
sprintf(query, query_format, llbuf);
1020
llstr((ulonglong) (mi->heartbeat_period*1000000000UL), llbuf);
1021
my_sprintf(query, (query, query_format, llbuf));
995
if (drizzle_real_query(drizzle, query, strlen(query))
1023
if (mysql_real_query(mysql, query, strlen(query))
996
1024
&& !check_io_slave_killed(mi->io_thd, mi, NULL))
998
1026
err_msg.append("The slave I/O thread stops because querying master with '");
999
1027
err_msg.append(query);
1000
1028
err_msg.append("' failed;");
1001
1029
err_msg.append(" error: ");
1002
err_code= drizzle_errno(drizzle);
1030
err_code= mysql_errno(mysql);
1003
1031
err_msg.qs_append(err_code);
1004
1032
err_msg.append(" '");
1005
err_msg.append(drizzle_error(drizzle));
1033
err_msg.append(mysql_error(mysql));
1006
1034
err_msg.append("'");
1007
drizzle_free_result(drizzle_store_result(drizzle));
1035
mysql_free_result(mysql_store_result(mysql));
1010
drizzle_free_result(drizzle_store_result(drizzle));
1038
mysql_free_result(mysql_store_result(mysql));
1014
1042
if (err_msg.length() != 0)
1016
1044
sql_print_error(err_msg.ptr());
1017
assert(err_code != 0);
1045
DBUG_ASSERT(err_code != 0);
1018
1046
mi->report(ERROR_LEVEL, err_code, err_msg.ptr());
1079
1109
if (unlikely(rli->relay_log.append(ev)))
1080
1110
mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
1081
1111
ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
1082
_("failed to write a Rotate event"
1083
" to the relay log, SHOW SLAVE STATUS may be"
1112
"failed to write a Rotate event"
1113
" to the relay log, SHOW SLAVE STATUS may be"
1085
1115
rli->relay_log.harvest_bytes_written(&rli->log_space_total);
1087
sql_print_error(_("Failed to flush master info file"));
1116
if (flush_master_info(mi, 1))
1117
sql_print_error("Failed to flush master info file");
1091
1121
mi->report(ERROR_LEVEL, ER_SLAVE_CREATE_EVENT_FAILURE,
1092
1122
ER(ER_SLAVE_CREATE_EVENT_FAILURE),
1093
_("Rotate_event (out of memory?),"
1094
" SHOW SLAVE STATUS may be inaccurate"));
1123
"Rotate_event (out of memory?),"
1124
" SHOW SLAVE STATUS may be inaccurate");
1097
1127
pthread_mutex_unlock(log_lock);
1102
int32_t register_slave_on_master(DRIZZLE *drizzle, Master_info *mi,
1132
int register_slave_on_master(MYSQL* mysql, Master_info *mi,
1103
1133
bool *suppress_warnings)
1105
unsigned char buf[1024], *pos= buf;
1106
uint32_t report_host_len, report_user_len=0, report_password_len=0;
1135
uchar buf[1024], *pos= buf;
1136
uint report_host_len, report_user_len=0, report_password_len=0;
1137
DBUG_ENTER("register_slave_on_master");
1108
*suppress_warnings= false;
1139
*suppress_warnings= FALSE;
1109
1140
if (!report_host)
1111
1142
report_host_len= strlen(report_host);
1112
1143
if (report_user)
1113
1144
report_user_len= strlen(report_user);
1116
1147
/* 30 is a good safety margin */
1117
1148
if (report_host_len + report_user_len + report_password_len + 30 >
1119
return(0); // safety
1150
DBUG_RETURN(0); // safety
1121
1152
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;
1153
pos= net_store_data(pos, (uchar*) report_host, report_host_len);
1154
pos= net_store_data(pos, (uchar*) report_user, report_user_len);
1155
pos= net_store_data(pos, (uchar*) report_password, report_password_len);
1156
int2store(pos, (uint16) report_port); pos+= 2;
1157
int4store(pos, rpl_recovery_rank); pos+= 4;
1127
1158
/* The master will fill in master_id */
1128
1159
int4store(pos, 0); pos+= 4;
1130
if (simple_command(drizzle, COM_REGISTER_SLAVE, buf, (size_t) (pos- buf), 0))
1161
if (simple_command(mysql, COM_REGISTER_SLAVE, buf, (size_t) (pos- buf), 0))
1132
if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
1163
if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1134
*suppress_warnings= true; // Suppress reconnect warning
1165
*suppress_warnings= TRUE; // Suppress reconnect warning
1136
1167
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));
1170
my_snprintf(buf, sizeof(buf), "%s (Errno: %d)", mysql_error(mysql),
1171
mysql_errno(mysql));
1141
1172
mi->report(ERROR_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
1142
1173
ER(ER_SLAVE_MASTER_COM_FAILURE), "COM_REGISTER_SLAVE", buf);
1182
1214
field_list.push_back(new Item_empty_string("Replicate_Wild_Do_Table", 24));
1183
1215
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));
1217
field_list.push_back(new Item_return_int("Last_Errno", 4, MYSQL_TYPE_LONG));
1186
1218
field_list.push_back(new Item_empty_string("Last_Error", 20));
1187
1219
field_list.push_back(new Item_return_int("Skip_Counter", 10,
1188
DRIZZLE_TYPE_LONG));
1189
1221
field_list.push_back(new Item_return_int("Exec_Master_Log_Pos", 10,
1190
DRIZZLE_TYPE_LONGLONG));
1222
MYSQL_TYPE_LONGLONG));
1191
1223
field_list.push_back(new Item_return_int("Relay_Log_Space", 10,
1192
DRIZZLE_TYPE_LONGLONG));
1224
MYSQL_TYPE_LONGLONG));
1193
1225
field_list.push_back(new Item_empty_string("Until_Condition", 6));
1194
1226
field_list.push_back(new Item_empty_string("Until_Log_File", FN_REFLEN));
1195
1227
field_list.push_back(new Item_return_int("Until_Log_Pos", 10,
1196
DRIZZLE_TYPE_LONGLONG));
1228
MYSQL_TYPE_LONGLONG));
1229
field_list.push_back(new Item_empty_string("Master_SSL_Allowed", 7));
1230
field_list.push_back(new Item_empty_string("Master_SSL_CA_File",
1231
sizeof(mi->ssl_ca)));
1232
field_list.push_back(new Item_empty_string("Master_SSL_CA_Path",
1233
sizeof(mi->ssl_capath)));
1234
field_list.push_back(new Item_empty_string("Master_SSL_Cert",
1235
sizeof(mi->ssl_cert)));
1236
field_list.push_back(new Item_empty_string("Master_SSL_Cipher",
1237
sizeof(mi->ssl_cipher)));
1238
field_list.push_back(new Item_empty_string("Master_SSL_Key",
1239
sizeof(mi->ssl_key)));
1197
1240
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));
1241
MYSQL_TYPE_LONGLONG));
1242
field_list.push_back(new Item_empty_string("Master_SSL_Verify_Server_Cert",
1244
field_list.push_back(new Item_return_int("Last_IO_Errno", 4, MYSQL_TYPE_LONG));
1200
1245
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));
1246
field_list.push_back(new Item_return_int("Last_SQL_Errno", 4, MYSQL_TYPE_LONG));
1202
1247
field_list.push_back(new Item_empty_string("Last_SQL_Error", 20));
1204
1249
if (protocol->send_fields(&field_list,
1205
1250
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1208
1253
if (mi->host[0])
1255
DBUG_PRINT("info",("host is set: '%s'", mi->host));
1210
1256
String *packet= &thd->packet;
1211
1257
protocol->prepare_for_resend();
1215
1261
non-volotile members like mi->io_thd, which is guarded by the mutex.
1217
1263
pthread_mutex_lock(&mi->run_lock);
1218
protocol->store(mi->io_thd ? mi->io_thd->get_proc_info() : "", &my_charset_bin);
1264
protocol->store(mi->io_thd ? mi->io_thd->proc_info : "", &my_charset_bin);
1219
1265
pthread_mutex_unlock(&mi->run_lock);
1221
1267
pthread_mutex_lock(&mi->data_lock);
1222
1268
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()),
1269
protocol->store(mi->host, &my_charset_bin);
1270
protocol->store(mi->user, &my_charset_bin);
1271
protocol->store((uint32) mi->port);
1272
protocol->store((uint32) mi->connect_retry);
1273
protocol->store(mi->master_log_name, &my_charset_bin);
1274
protocol->store((ulonglong) mi->master_log_pos);
1275
protocol->store(mi->rli.group_relay_log_name +
1276
dirname_length(mi->rli.group_relay_log_name),
1231
1277
&my_charset_bin);
1232
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 ?
1278
protocol->store((ulonglong) mi->rli.group_relay_log_pos);
1279
protocol->store(mi->rli.group_master_log_name, &my_charset_bin);
1280
protocol->store(mi->slave_running == MYSQL_SLAVE_RUN_CONNECT ?
1235
1281
"Yes" : "No", &my_charset_bin);
1236
1282
protocol->store(mi->rli.slave_running ? "Yes":"No", &my_charset_bin);
1237
1283
protocol->store(rpl_filter->get_do_db());
1251
1297
protocol->store(mi->rli.last_error().number);
1252
1298
protocol->store(mi->rli.last_error().message, &my_charset_bin);
1253
protocol->store((uint32_t) mi->rli.slave_skip_counter);
1254
protocol->store((uint64_t) mi->rli.group_master_log_pos);
1255
protocol->store((uint64_t) mi->rli.log_space_total);
1299
protocol->store((uint32) mi->rli.slave_skip_counter);
1300
protocol->store((ulonglong) mi->rli.group_master_log_pos);
1301
protocol->store((ulonglong) mi->rli.log_space_total);
1257
1303
protocol->store(
1258
1304
mi->rli.until_condition==Relay_log_info::UNTIL_NONE ? "None":
1259
1305
( mi->rli.until_condition==Relay_log_info::UNTIL_MASTER_POS? "Master":
1260
1306
"Relay"), &my_charset_bin);
1261
1307
protocol->store(mi->rli.until_log_name, &my_charset_bin);
1262
protocol->store((uint64_t) mi->rli.until_log_pos);
1308
protocol->store((ulonglong) mi->rli.until_log_pos);
1310
protocol->store(mi->ssl? "Ignored":"No", &my_charset_bin);
1311
protocol->store(mi->ssl_ca, &my_charset_bin);
1312
protocol->store(mi->ssl_capath, &my_charset_bin);
1313
protocol->store(mi->ssl_cert, &my_charset_bin);
1314
protocol->store(mi->ssl_cipher, &my_charset_bin);
1315
protocol->store(mi->ssl_key, &my_charset_bin);
1265
1318
Seconds_Behind_Master: if SQL thread is running and I/O thread is
1266
1319
connected, we can compute it otherwise show NULL (i.e. unknown).
1268
if ((mi->slave_running == DRIZZLE_SLAVE_RUN_CONNECT) &&
1321
if ((mi->slave_running == MYSQL_SLAVE_RUN_CONNECT) &&
1269
1322
mi->rli.slave_running)
1271
1324
long time_diff= ((long)(time(0) - mi->rli.last_master_timestamp)
1329
1384
when max_join_size is 4G, OPTION_BIG_SELECTS is automatically set, but
1330
1385
only for client threads.
1332
uint64_t options= thd->options | OPTION_BIG_SELECTS;
1387
ulonglong options= thd->options | OPTION_BIG_SELECTS;
1333
1388
if (opt_log_slave_updates)
1334
1389
options|= OPTION_BIN_LOG;
1336
1391
options&= ~OPTION_BIN_LOG;
1337
1392
thd->options= options;
1338
1393
thd->variables.completion_type= 0;
1397
void set_slave_thread_default_charset(THD* thd, Relay_log_info const *rli)
1399
DBUG_ENTER("set_slave_thread_default_charset");
1401
thd->variables.character_set_client=
1402
global_system_variables.character_set_client;
1403
thd->variables.collation_connection=
1404
global_system_variables.collation_connection;
1405
thd->variables.collation_server=
1406
global_system_variables.collation_server;
1407
thd->update_charset();
1410
We use a const cast here since the conceptual (and externally
1411
visible) behavior of the function is to set the default charset of
1412
the thread. That the cache has to be invalidated is a secondary
1415
const_cast<Relay_log_info*>(rli)->cached_charset_invalidate();
1343
1420
init_slave_thread()
1346
static int32_t init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type)
1423
static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type)
1348
int32_t simulate_error= 0;
1425
DBUG_ENTER("init_slave_thread");
1426
#if !defined(DBUG_OFF)
1427
int simulate_error= 0;
1349
1429
thd->system_thread = (thd_type == SLAVE_THD_SQL) ?
1350
1430
SYSTEM_THREAD_SLAVE_SQL : SYSTEM_THREAD_SLAVE_IO;
1351
1431
thd->security_ctx->skip_grants();
1358
1438
thd->variables.max_allowed_packet= global_system_variables.max_allowed_packet
1359
1439
+ MAX_LOG_EVENT_HEADER; /* note, incr over the global not session var */
1360
1440
thd->slave_thread = 1;
1441
thd->enable_slow_log= opt_log_slow_slave_statements;
1361
1442
set_slave_thread_options(thd);
1362
1443
thd->client_capabilities = CLIENT_LOCAL_FILES;
1363
1444
pthread_mutex_lock(&LOCK_thread_count);
1364
1445
thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
1365
1446
pthread_mutex_unlock(&LOCK_thread_count);
1367
simulate_error|= (1 << SLAVE_THD_IO);
1368
simulate_error|= (1 << SLAVE_THD_SQL);
1448
DBUG_EXECUTE_IF("simulate_io_slave_error_on_init",
1449
simulate_error|= (1 << SLAVE_THD_IO););
1450
DBUG_EXECUTE_IF("simulate_sql_slave_error_on_init",
1451
simulate_error|= (1 << SLAVE_THD_SQL););
1452
#if !defined(DBUG_OFF)
1369
1453
if (init_thr_lock() || thd->store_globals() || simulate_error & (1<< thd_type))
1455
if (init_thr_lock() || thd->store_globals())
1371
1458
thd->cleanup();
1374
1461
lex_start(thd);
1376
1463
if (thd_type == SLAVE_THD_SQL)
1377
thd->set_proc_info("Waiting for the next event in relay log");
1464
thd_proc_info(thd, "Waiting for the next event in relay log");
1379
thd->set_proc_info("Waiting for master update");
1466
thd_proc_info(thd, "Waiting for master update");
1380
1467
thd->version=refresh_version;
1381
1468
thd->set_time();
1386
static int32_t safe_sleep(THD* thd, int32_t sec, CHECK_KILLED_FUNC thread_killed,
1473
static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed,
1387
1474
void* thread_killed_arg)
1390
1477
thr_alarm_t alarmed;
1478
DBUG_ENTER("safe_sleep");
1392
1480
thr_alarm_init(&alarmed);
1393
1481
time_t start_time= my_time(0);
1394
1482
time_t end_time= start_time+sec;
1396
while ((nap_time= (int32_t) (end_time - start_time)) > 0)
1484
while ((nap_time= (int) (end_time - start_time)) > 0)
1398
1486
ALARM alarm_buff;
1406
1494
thr_end_alarm(&alarmed);
1408
1496
if ((*thread_killed)(thd,thread_killed_arg))
1410
1498
start_time= my_time(0);
1416
static int32_t request_dump(DRIZZLE *drizzle, Master_info* mi,
1504
static int request_dump(MYSQL* mysql, Master_info* mi,
1417
1505
bool *suppress_warnings)
1419
unsigned char buf[FN_REFLEN + 10];
1421
int32_t binlog_flags = 0; // for now
1422
const char* logname = mi->getLogName();
1507
uchar buf[FN_REFLEN + 10];
1509
int binlog_flags = 0; // for now
1510
char* logname = mi->master_log_name;
1511
DBUG_ENTER("request_dump");
1424
*suppress_warnings= false;
1513
*suppress_warnings= FALSE;
1426
1515
// TODO if big log files: Change next to int8store()
1427
int4store(buf, (uint32_t) mi->getLogPosition());
1516
int4store(buf, (ulong) mi->master_log_pos);
1428
1517
int2store(buf + 4, binlog_flags);
1429
1518
int4store(buf + 6, server_id);
1430
len = (uint32_t) strlen(logname);
1519
len = (uint) strlen(logname);
1431
1520
memcpy(buf + 10, logname,len);
1432
if (simple_command(drizzle, COM_BINLOG_DUMP, buf, len + 10, 1))
1521
if (simple_command(mysql, COM_BINLOG_DUMP, buf, len + 10, 1))
1435
1524
Something went wrong, so we will just reconnect and retry later
1436
1525
in the future, we should do a better error analysis, but for
1437
1526
now we just fill up the error log :-)
1439
if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
1440
*suppress_warnings= true; // Suppress reconnect warning
1528
if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1529
*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),
1531
sql_print_error("Error on COM_BINLOG_DUMP: %d %s, will retry in %d secs",
1532
mysql_errno(mysql), mysql_error(mysql),
1444
1533
mi->connect_retry);
1465
1554
number Length of packet
1468
static uint32_t read_event(DRIZZLE *drizzle,
1469
Master_info *mi __attribute__((unused)),
1470
bool* suppress_warnings)
1557
static ulong read_event(MYSQL* mysql, Master_info *mi, bool* suppress_warnings)
1560
DBUG_ENTER("read_event");
1474
*suppress_warnings= false;
1562
*suppress_warnings= FALSE;
1476
1564
my_real_read() will time us out
1477
1565
We check if we were told to die, and if not, try reading again
1479
1568
if (disconnect_slave_event_count && !(mi->events_till_disconnect--))
1480
return(packet_error);
1569
DBUG_RETURN(packet_error);
1482
len = cli_safe_read(drizzle);
1483
if (len == packet_error || (int32_t) len < 1)
1572
len = cli_safe_read(mysql);
1573
if (len == packet_error || (long) len < 1)
1485
if (drizzle_errno(drizzle) == ER_NET_READ_INTERRUPTED)
1575
if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
1488
1578
We are trying a normal reconnect after a read timeout;
1489
1579
we suppress prints to .err file as long as the reconnect
1490
1580
happens without problems
1492
*suppress_warnings= true;
1582
*suppress_warnings= TRUE;
1495
sql_print_error(_("Error reading packet from server: %s ( server_errno=%d)"),
1496
drizzle_error(drizzle), drizzle_errno(drizzle));
1497
return(packet_error);
1585
sql_print_error("Error reading packet from server: %s ( server_errno=%d)",
1586
mysql_error(mysql), mysql_errno(mysql));
1587
DBUG_RETURN(packet_error);
1500
1590
/* Check if eof packet */
1501
if (len < 8 && drizzle->net.read_pos[0] == 254)
1591
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));
1506
return(packet_error);
1593
sql_print_information("Slave: received end packet from server, apparent "
1594
"master shutdown: %s",
1595
mysql_error(mysql));
1596
DBUG_RETURN(packet_error);
1599
DBUG_PRINT("exit", ("len: %lu net->read_pos[4]: %d",
1600
len, mysql->net.read_pos[4]));
1601
DBUG_RETURN(len - 1);
1513
int32_t check_expected_error(THD* thd __attribute__((unused)),
1514
Relay_log_info const *rli __attribute__((unused)),
1515
int32_t expected_error)
1605
int check_expected_error(THD* thd, Relay_log_info const *rli,
1608
DBUG_ENTER("check_expected_error");
1517
1610
switch (expected_error) {
1518
1611
case ER_NET_READ_ERROR:
1519
1612
case ER_NET_ERROR_ON_WRITE:
1520
1613
case ER_QUERY_INTERRUPTED:
1521
1614
case ER_SERVER_SHUTDOWN:
1522
1615
case ER_NEW_ABORTING_CONNECTION:
1633
int32_t reason= ev->shall_skip(rli);
1739
int reason= ev->shall_skip(rli);
1634
1740
if (reason == Log_event::EVENT_SKIP_COUNT)
1635
1741
--rli->slave_skip_counter;
1636
1742
pthread_mutex_unlock(&rli->data_lock);
1637
1743
if (reason == Log_event::EVENT_SKIP_NOT)
1638
1744
exec_res= ev->apply_event(rli);
1747
This only prints information to the debug trace.
1749
TODO: Print an informational message to the error log?
1751
static const char *const explain[] = {
1754
// EVENT_SKIP_IGNORE,
1755
"skipped because event should be ignored",
1757
"skipped because event skip counter was non-zero"
1759
DBUG_PRINT("info", ("OPTION_BEGIN: %d; IN_STMT: %d",
1760
thd->options & OPTION_BEGIN ? 1 : 0,
1761
rli->get_flag(Relay_log_info::IN_STMT)));
1762
DBUG_PRINT("skip_event", ("%s event was %s",
1763
ev->get_type_str(), explain[reason]));
1641
1767
exec_res= ev->apply_event(rli);
1769
DBUG_PRINT("info", ("apply_event error = %d", exec_res));
1643
1770
if (exec_res == 0)
1645
int32_t error= ev->update_pos(rli);
1772
int error= ev->update_pos(rli);
1780
DBUG_PRINT("info", ("update_pos error = %d", error));
1781
DBUG_PRINT("info", ("group %s %s",
1782
llstr(rli->group_relay_log_pos, buf),
1783
rli->group_relay_log_name));
1784
DBUG_PRINT("info", ("event %s %s",
1785
llstr(rli->event_relay_log_pos, buf),
1786
rli->event_relay_log_name));
1647
1789
The update should not fail, so print an error message and
1648
1790
return an error code.
1783
1927
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"));
1929
if (init_master_info(rli->mi, 0, 0, 0, SLAVE_SQL))
1930
sql_print_error("Failed to initialize the master info structure");
1787
1931
else if (init_relay_log_pos(rli,
1788
rli->group_relay_log_name.c_str(),
1932
rli->group_relay_log_name,
1789
1933
rli->group_relay_log_pos,
1790
1934
1, &errmsg, 1))
1791
sql_print_error(_("Error initializing relay log position: %s"),
1935
sql_print_error("Error initializing relay log position: %s",
1796
1940
end_trans(thd, ROLLBACK);
1797
1941
/* chance for concurrent connection to get more locks */
1798
safe_sleep(thd, cmin(rli->trans_retries, (uint32_t)MAX_SLAVE_RETRY_PAUSE),
1942
safe_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
1799
1943
(CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);
1800
1944
pthread_mutex_lock(&rli->data_lock); // because of SHOW STATUS
1801
1945
rli->trans_retries++;
1802
1946
rli->retried_trans++;
1803
1947
pthread_mutex_unlock(&rli->data_lock);
1948
DBUG_PRINT("info", ("Slave retries transaction "
1949
"rli->trans_retries: %lu", rli->trans_retries));
1807
sql_print_error(_("Slave SQL thread retried transaction %lu time(s) "
1808
"in vain, giving up. Consider raising the value of "
1809
"the slave_transaction_retries variable."),
1953
sql_print_error("Slave SQL thread retried transaction %lu time(s) "
1954
"in vain, giving up. Consider raising the value of "
1955
"the slave_transaction_retries variable.",
1810
1956
slave_trans_retries);
1812
else if ((exec_res && !temp_err) ||
1958
else if (exec_res && !temp_err ||
1813
1959
(opt_using_transactions &&
1814
1960
rli->group_relay_log_pos == rli->event_relay_log_pos))
1820
1966
non-transient error, the slave will stop with an error.
1822
1968
rli->trans_retries= 0; // restart from fresh
1969
DBUG_PRINT("info", ("Resetting retry counter, rli->trans_retries: %lu",
1970
rli->trans_retries));
1973
DBUG_RETURN(exec_res);
1827
1975
pthread_mutex_unlock(&rli->data_lock);
1828
1976
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' "
1977
ER(ER_SLAVE_RELAY_LOG_READ_FAILURE), "\
1978
Could not parse relay log event entry. The possible reasons are: the master's \
1979
binary log is corrupted (you can check this by running 'mysqlbinlog' on the \
1980
binary log), the slave's relay log is corrupted (you can check this by running \
1981
'mysqlbinlog' on the relay log), a network problem, or a bug in the master's \
1982
or slave's MySQL code. If you want to check the master's binary log or slave's \
1983
relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' \
1880
2030
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])))
2033
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)
2035
thd->proc_info = messages[SLAVE_RECON_MSG_AFTER];
2036
if (!suppress_warnings)
1889
2038
char buf[256], llbuff[22];
1890
snprintf(buf, sizeof(buf), _(messages[SLAVE_RECON_MSG_FAILED]),
1891
IO_RPL_LOG_NAME, llstr(mi->getLogPosition(), llbuff));
2039
my_snprintf(buf, sizeof(buf), messages[SLAVE_RECON_MSG_FAILED],
2040
IO_RPL_LOG_NAME, llstr(mi->master_log_pos, llbuff));
1893
2042
Raise a warining during registering on master/requesting dump.
1894
2043
Log a message reading event.
1896
if (_(messages[SLAVE_RECON_MSG_COMMAND])[0])
2045
if (messages[SLAVE_RECON_MSG_COMMAND][0])
1898
2047
mi->report(WARNING_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
1899
ER(ER_SLAVE_MASTER_COM_FAILURE),
1900
_(messages[SLAVE_RECON_MSG_COMMAND]), buf);
2048
ER(ER_SLAVE_MASTER_COM_FAILURE),
2049
messages[SLAVE_RECON_MSG_COMMAND], buf);
1904
2053
sql_print_information(buf);
1907
if (safe_reconnect(thd, drizzle, mi, 1) || io_slave_killed(thd, mi))
2056
if (safe_reconnect(thd, mysql, mi, 1) || io_slave_killed(thd, mi))
1909
2058
if (global_system_variables.log_warnings)
1910
sql_print_information(_(messages[SLAVE_RECON_MSG_KILLED_AFTER]));
2059
sql_print_information(messages[SLAVE_RECON_MSG_KILLED_AFTER]);
1959
2114
pthread_mutex_unlock(&mi->run_lock);
1960
2115
pthread_cond_broadcast(&mi->start_cond);
1962
if (!(mi->drizzle= drizzle = drizzle_create(NULL)))
2117
DBUG_PRINT("master_info",("log_file_name: '%s' position: %s",
2118
mi->master_log_name,
2119
llstr(mi->master_log_pos,llbuff)));
2121
if (!(mi->mysql = mysql = mysql_init(NULL)))
1964
2123
mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
1965
ER(ER_SLAVE_FATAL_ERROR), _("error in drizzle_create()"));
2124
ER(ER_SLAVE_FATAL_ERROR), "error in mysql_init()");
1969
thd->set_proc_info("Connecting to master");
2128
thd_proc_info(thd, "Connecting to master");
1970
2129
// we can get killed during safe_connect
1971
if (!safe_connect(thd, drizzle, mi))
2130
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(),
2132
sql_print_information("Slave I/O thread: connected to master '%s@%s:%d',"
2133
"replication started in log '%s' at position %s",
2134
mi->user, mi->host, mi->port,
1976
2135
IO_RPL_LOG_NAME,
1977
llstr(mi->getLogPosition(), llbuff));
2136
llstr(mi->master_log_pos,llbuff));
1979
2138
Adding MAX_LOG_EVENT_HEADER_LEN to the max_packet_size on the I/O
1980
2139
thread, since a replication event can become this much larger than
1981
2140
the corresponding packet (query) sent from client to master.
1983
drizzle->net.max_packet_size= thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER;
2142
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"));
2146
sql_print_information("Slave I/O thread killed while connecting to master");
1993
2152
// 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))
2153
mi->slave_running= MYSQL_SLAVE_RUN_CONNECT;
2154
thd->slave_net = &mysql->net;
2155
thd_proc_info(thd, "Checking master version");
2156
if (get_master_version_and_clock(mysql, mi))
2000
2159
if (mi->rli.relay_log.description_event_for_queue->binlog_version > 1)
2003
2162
Register ourselves with the master.
2005
thd->set_proc_info("Registering slave on master");
2006
if (register_slave_on_master(drizzle, mi, &suppress_warnings))
2164
thd_proc_info(thd, "Registering slave on master");
2165
if (register_slave_on_master(mysql, mi, &suppress_warnings))
2008
2167
if (!check_io_slave_killed(thd, mi, "Slave I/O thread killed "
2009
"while registering slave on master"))
2168
"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,
2170
sql_print_error("Slave I/O thread couldn't register on master");
2171
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2013
2172
reconnect_messages[SLAVE_RECON_ACT_REG]))
2018
2177
goto connected;
2020
if (!retry_count_reg)
2023
sql_print_information(_("Forcing to reconnect slave I/O thread"));
2024
if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2025
reconnect_messages[SLAVE_RECON_ACT_REG]))
2179
DBUG_EXECUTE_IF("FORCE_SLAVE_TO_RECONNECT_REG",
2180
if (!retry_count_reg)
2183
sql_print_information("Forcing to reconnect slave I/O thread");
2184
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2185
reconnect_messages[SLAVE_RECON_ACT_REG]))
2191
DBUG_PRINT("info",("Starting reading binary log from master"));
2031
2192
while (!io_slave_killed(thd,mi))
2033
thd->set_proc_info("Requesting binlog dump");
2034
if (request_dump(drizzle, 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,
2040
reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2044
if (!retry_count_dump)
2047
sql_print_information(_("Forcing to reconnect slave I/O thread"));
2048
if (try_to_reconnect(thd, drizzle, mi, &retry_count, suppress_warnings,
2049
reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2194
thd_proc_info(thd, "Requesting binlog dump");
2195
if (request_dump(mysql, mi, &suppress_warnings))
2197
sql_print_error("Failed on request_dump()");
2198
if (check_io_slave_killed(thd, mi, "Slave I/O thread killed while \
2199
requesting master dump") ||
2200
try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2201
reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2205
DBUG_EXECUTE_IF("FORCE_SLAVE_TO_RECONNECT_DUMP",
2206
if (!retry_count_dump)
2209
sql_print_information("Forcing to reconnect slave I/O thread");
2210
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2211
reconnect_messages[SLAVE_RECON_ACT_DUMP]))
2054
2216
while (!io_slave_killed(thd,mi))
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.
2220
We say "waiting" because read_event() will wait if there's nothing to
2221
read. But if there's something to read, it will not wait. The
2222
important thing is to not confuse users by saying "reading" whereas
2223
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 "
2225
thd_proc_info(thd, "Waiting for master to send event");
2226
event_len= read_event(mysql, mi, &suppress_warnings);
2227
if (check_io_slave_killed(thd, mi, "Slave I/O thread killed while \
2068
if (!retry_count_event)
2070
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,
2073
reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2230
DBUG_EXECUTE_IF("FORCE_SLAVE_TO_RECONNECT_EVENT",
2231
if (!retry_count_event)
2233
retry_count_event++;
2234
sql_print_information("Forcing to reconnect slave I/O thread");
2235
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2236
reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2078
2241
if (event_len == packet_error)
2080
uint32_t drizzle_error_number= drizzle_errno(drizzle);
2081
switch (drizzle_error_number) {
2243
uint mysql_error_number= mysql_errno(mysql);
2244
switch (mysql_error_number) {
2082
2245
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"),
2247
Log entry on master is longer than max_allowed_packet (%ld) on \
2248
slave. If the entry is correct, restart the server with a higher value of \
2249
max_allowed_packet",
2088
2250
thd->variables.max_allowed_packet);
2090
2252
case ER_MASTER_FATAL_ERROR_READING_BINLOG:
2091
sql_print_error(ER(drizzle_error_number), drizzle_error_number,
2092
drizzle_error(drizzle));
2253
sql_print_error(ER(mysql_error_number), mysql_error_number,
2254
mysql_error(mysql));
2094
2256
case EE_OUTOFMEMORY:
2095
2257
case ER_OUTOFMEMORY:
2097
_("Stopping slave I/O thread due to out-of-memory error from master"));
2259
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,
2262
if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
2101
2263
reconnect_messages[SLAVE_RECON_ACT_EVENT]))
2103
2265
goto connected;
2104
2266
} // if (event_len == packet_error)
2106
2268
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))
2269
thd_proc_info(thd, "Queueing master event to the relay log");
2270
if (queue_event(mi,(const char*)mysql->net.read_pos + 1, event_len))
2274
if (flush_master_info(mi, 1))
2114
sql_print_error(_("Failed to flush master info file"));
2276
sql_print_error("Failed to flush master info file");
2126
2288
for no reason, but this function will do a clean read, notice the clean
2127
2289
value and exit immediately.
2293
char llbuf1[22], llbuf2[22];
2294
DBUG_PRINT("info", ("log_space_limit=%s log_space_total=%s \
2295
ignore_log_space_limit=%d",
2296
llstr(rli->log_space_limit,llbuf1),
2297
llstr(rli->log_space_total,llbuf2),
2298
(int) rli->ignore_log_space_limit));
2129
2302
if (rli->log_space_limit && rli->log_space_limit <
2130
2303
rli->log_space_total &&
2131
2304
!rli->ignore_log_space_limit)
2132
2305
if (wait_for_relay_log_space(rli))
2134
sql_print_error(_("Slave I/O thread aborted while waiting for "
2135
"relay log space"));
2307
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);
2316
// print the current replication position
2317
sql_print_information("Slave I/O thread exiting, read up to log '%s', position %s",
2318
IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
2319
VOID(pthread_mutex_lock(&LOCK_thread_count));
2148
2320
thd->query = thd->db = 0; // extra safety
2149
2321
thd->query_length= thd->db_length= 0;
2150
pthread_mutex_unlock(&LOCK_thread_count);
2322
VOID(pthread_mutex_unlock(&LOCK_thread_count));
2154
2326
Here we need to clear the active VIO before closing the
2263
2444
rli->ignore_log_space_limit= 0;
2264
2445
pthread_mutex_unlock(&rli->log_space_lock);
2265
2446
rli->trans_retries= 0; // start from "no error"
2447
DBUG_PRINT("info", ("rli->trans_retries: %lu", rli->trans_retries));
2267
2449
if (init_relay_log_pos(rli,
2268
rli->group_relay_log_name.c_str(),
2450
rli->group_relay_log_name,
2269
2451
rli->group_relay_log_pos,
2270
2452
1 /*need data lock*/, &errmsg,
2271
2453
1 /*look for a description_event*/))
2273
sql_print_error(_("Error initializing relay log position: %s"),
2455
sql_print_error("Error initializing relay log position: %s",
2277
2459
THD_CHECK_SENTRY(thd);
2278
assert(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
2280
Wonder if this is correct. I (Guilhem) wonder if my_b_tell() returns the
2281
correct position when it's called just after my_b_seek() (the questionable
2282
stuff is those "seek is done on next read" comments in the my_b_seek()
2284
The crude reality is that this assertion randomly fails whereas
2285
replication seems to work fine. And there is no easy explanation why it
2286
fails (as we my_b_seek(rli->event_relay_log_pos) at the very end of
2287
init_relay_log_pos() called above). Maybe the assertion would be
2288
meaningful if we held rli->data_lock between the my_b_seek() and the
2291
assert(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
2292
assert(rli->sql_thd == thd);
2462
char llbuf1[22], llbuf2[22];
2463
DBUG_PRINT("info", ("my_b_tell(rli->cur_log)=%s rli->event_relay_log_pos=%s",
2464
llstr(my_b_tell(rli->cur_log),llbuf1),
2465
llstr(rli->event_relay_log_pos,llbuf2)));
2466
DBUG_ASSERT(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
2468
Wonder if this is correct. I (Guilhem) wonder if my_b_tell() returns the
2469
correct position when it's called just after my_b_seek() (the questionable
2470
stuff is those "seek is done on next read" comments in the my_b_seek()
2472
The crude reality is that this assertion randomly fails whereas
2473
replication seems to work fine. And there is no easy explanation why it
2474
fails (as we my_b_seek(rli->event_relay_log_pos) at the very end of
2475
init_relay_log_pos() called above). Maybe the assertion would be
2476
meaningful if we held rli->data_lock between the my_b_seek() and the
2479
#ifdef SHOULD_BE_CHECKED
2480
DBUG_ASSERT(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
2484
DBUG_ASSERT(rli->sql_thd == thd);
2486
DBUG_PRINT("master_info",("log_file_name: %s position: %s",
2487
rli->group_master_log_name,
2488
llstr(rli->group_master_log_pos,llbuff)));
2294
2489
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));
2490
sql_print_information("Slave SQL thread initialized, starting replication in \
2491
log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME,
2492
llstr(rli->group_master_log_pos,llbuff),rli->group_relay_log_name,
2493
llstr(rli->group_relay_log_pos,llbuff1));
2303
2495
/* execute init_slave variable */
2304
2496
if (sys_init_slave.value_length)
2375
2571
if (err->code == ER_CANT_OPEN_LIBRARY)
2376
2572
udf_error = true;
2377
sql_print_warning(_("Slave: %s Error_code: %d"),err->msg, err->code);
2573
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,
2576
sql_print_error("Error loading user-defined library, slave SQL "
2577
"thread aborted. Install the missing library, and restart the "
2578
"slave SQL thread with \"SLAVE START\". We stopped at log '%s' "
2579
"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));
2583
Error running query, slave SQL thread aborted. Fix the problem, and restart \
2584
the slave SQL thread with \"SLAVE START\". We stopped at log \
2585
'%s' position %s", RPL_LOG_NAME, llstr(rli->group_master_log_pos, llbuff));
2399
2591
/* 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));
2592
sql_print_information("Slave SQL thread exiting, replication stopped in log "
2593
"'%s' at position %s",
2594
RPL_LOG_NAME, llstr(rli->group_master_log_pos,llbuff));
2597
static int32_t process_io_rotate(Master_info *mi, Rotate_log_event *rev)
2792
static int process_io_rotate(Master_info *mi, Rotate_log_event *rev)
2794
DBUG_ENTER("process_io_rotate");
2599
2795
safe_mutex_assert_owner(&mi->data_lock);
2601
2797
if (unlikely(!rev->is_valid()))
2604
2800
/* Safe copy as 'rev' has been "sanitized" in Rotate_log_event's ctor */
2605
mi->setLogName(rev->new_log_ident);
2606
mi->setLogPosition(rev->pos);
2801
memcpy(mi->master_log_name, rev->new_log_ident, rev->ident_len+1);
2802
mi->master_log_pos= rev->pos;
2803
DBUG_PRINT("info", ("master_log_pos: '%s' %lu",
2804
mi->master_log_name, (ulong) mi->master_log_pos));
2608
2807
If we do not do this, we will be getting the first
2609
2808
rotate event forever, so we need to not disconnect after one.
2611
2810
if (disconnect_slave_event_count)
2612
2811
mi->events_till_disconnect++;
2615
2815
If description_event_for_queue is format <4, there is conversion in the
2741
2942
pthread_mutex_unlock(&mi->data_lock);
2744
2945
rli->relay_log.harvest_bytes_written(&rli->log_space_total);
2747
mi->incrementLogPosition(inc_pos);
2948
mi->master_log_pos+= inc_pos;
2949
DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos));
2748
2950
pthread_mutex_unlock(&mi->data_lock);
2753
2955
Reads a 4.0 event and converts it to the slave's format. This code was copied
2754
2956
from queue_binlog_ver_1_event(), with some affordable simplifications.
2756
static int32_t queue_binlog_ver_3_event(Master_info *mi, const char *buf,
2958
static int queue_binlog_ver_3_event(Master_info *mi, const char *buf,
2759
2961
const char *errmsg = 0;
2761
2963
char *tmp_buf = 0;
2762
2964
Relay_log_info *rli= &mi->rli;
2965
DBUG_ENTER("queue_binlog_ver_3_event");
2764
2967
/* read_log_event() will adjust log_pos to be end_log_pos */
2765
2968
Log_event *ev = Log_event::read_log_event(buf,event_len, &errmsg,
2766
2969
mi->rli.relay_log.description_event_for_queue);
2767
2970
if (unlikely(!ev))
2769
sql_print_error(_("Read invalid event from master: '%s', "
2770
"master could be corrupt but a more likely cause of "
2972
sql_print_error("Read invalid event from master: '%s',\
2973
master could be corrupt but a more likely cause of this is a bug",
2773
free((char*) tmp_buf);
2975
my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
2776
2978
pthread_mutex_lock(&mi->data_lock);
2777
2979
switch (ev->get_type_code()) {
3008
3220
buf[EVENT_TYPE_OFFSET]!=ROTATE_EVENT &&
3009
3221
buf[EVENT_TYPE_OFFSET]!=STOP_EVENT)
3011
mi->incrementLogPosition(inc_pos);
3012
memcpy(rli->ign_master_log_name_end, mi->getLogName(), FN_REFLEN);
3013
assert(rli->ign_master_log_name_end[0]);
3014
rli->ign_master_log_pos_end= mi->getLogPosition();
3223
mi->master_log_pos+= inc_pos;
3224
memcpy(rli->ign_master_log_name_end, mi->master_log_name, FN_REFLEN);
3225
DBUG_ASSERT(rli->ign_master_log_name_end[0]);
3226
rli->ign_master_log_pos_end= mi->master_log_pos;
3016
3228
rli->relay_log.signal_update(); // the slave SQL thread needs to re-check
3229
DBUG_PRINT("info", ("master_log_pos: %lu, event originating from the same server, ignored",
3230
(ulong) mi->master_log_pos));
3020
3234
/* write the event to the relay log */
3021
3235
if (likely(!(rli->relay_log.appendv(buf,event_len,0))))
3023
mi->incrementLogPosition(inc_pos);
3237
mi->master_log_pos+= inc_pos;
3238
DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos));
3024
3239
rli->relay_log.harvest_bytes_written(&rli->log_space_total);
3101
3321
master_retry_count times
3104
static int32_t connect_to_master(THD* thd, DRIZZLE *drizzle, Master_info* mi,
3105
bool reconnect, bool suppress_warnings)
3324
static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
3325
bool reconnect, bool suppress_warnings)
3107
int32_t slave_was_killed;
3108
int32_t last_errno= -2; // impossible error
3109
uint32_t err_count=0;
3327
int slave_was_killed;
3328
int last_errno= -2; // impossible error
3110
3330
char llbuff[22];
3331
DBUG_ENTER("connect_to_master");
3112
3334
mi->events_till_disconnect = disconnect_slave_event_count;
3113
uint32_t client_flag= CLIENT_REMEMBER_OPTIONS;
3336
ulong client_flag= CLIENT_REMEMBER_OPTIONS;
3114
3337
if (opt_slave_compressed_protocol)
3115
3338
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);
3340
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
3341
mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout);
3343
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset_info->csname);
3344
/* This one is not strictly needed but we have it here for completeness */
3345
mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
3120
3347
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))
3348
(reconnect ? mysql_reconnect(mysql) != 0 :
3349
mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
3350
mi->port, 0, client_flag) == 0))
3125
3352
/* Don't repeat last error */
3126
if ((int32_t)drizzle_errno(drizzle) != last_errno)
3353
if ((int)mysql_errno(mysql) != last_errno)
3128
last_errno=drizzle_errno(drizzle);
3355
last_errno=mysql_errno(mysql);
3129
3356
suppress_warnings= 0;
3130
3357
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);
3358
"error %s to master '%s@%s:%d'"
3359
" - retry-time: %d retries: %lu",
3360
(reconnect ? "reconnecting" : "connecting"),
3361
mi->user, mi->host, mi->port,
3362
mi->connect_retry, master_retry_count);
3138
3365
By default we try forever. The reason is that failure will trigger
3156
3385
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));
3386
sql_print_information("Slave: connected to master '%s@%s:%d',\
3387
replication resumed in log '%s' at position %s", mi->user,
3390
llstr(mi->master_log_pos,llbuff));
3394
change_rpl_status(RPL_IDLE_SLAVE,RPL_ACTIVE_SLAVE);
3395
general_log_print(thd, COM_CONNECT_OUT, "%s@%s:%d",
3396
mi->user, mi->host, mi->port);
3398
#ifdef SIGNAL_WITH_VIO_CLOSE
3399
thd->set_active_vio(mysql->net.vio);
3165
drizzle->reconnect= 1;
3166
return(slave_was_killed);
3402
mysql->reconnect= 1;
3403
DBUG_PRINT("exit",("slave_was_killed: %d", slave_was_killed));
3404
DBUG_RETURN(slave_was_killed);
3563
3837
pthread_mutex_unlock(log_lock);
3564
sql_print_error(_("Slave SQL thread: I/O error reading "
3565
"event(errno: %d cur_log->error: %d)"),
3838
sql_print_error("Slave SQL thread: I/O error reading \
3839
event(errno: %d cur_log->error: %d)",
3566
3840
my_errno,cur_log->error);
3567
3841
// set read position to the beginning of the event
3568
3842
my_b_seek(cur_log,rli->event_relay_log_pos);
3569
3843
/* otherwise, we have had a partial read */
3570
errmsg = _("Aborting slave SQL thread because of partial event read");
3844
errmsg = "Aborting slave SQL thread because of partial event read";
3571
3845
break; // To end of function
3574
3848
if (!errmsg && global_system_variables.log_warnings)
3576
sql_print_information(_("Error reading relay log event: %s"),
3577
_("slave SQL thread was killed"));
3850
sql_print_information("Error reading relay log event: %s",
3851
"slave SQL thread was killed");
3583
sql_print_error(_("Error reading relay log event: %s"), errmsg);
3857
sql_print_error("Error reading relay log event: %s", errmsg);
3588
3862
Rotate a relay log (this is used only by FLUSH LOGS; the automatic rotation
3589
3863
because of size is simpler because when we do it we already have all relevant
3590
3864
locks; here we don't, so this function is mainly taking locks).
3591
Returns nothing as we cannot catch any error (DRIZZLE_BIN_LOG::new_file()
3865
Returns nothing as we cannot catch any error (MYSQL_BIN_LOG::new_file()
3595
3869
void rotate_relay_log(Master_info* mi)
3871
DBUG_ENTER("rotate_relay_log");
3597
3872
Relay_log_info* rli= &mi->rli;
3599
3874
/* We don't lock rli->run_lock. This would lead to deadlocks. */
3653
3929
{33029, { 5, 0, 0 }, { 5, 0, 58 } },
3654
3930
{33029, { 5, 1, 0 }, { 5, 1, 12 } },
3656
const unsigned char *master_ver=
3932
const uchar *master_ver=
3657
3933
rli->relay_log.description_event_for_exec->server_version_split;
3659
assert(sizeof(rli->relay_log.description_event_for_exec->server_version_split) == 3);
3935
DBUG_ASSERT(sizeof(rli->relay_log.description_event_for_exec->server_version_split) == 3);
3662
3938
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,
3940
const uchar *introduced_in= versions_for_all_bugs[i].introduced_in,
3665
3941
*fixed_in= versions_for_all_bugs[i].fixed_in;
3666
3942
if ((versions_for_all_bugs[i].bug_id == bug_id) &&
3667
3943
(memcmp(introduced_in, master_ver, 3) <= 0) &&
3668
3944
(memcmp(fixed_in, master_ver, 3) > 0))
3673
3949
// 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);
3950
my_printf_error(ER_UNKNOWN_ERROR, "master may suffer from"
3951
" http://bugs.mysql.com/bug.php?id=%u"
3952
" so slave stops; check error log on slave"
3953
" for more info", MYF(0), bug_id);
3679
3954
// a verbose message for the error log
3680
3955
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]);
3956
"According to the master's version ('%s'),"
3957
" it is probable that master suffers from this bug:"
3958
" http://bugs.mysql.com/bug.php?id=%u"
3959
" and thus replicating the current binary log event"
3960
" may make the slave's data become different from the"
3962
" To take no risk, slave refuses to replicate"
3963
" this event and stops."
3964
" We recommend that all updates be stopped on the"
3965
" master and slave, that the data of both be"
3966
" manually synchronized,"
3967
" that master's binary logs be deleted,"
3968
" that master be upgraded to a version at least"
3969
" equal to '%d.%d.%d'. Then replication can be"
3971
rli->relay_log.description_event_for_exec->server_version,
3973
fixed_in[0], fixed_in[1], fixed_in[2]);