summaryrefslogtreecommitdiff
path: root/sql/slave.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/slave.cc')
-rw-r--r--sql/slave.cc205
1 files changed, 87 insertions, 118 deletions
diff --git a/sql/slave.cc b/sql/slave.cc
index 67e8ba20c4f..2eb3557641c 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -523,13 +523,13 @@ static bool sql_slave_killed(THD* thd, RELAY_LOG_INFO* rli)
"it some grace period"));
if (difftime(time(0), rli->unsafe_to_stop_at) > 60)
{
- slave_print_msg(ERROR_LEVEL, rli, 0,
- "SQL thread had to stop in an unsafe situation, in "
- "the middle of applying updates to a "
- "non-transactional table without any primary key. "
- "There is a risk of duplicate updates when the slave "
- "SQL thread is restarted. Please check your tables' "
- "contents after restart.");
+ rli->report(ERROR_LEVEL, 0,
+ "SQL thread had to stop in an unsafe situation, in "
+ "the middle of applying updates to a "
+ "non-transactional table without any primary key. "
+ "There is a risk of duplicate updates when the slave "
+ "SQL thread is restarted. Please check your tables' "
+ "contents after restart.");
DBUG_RETURN(1);
}
}
@@ -538,70 +538,6 @@ static bool sql_slave_killed(THD* thd, RELAY_LOG_INFO* rli)
/*
- Writes a message to stderr, and if it's an error message, to
- rli->last_slave_error and rli->last_slave_errno (which will be displayed by
- SHOW SLAVE STATUS).
-
- SYNOPSIS
- slave_print_msg()
- level The severity level
- rli
- err_code The error code
- msg The message (usually related to the error code, but can
- contain more information).
- ... (this is printf-like format, with % symbols in msg)
-
- RETURN VALUES
- void
-*/
-
-void slave_print_msg(enum loglevel level, RELAY_LOG_INFO* rli,
- int err_code, const char* msg, ...)
-{
- void (*report_function)(const char *, ...);
- char buff[MAX_SLAVE_ERRMSG], *pbuff= buff;
- uint pbuffsize= sizeof(buff);
- va_list args;
- DBUG_ENTER("slave_print_msg");
-
- va_start(args,msg);
- switch (level)
- {
- case ERROR_LEVEL:
- /*
- This my_error call only has effect in client threads.
- Slave threads do nothing in my_error().
- */
- my_error(ER_UNKNOWN_ERROR, MYF(0), msg);
- /*
- It's an error, it must be reported in Last_error and Last_errno in SHOW
- SLAVE STATUS.
- */
- pbuff= rli->last_slave_error;
- pbuffsize= sizeof(rli->last_slave_error);
- rli->last_slave_errno = err_code;
- report_function= sql_print_error;
- break;
- case WARNING_LEVEL:
- report_function= sql_print_warning;
- break;
- case INFORMATION_LEVEL:
- report_function= sql_print_information;
- break;
- default:
- DBUG_ASSERT(0); // should not come here
- DBUG_VOID_RETURN; // don't crash production builds, just do nothing
- }
- my_vsnprintf(pbuff, pbuffsize, msg, args);
- /* If the msg string ends with '.', do not add a ',' it would be ugly */
- if (pbuff[0] && (*(strend(pbuff)-1) == '.'))
- (*report_function)("Slave: %s Error_code: %d", pbuff, err_code);
- else
- (*report_function)("Slave: %s, Error_code: %d", pbuff, err_code);
- DBUG_VOID_RETURN;
-}
-
-/*
skip_load_data_infile()
NOTES
@@ -768,7 +704,9 @@ static int get_master_version_and_clock(MYSQL* mysql, MASTER_INFO* mi)
/* as we are here, we tried to allocate the event */
if (!mi->rli.relay_log.description_event_for_queue)
{
- sql_print_error("Slave I/O thread failed to create a default Format_description_log_event");
+ mi->report(ERROR_LEVEL, ER_SLAVE_CREATE_EVENT_FAILURE,
+ ER(ER_SLAVE_CREATE_EVENT_FAILURE),
+ "default Format_description_log_event");
DBUG_RETURN(1);
}
@@ -1128,18 +1066,21 @@ static void write_ignored_events_info_to_relay_log(THD *thd, MASTER_INFO *mi)
{
ev->server_id= 0; // don't be ignored by slave SQL thread
if (unlikely(rli->relay_log.append(ev)))
- sql_print_error("Slave I/O thread failed to write a Rotate event"
- " to the relay log, "
- "SHOW SLAVE STATUS may be inaccurate");
+ mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
+ ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
+ "failed to write a Rotate event"
+ " to the relay log, SHOW SLAVE STATUS may be"
+ " inaccurate");
rli->relay_log.harvest_bytes_written(&rli->log_space_total);
if (flush_master_info(mi, 1))
sql_print_error("Failed to flush master info file");
delete ev;
}
else
- sql_print_error("Slave I/O thread failed to create a Rotate event"
- " (out of memory?), "
- "SHOW SLAVE STATUS may be inaccurate");
+ mi->report(ERROR_LEVEL, ER_SLAVE_CREATE_EVENT_FAILURE,
+ ER(ER_SLAVE_CREATE_EVENT_FAILURE),
+ "Rotate_event (out of memory?),"
+ " SHOW SLAVE STATUS may be inaccurate");
}
else
pthread_mutex_unlock(log_lock);
@@ -1147,7 +1088,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, MASTER_INFO *mi)
}
-int register_slave_on_master(MYSQL* mysql)
+int register_slave_on_master(MYSQL* mysql, MASTER_INFO *mi)
{
char buf[1024], *pos= buf;
uint report_host_len, report_user_len=0, report_password_len=0;
@@ -1177,9 +1118,11 @@ int register_slave_on_master(MYSQL* mysql)
if (simple_command(mysql, COM_REGISTER_SLAVE, (char*) buf,
(uint) (pos- buf), 0))
{
- sql_print_error("Error on COM_REGISTER_SLAVE: %d '%s'",
- mysql_errno(mysql),
- mysql_error(mysql));
+ char buf[256];
+ my_snprintf(buf, sizeof(buf),
+ "%s (Errno: %d)", mysql_error(mysql), mysql_errno(mysql));
+ mi->report(ERROR_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
+ ER(ER_SLAVE_MASTER_COM_FAILURE), "COM_REGISTER_SLAVE", buf);
DBUG_RETURN(1);
}
DBUG_RETURN(0);
@@ -1247,6 +1190,10 @@ bool show_master_info(THD* thd, MASTER_INFO* mi)
sizeof(mi->ssl_key)));
field_list.push_back(new Item_return_int("Seconds_Behind_Master", 10,
MYSQL_TYPE_LONGLONG));
+ field_list.push_back(new Item_return_int("Last_IO_Errno", 4, MYSQL_TYPE_LONG));
+ field_list.push_back(new Item_empty_string("Last_IO_Error", 20));
+ field_list.push_back(new Item_return_int("Last_SQL_Errno", 4, MYSQL_TYPE_LONG));
+ field_list.push_back(new Item_empty_string("Last_SQL_Error", 20));
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
@@ -1295,8 +1242,8 @@ bool show_master_info(THD* thd, MASTER_INFO* mi)
rpl_filter->get_wild_ignore_table(&tmp);
protocol->store(&tmp);
- protocol->store((uint32) mi->rli.last_slave_errno);
- protocol->store(mi->rli.last_slave_error, &my_charset_bin);
+ protocol->store(mi->rli.last_error.number);
+ protocol->store(mi->rli.last_error.message, &my_charset_bin);
protocol->store((uint32) mi->rli.slave_skip_counter);
protocol->store((ulonglong) mi->rli.group_master_log_pos);
protocol->store((ulonglong) mi->rli.log_space_total);
@@ -1355,6 +1302,15 @@ bool show_master_info(THD* thd, MASTER_INFO* mi)
else
protocol->store_null();
+ // Last_IO_Errno
+ protocol->store(mi->last_error.number);
+ // Last_IO_Error
+ protocol->store(mi->last_error.message, &my_charset_bin);
+ // Last_SQL_Errno
+ protocol->store(mi->rli.last_error.number);
+ // Last_SQL_Error
+ protocol->store(mi->rli.last_error.message, &my_charset_bin);
+
pthread_mutex_unlock(&mi->rli.data_lock);
pthread_mutex_unlock(&mi->data_lock);
@@ -1876,7 +1832,8 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli)
DBUG_RETURN(exec_res);
}
pthread_mutex_unlock(&rli->data_lock);
- slave_print_msg(ERROR_LEVEL, rli, 0, "\
+ rli->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_READ_FAILURE,
+ ER(ER_SLAVE_RELAY_LOG_READ_FAILURE), "\
Could not parse relay log event entry. The possible reasons are: the master's \
binary log is corrupted (you can check this by running 'mysqlbinlog' on the \
binary log), the slave's relay log is corrupted (you can check this by running \
@@ -1943,7 +1900,8 @@ pthread_handler_t handle_slave_io(void *arg)
if (!(mi->mysql = mysql = mysql_init(NULL)))
{
- sql_print_error("Slave I/O thread: error in mysql_init()");
+ mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
+ ER(ER_SLAVE_FATAL_ERROR), "error in mysql_init()");
goto err;
}
@@ -1986,7 +1944,7 @@ connected:
on with life.
*/
thd->proc_info = "Registering slave on master";
- if (register_slave_on_master(mysql) || update_slave_list(mysql, mi))
+ if (register_slave_on_master(mysql, mi) || update_slave_list(mysql, mi))
goto err;
}
@@ -2031,10 +1989,16 @@ dump");
}
thd->proc_info = "Reconnecting after a failed binlog dump request";
- if (!suppress_warnings)
- sql_print_error("Slave I/O thread: failed dump request, \
-reconnecting to try again, log '%s' at postion %s", IO_RPL_LOG_NAME,
- llstr(mi->master_log_pos,llbuff));
+ if (!suppress_warnings) {
+ char buf[256];
+ my_snprintf(buf, sizeof(buf),
+ "failed dump request, reconnecting to try again,"
+ " log '%s' at postion %s",
+ IO_RPL_LOG_NAME,
+ llstr(mi->master_log_pos,llbuff));
+ mi->report(WARNING_LEVEL, ER_SLAVE_MASTER_COM_FAILURE,
+ ER(ER_SLAVE_MASTER_COM_FAILURE), "COM_BINLOG_DUMP", buf);
+ }
if (safe_reconnect(thd, mysql, mi, suppress_warnings) ||
io_slave_killed(thd,mi))
{
@@ -2123,7 +2087,9 @@ reconnect done to recover from failed read");
if (queue_event(mi,(const char*)mysql->net.read_pos + 1,
event_len))
{
- sql_print_error("Slave I/O thread could not queue event from master");
+ mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
+ ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
+ "could not queue event from master");
goto err;
}
if (flush_master_info(mi, 1))
@@ -2287,7 +2253,7 @@ pthread_handler_t handle_slave_sql(void *arg)
now.
But the master timestamp is reset by RESET SLAVE & CHANGE MASTER.
*/
- rli->clear_slave_error();
+ rli->clear_error();
//tell the I/O thread to take relay_log_space_limit into account from now on
pthread_mutex_lock(&rli->log_space_lock);
@@ -2366,23 +2332,24 @@ Slave SQL thread aborted. Can't execute init_slave query");
if (!sql_slave_killed(thd,rli))
{
/*
- retrieve as much info as possible from the thd and, error codes and warnings
- and print this to the error log as to allow the user to locate the error
+ retrieve as much info as possible from the thd and, error
+ codes and warnings and print this to the error log as to
+ allow the user to locate the error
*/
+ uint32 const last_errno= rli->last_error.number;
+
if (thd->net.last_errno != 0)
{
- if (rli->last_slave_errno == 0)
+ char const *const errmsg=
+ thd->net.last_error ? thd->net.last_error : "<no message>";
+ if (last_errno == 0)
{
- slave_print_msg(ERROR_LEVEL, rli, thd->net.last_errno,
- thd->net.last_error ?
- thd->net.last_error : "<no message>");
+ rli->report(ERROR_LEVEL, thd->net.last_errno, errmsg);
}
- else if (rli->last_slave_errno != (int) thd->net.last_errno)
+ else if (last_errno != thd->net.last_errno)
{
sql_print_error("Slave (additional info): %s Error_code: %d",
- thd->net.last_error ?
- thd->net.last_error : "<no message>",
- thd->net.last_errno);
+ errmsg, thd->net.last_errno);
}
}
@@ -2530,8 +2497,9 @@ static int process_io_create_file(MASTER_INFO* mi, Create_file_log_event* cev)
xev.log_pos = cev->log_pos;
if (unlikely(mi->rli.relay_log.append(&xev)))
{
- sql_print_error("Slave I/O: error writing Exec_load event to \
-relay log");
+ mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
+ ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
+ "error writing Exec_load event to relay log");
goto err;
}
mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total);
@@ -2543,8 +2511,9 @@ relay log");
cev->block_len = num_bytes;
if (unlikely(mi->rli.relay_log.append(cev)))
{
- sql_print_error("Slave I/O: error writing Create_file event to \
-relay log");
+ mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
+ ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
+ "error writing Create_file event to relay log");
goto err;
}
cev_not_written=0;
@@ -2557,8 +2526,9 @@ relay log");
aev.log_pos = cev->log_pos;
if (unlikely(mi->rli.relay_log.append(&aev)))
{
- sql_print_error("Slave I/O: error writing Append_block event to \
-relay log");
+ mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
+ ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
+ "error writing Append_block event to relay log");
goto err;
}
mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total) ;
@@ -2659,7 +2629,8 @@ static int queue_binlog_ver_1_event(MASTER_INFO *mi, const char *buf,
{
if (unlikely(!(tmp_buf=(char*)my_malloc(event_len+1,MYF(MY_WME)))))
{
- sql_print_error("Slave I/O: out of memory for Load event");
+ mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
+ ER(ER_SLAVE_FATAL_ERROR), "Memory allocation failed");
DBUG_RETURN(1);
}
memcpy(tmp_buf,buf,event_len);
@@ -3107,14 +3078,12 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
{
last_errno=mysql_errno(mysql);
suppress_warnings= 0;
- sql_print_error("Slave I/O thread: error %s to master "
- "'%s@%s:%d': \
-Error: '%s' errno: %d retry-time: %d retries: %lu",
- (reconnect ? "reconnecting" : "connecting"),
- mi->user, mi->host, mi->port,
- mysql_error(mysql), last_errno,
- mi->connect_retry,
- master_retry_count);
+ mi->report(ERROR_LEVEL, last_errno,
+ "error %s to master '%s@%s:%d'"
+ " - retry-time: %d retries: %lu",
+ (reconnect ? "reconnecting" : "connecting"),
+ mi->user, mi->host, mi->port,
+ mi->connect_retry, master_retry_count);
}
/*
By default we try forever. The reason is that failure will trigger