mirror of
https://github.com/MariaDB/server.git
synced 2025-01-27 01:04:19 +01:00
fix the code style for read_binlog_speed_limit
This commit is contained in:
parent
ef77847ccf
commit
c334f4fe46
4 changed files with 66 additions and 97 deletions
|
@ -939,7 +939,6 @@ void my_time_init(void);
|
|||
extern my_hrtime_t my_hrtime(void);
|
||||
extern ulonglong my_interval_timer(void);
|
||||
extern ulonglong my_getcputime(void);
|
||||
extern ulonglong my_micro_time();
|
||||
|
||||
#define microsecond_interval_timer() (my_interval_timer()/1000)
|
||||
#define hrtime_to_time(X) ((X).val/HRTIME_RESOLUTION)
|
||||
|
|
|
@ -131,34 +131,3 @@ ulonglong my_getcputime()
|
|||
#endif /* CLOCK_THREAD_CPUTIME_ID */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Return time in microseconds.
|
||||
|
||||
@remark This function is to be used to measure performance in
|
||||
micro seconds. As it's not defined whats the start time
|
||||
for the clock, this function us only useful to measure
|
||||
time between two moments.
|
||||
|
||||
@retval Value in microseconds from some undefined point in time.
|
||||
*/
|
||||
|
||||
ulonglong my_micro_time()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
ulonglong newtime;
|
||||
GetSystemTimeAsFileTime((FILETIME*)&newtime);
|
||||
newtime-= OFFSET_TO_EPOC;
|
||||
return (newtime/10);
|
||||
#else
|
||||
ulonglong newtime;
|
||||
struct timeval t;
|
||||
/*
|
||||
The following loop is here because gettimeofday may fail on some systems
|
||||
*/
|
||||
while (gettimeofday(&t, NULL) != 0)
|
||||
{}
|
||||
newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec;
|
||||
return newtime;
|
||||
#endif
|
||||
}
|
||||
|
|
113
sql/net_serv.cc
113
sql/net_serv.cc
|
@ -1155,16 +1155,17 @@ my_net_read_packet(NET *net, my_bool read_from_server)
|
|||
size_t total_length= 0;
|
||||
do
|
||||
{
|
||||
net->where_b += len;
|
||||
total_length += len;
|
||||
len = my_real_read(net,&complen, 0);
|
||||
net->where_b += len;
|
||||
total_length += len;
|
||||
len = my_real_read(net,&complen, 0);
|
||||
} while (len == MAX_PACKET_LENGTH);
|
||||
if (len != packet_error)
|
||||
len+= total_length;
|
||||
len+= total_length;
|
||||
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;
|
||||
}
|
||||
|
@ -1185,7 +1186,7 @@ my_net_read_packet(NET *net, my_bool read_from_server)
|
|||
{
|
||||
buf_length= net->buf_length; /* Data left in old packet */
|
||||
first_packet_offset= start_of_packet= (net->buf_length -
|
||||
net->remain_in_buf);
|
||||
net->remain_in_buf);
|
||||
/* Restore the character that was overwritten by the end 0 */
|
||||
net->buff[start_of_packet]= net->save_char;
|
||||
}
|
||||
|
@ -1200,72 +1201,72 @@ my_net_read_packet(NET *net, my_bool read_from_server)
|
|||
|
||||
if (buf_length - start_of_packet >= NET_HEADER_SIZE)
|
||||
{
|
||||
read_length = uint3korr(net->buff+start_of_packet);
|
||||
if (!read_length)
|
||||
{
|
||||
/* End of multi-byte packet */
|
||||
start_of_packet += NET_HEADER_SIZE;
|
||||
break;
|
||||
}
|
||||
if (read_length + NET_HEADER_SIZE <= buf_length - start_of_packet)
|
||||
{
|
||||
if (multi_byte_packet)
|
||||
{
|
||||
/* Remove packet header for second packet */
|
||||
memmove(net->buff + first_packet_offset + start_of_packet,
|
||||
net->buff + first_packet_offset + start_of_packet +
|
||||
NET_HEADER_SIZE,
|
||||
buf_length - start_of_packet);
|
||||
start_of_packet += read_length;
|
||||
buf_length -= NET_HEADER_SIZE;
|
||||
}
|
||||
else
|
||||
start_of_packet+= read_length + NET_HEADER_SIZE;
|
||||
read_length = uint3korr(net->buff+start_of_packet);
|
||||
if (!read_length)
|
||||
{
|
||||
/* End of multi-byte packet */
|
||||
start_of_packet += NET_HEADER_SIZE;
|
||||
break;
|
||||
}
|
||||
if (read_length + NET_HEADER_SIZE <= buf_length - start_of_packet)
|
||||
{
|
||||
if (multi_byte_packet)
|
||||
{
|
||||
/* Remove packet header for second packet */
|
||||
memmove(net->buff + first_packet_offset + start_of_packet,
|
||||
net->buff + first_packet_offset + start_of_packet +
|
||||
NET_HEADER_SIZE,
|
||||
buf_length - start_of_packet);
|
||||
start_of_packet += read_length;
|
||||
buf_length -= NET_HEADER_SIZE;
|
||||
}
|
||||
else
|
||||
start_of_packet+= read_length + NET_HEADER_SIZE;
|
||||
|
||||
if (read_length != MAX_PACKET_LENGTH) /* last package */
|
||||
{
|
||||
multi_byte_packet= 0; /* No last zero len packet */
|
||||
break;
|
||||
}
|
||||
multi_byte_packet= NET_HEADER_SIZE;
|
||||
/* Move data down to read next data packet after current one */
|
||||
if (first_packet_offset)
|
||||
{
|
||||
memmove(net->buff,net->buff+first_packet_offset,
|
||||
buf_length-first_packet_offset);
|
||||
buf_length-=first_packet_offset;
|
||||
start_of_packet -= first_packet_offset;
|
||||
first_packet_offset=0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (read_length != MAX_PACKET_LENGTH) /* last package */
|
||||
{
|
||||
multi_byte_packet= 0; /* No last zero len packet */
|
||||
break;
|
||||
}
|
||||
multi_byte_packet= NET_HEADER_SIZE;
|
||||
/* Move data down to read next data packet after current one */
|
||||
if (first_packet_offset)
|
||||
{
|
||||
memmove(net->buff,net->buff+first_packet_offset,
|
||||
buf_length-first_packet_offset);
|
||||
buf_length-=first_packet_offset;
|
||||
start_of_packet -= first_packet_offset;
|
||||
first_packet_offset=0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* Move data down to read next data packet after current one */
|
||||
if (first_packet_offset)
|
||||
{
|
||||
memmove(net->buff,net->buff+first_packet_offset,
|
||||
buf_length-first_packet_offset);
|
||||
buf_length-=first_packet_offset;
|
||||
start_of_packet -= first_packet_offset;
|
||||
first_packet_offset=0;
|
||||
memmove(net->buff,net->buff+first_packet_offset,
|
||||
buf_length-first_packet_offset);
|
||||
buf_length-=first_packet_offset;
|
||||
start_of_packet -= first_packet_offset;
|
||||
first_packet_offset=0;
|
||||
}
|
||||
|
||||
net->where_b=buf_length;
|
||||
if ((packet_len = my_real_read(net,&complen, read_from_server))
|
||||
== packet_error)
|
||||
== packet_error)
|
||||
{
|
||||
MYSQL_NET_READ_DONE(1, 0);
|
||||
return packet_error;
|
||||
return packet_error;
|
||||
}
|
||||
read_from_server= 0;
|
||||
if (my_uncompress(net->buff + net->where_b, packet_len,
|
||||
&complen))
|
||||
&complen))
|
||||
{
|
||||
net->error= 2; /* caller will close socket */
|
||||
net->error= 2; /* caller will close socket */
|
||||
net->last_errno= ER_NET_UNCOMPRESS_ERROR;
|
||||
MYSQL_SERVER_my_error(ER_NET_UNCOMPRESS_ERROR, MYF(0));
|
||||
MYSQL_SERVER_my_error(ER_NET_UNCOMPRESS_ERROR, MYF(0));
|
||||
MYSQL_NET_READ_DONE(1, 0);
|
||||
return packet_error;
|
||||
return packet_error;
|
||||
}
|
||||
buf_length+= complen;
|
||||
net->real_network_read_len += packet_len;
|
||||
|
@ -1275,7 +1276,7 @@ my_net_read_packet(NET *net, my_bool read_from_server)
|
|||
net->buf_length= buf_length;
|
||||
net->remain_in_buf= (ulong) (buf_length - start_of_packet);
|
||||
len = ((ulong) (start_of_packet - first_packet_offset) - NET_HEADER_SIZE -
|
||||
multi_byte_packet);
|
||||
multi_byte_packet);
|
||||
net->save_char= net->read_pos[len]; /* Must be saved */
|
||||
net->read_pos[len]=0; /* Safeguard for mysql_use_result */
|
||||
}
|
||||
|
|
18
sql/slave.cc
18
sql/slave.cc
|
@ -4419,7 +4419,7 @@ connected:
|
|||
|
||||
mi->slave_running= MYSQL_SLAVE_RUN_READING;
|
||||
DBUG_ASSERT(mi->last_error().number == 0);
|
||||
ulonglong lastchecktime = my_micro_time()/1000;
|
||||
ulonglong lastchecktime = my_hrtime().val;
|
||||
ulonglong tokenamount = opt_read_binlog_speed_limit*1024;
|
||||
while (!io_slave_killed(mi))
|
||||
{
|
||||
|
@ -4481,24 +4481,24 @@ Stopping slave I/O thread due to out-of-memory error from master");
|
|||
|
||||
/* Control the binlog read speed of master when read_binlog_speed_limit is non-zero
|
||||
*/
|
||||
ulonglong read_binlog_speed_limit = opt_read_binlog_speed_limit;
|
||||
if (read_binlog_speed_limit) {
|
||||
ulonglong read_binlog_speed_limit_in_bytes = opt_read_binlog_speed_limit * 1024;
|
||||
if (read_binlog_speed_limit_in_bytes) {
|
||||
/* prevent the tokenamount become a large value,
|
||||
for example, the IO thread doesn't work for a long time
|
||||
*/
|
||||
if (tokenamount > read_binlog_speed_limit * 1024 *2)
|
||||
if (tokenamount > read_binlog_speed_limit_in_bytes * 2)
|
||||
{
|
||||
lastchecktime = my_micro_time()/1000;
|
||||
tokenamount = read_binlog_speed_limit * 1024 *2;
|
||||
lastchecktime = my_hrtime().val;
|
||||
tokenamount = read_binlog_speed_limit_in_bytes * 2;
|
||||
}
|
||||
|
||||
do{
|
||||
ulonglong currenttime = my_micro_time()/1000;
|
||||
tokenamount += (currenttime - lastchecktime)*read_binlog_speed_limit*1024/1000;
|
||||
ulonglong currenttime = my_hrtime().val;
|
||||
tokenamount += (currenttime - lastchecktime)*read_binlog_speed_limit_in_bytes/(1000*1000);
|
||||
lastchecktime = currenttime;
|
||||
if(tokenamount < network_read_len)
|
||||
{
|
||||
ulonglong micro_sleeptime = 1000*1000*(network_read_len - tokenamount) / (read_binlog_speed_limit * 1024);
|
||||
ulonglong micro_sleeptime = 1000*1000*(network_read_len - tokenamount) / read_binlog_speed_limit_in_bytes ;
|
||||
my_sleep(micro_sleeptime > 1000 ? micro_sleeptime : 1000); // at least sleep 1000 micro second
|
||||
}
|
||||
}while(tokenamount < network_read_len);
|
||||
|
|
Loading…
Add table
Reference in a new issue