Commit 43789901 authored by vinchen's avatar vinchen Committed by Kristian Nielsen

Control the binlog read speed for compressed protocol

parent 8eb0f5ca
......@@ -424,6 +424,7 @@ typedef struct st_net {
Pointer to query object in query cache, do not equal NULL (0) for
queries in cache that have not stored its results yet
*/
unsigned long real_network_read_len; // the my_real_read length for each package
#endif
void *thd; /* Used by MariaDB server to avoid calling current_thd */
unsigned int last_errno;
......
......@@ -1142,6 +1142,7 @@ my_net_read_packet(NET *net, my_bool read_from_server)
MYSQL_NET_READ_START();
net->real_network_read_len = 0;
#ifdef HAVE_COMPRESS
if (!net->compress)
{
......@@ -1163,8 +1164,10 @@ my_net_read_packet(NET *net, my_bool read_from_server)
net->where_b = save_pos;
}
net->read_pos = net->buff + net->where_b;
if (len != packet_error)
if (len != packet_error) {
net->read_pos[len]=0; /* Safeguard for mysql_use_result */
net->real_network_read_len = len;
}
MYSQL_NET_READ_DONE(0, len);
return len;
#ifdef HAVE_COMPRESS
......@@ -1265,6 +1268,7 @@ my_net_read_packet(NET *net, my_bool read_from_server)
return packet_error;
}
buf_length+= complen;
net->real_network_read_len += packet_len;
}
net->read_pos= net->buff+ first_packet_offset + NET_HEADER_SIZE;
......
......@@ -3308,13 +3308,14 @@ static int request_dump(THD *thd, MYSQL* mysql, Master_info* mi,
try a reconnect. We do not want to print anything to
the error log in this case because this a anormal
event in an idle server.
network_read_len get the real network read length in VIO, especially using compressed protocol
RETURN VALUES
'packet_error' Error
number Length of packet
*/
static ulong read_event(MYSQL* mysql, Master_info *mi, bool* suppress_warnings)
static ulong read_event(MYSQL* mysql, Master_info *mi, bool* suppress_warnings, ulong* network_read_len)
{
ulong len;
DBUG_ENTER("read_event");
......@@ -3356,6 +3357,8 @@ static ulong read_event(MYSQL* mysql, Master_info *mi, bool* suppress_warnings)
DBUG_RETURN(packet_error);
}
*network_read_len = mysql->net.real_network_read_len ;
DBUG_PRINT("exit", ("len: %lu net->read_pos[4]: %d",
len, mysql->net.read_pos[4]));
DBUG_RETURN(len - 1);
......@@ -4420,7 +4423,7 @@ pthread_handler_t handle_slave_io(void *arg)
ulonglong tokenamount = opt_read_binlog_speed_limit*1024;
while (!io_slave_killed(mi))
{
ulong event_len;
ulong event_len, network_read_len = 0;
/*
We say "waiting" because read_event() will wait if there's nothing to
read. But if there's something to read, it will not wait. The
......@@ -4428,7 +4431,7 @@ pthread_handler_t handle_slave_io(void *arg)
we're in fact receiving nothing.
*/
THD_STAGE_INFO(thd, stage_waiting_for_master_to_send_event);
event_len= read_event(mysql, mi, &suppress_warnings);
event_len= read_event(mysql, mi, &suppress_warnings, &network_read_len);
if (check_io_slave_killed(mi, NullS))
goto err;
......@@ -4493,13 +4496,13 @@ Stopping slave I/O thread due to out-of-memory error from master");
ulonglong currenttime = my_micro_time()/1000;
tokenamount += (currenttime - lastchecktime)*read_binlog_speed_limit*1024/1000;
lastchecktime = currenttime;
if(tokenamount < event_len)
if(tokenamount < network_read_len)
{
ulonglong micro_sleeptime = 1000*1000*(event_len - tokenamount) / (read_binlog_speed_limit * 1024);
ulonglong micro_sleeptime = 1000*1000*(network_read_len - tokenamount) / (read_binlog_speed_limit * 1024);
my_sleep(micro_sleeptime > 1000 ? micro_sleeptime : 1000); // at least sleep 1000 micro second
}
}while(tokenamount < event_len);
tokenamount -= event_len;
}while(tokenamount < network_read_len);
tokenamount -= network_read_len;
}
/* XXX: 'synced' should be updated by queue_event to indicate
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment