mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
BUG#16438800 - SLAVE_MAX_ALLOWED_PACKET NOT HONORED ON SLAVE IO CONNECT
Problem - When the slave was disconnected from the master, under certain conditions, upon reconnect, it will report that it received a packet larger the slave_max_allowed_packet which causes the replication to stop. Analysis -The reason of this failure is that on reconnect the slave sets the max_allowed_packet from the master's mi->mysql object which keeps the max_allowed_packet as 1MB. This causes the slave to report such error on recieving packet bigger than 1MB. START SLAVE on the slave fixes the problem since it restarts slave threads which initializes the max_allowed_packet to slave_max_allowed_packet. Fix - The problem is fixed by some code refactoring and introduction of a new function which updates the max_allowed_packet for the THD object of the slave thread and the mysql->options max_allowed_packet.
This commit is contained in:
parent
6a9f12fda8
commit
142fbb9eaa
1 changed files with 32 additions and 14 deletions
46
sql/slave.cc
46
sql/slave.cc
|
@ -158,6 +158,37 @@ static int terminate_slave_thread(THD *thd,
|
|||
volatile uint *slave_running,
|
||||
bool skip_lock);
|
||||
static bool check_io_slave_killed(THD *thd, Master_info *mi, const char *info);
|
||||
/*
|
||||
Function to set the slave's max_allowed_packet based on the value
|
||||
of slave_max_allowed_packet.
|
||||
|
||||
@in_param thd Thread handler for slave
|
||||
@in_param mysql MySQL connection handle
|
||||
*/
|
||||
|
||||
static void set_slave_max_allowed_packet(THD *thd, MYSQL *mysql)
|
||||
{
|
||||
DBUG_ENTER("set_slave_max_allowed_packet");
|
||||
// thd and mysql must be valid
|
||||
DBUG_ASSERT(thd && mysql);
|
||||
|
||||
thd->variables.max_allowed_packet= slave_max_allowed_packet;
|
||||
thd->net.max_packet_size= slave_max_allowed_packet;
|
||||
/*
|
||||
Adding MAX_LOG_EVENT_HEADER_LEN to the max_packet_size on the I/O
|
||||
thread and the mysql->option max_allowed_packet, since a
|
||||
replication event can become this much larger than
|
||||
the corresponding packet (query) sent from client to master.
|
||||
*/
|
||||
thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER;
|
||||
/*
|
||||
Skipping the setting of mysql->net.max_packet size to slave
|
||||
max_allowed_packet since this is done during mysql_real_connect.
|
||||
*/
|
||||
mysql->options.max_allowed_packet=
|
||||
slave_max_allowed_packet+MAX_LOG_EVENT_HEADER;
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
/*
|
||||
Find out which replications threads are running
|
||||
|
@ -2072,12 +2103,6 @@ static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type)
|
|||
SYSTEM_THREAD_SLAVE_SQL : SYSTEM_THREAD_SLAVE_IO;
|
||||
thd->security_ctx->skip_grants();
|
||||
my_net_init(&thd->net, 0);
|
||||
/*
|
||||
Adding MAX_LOG_EVENT_HEADER_LEN to the max_allowed_packet on all
|
||||
slave threads, since a replication event can become this much larger
|
||||
than the corresponding packet (query) sent from client to master.
|
||||
*/
|
||||
thd->variables.max_allowed_packet= slave_max_allowed_packet;
|
||||
thd->slave_thread = 1;
|
||||
thd->enable_slow_log= opt_log_slow_slave_statements;
|
||||
set_slave_thread_options(thd);
|
||||
|
@ -2828,13 +2853,6 @@ pthread_handler_t handle_slave_io(void *arg)
|
|||
mi->user, mi->host, mi->port,
|
||||
IO_RPL_LOG_NAME,
|
||||
llstr(mi->master_log_pos,llbuff));
|
||||
/*
|
||||
Adding MAX_LOG_EVENT_HEADER_LEN to the max_packet_size on the I/O
|
||||
thread, since a replication event can become this much larger than
|
||||
the corresponding packet (query) sent from client to master.
|
||||
*/
|
||||
thd->net.max_packet_size= slave_max_allowed_packet;
|
||||
mysql->net.max_packet_size= thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4231,7 +4249,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
|
|||
ulong err_count=0;
|
||||
char llbuff[22];
|
||||
DBUG_ENTER("connect_to_master");
|
||||
|
||||
set_slave_max_allowed_packet(thd, mysql);
|
||||
#ifndef DBUG_OFF
|
||||
mi->events_till_disconnect = disconnect_slave_event_count;
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue