Skip to content

Commit

Permalink
check for sql_bin_log = 0 with write throttling
Browse files Browse the repository at this point in the history
Summary:
Adds extra check to ensure writes aren't throttled if sql_bin_log = 0.

See T90163290

Reviewed By: satya-valluri

Differential Revision: D28712613

fbshipit-source-id: a773d7d3e1b
  • Loading branch information
Nicholas Meisburger authored and inikep committed Oct 22, 2021
1 parent 0cc6fc6 commit 040b87a
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 1 deletion.
77 changes: 77 additions & 0 deletions mysql-test/r/sql_bin_log0.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
include/master-slave.inc
Warnings:
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
[connection master]
create table test(a int, b int, c int) engine=innodb;
Set CPU limit for milliseconds to 1
set @@GLOBAL.write_cpu_limit_milliseconds=1;
connect to master
setting dbug.force_long_running_query which will
make the query long running after processing number
of rows determined by write_time_check_batch
set @@global.debug= '+d,dbug.force_long_running_query';
Set the batch size for checking CPU time to 3
set @@GLOBAL.write_time_check_batch=3;
Test 1.1: Long running query to force throttling level=NOTE
set @@GLOBAL.write_control_level=NOTE;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
this query raises warning
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);
show warnings;
Level Code Message
Note 50091 Write CPU time exceeded (controlled by write_cpu_limit_milliseconds)
Test 1.2: Long running query to force throttling level=WARN
set @@GLOBAL.write_control_level=WARN;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
this query raises warning
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);
show warnings;
Level Code Message
Warning 50091 Write CPU time exceeded (controlled by write_cpu_limit_milliseconds)
Test 1.3: Long running query to force throttling level=ERROR
set @@GLOBAL.write_control_level=ERROR;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
this query raises error
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);
ERROR HY000: Write CPU time exceeded (controlled by write_cpu_limit_milliseconds)
show errors;
Level Code Message
Error 50091 Write CPU time exceeded (controlled by write_cpu_limit_milliseconds)
Set sql_log_bin to 0
set sql_log_bin=0;
Test 2.1: Repeat query with sql_log_bin = 0 level=NOTE
set @@GLOBAL.write_control_level=NOTE;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
this query should not raise warning
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);
show warnings;
Level Code Message
Test 2.2: Repeat query with sql_log_bin = 0 level=WARN
set @@GLOBAL.write_control_level=WARN;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
this query should not raise warning
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);
show warnings;
Level Code Message
Test 2.3: Repeat query with sql_log_bin = 0 level=ERROR
set @@GLOBAL.write_control_level=ERROR;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
this query should not raise error
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);
show errors;
Level Code Message
Finished tests begining cleanup
set @@GLOBAL.write_control_level=OFF;
set @@GLOBAL.write_cpu_limit_milliseconds=0;
set @@GLOBAL.write_time_check_batch=0;
set @@global.debug= '-d,dbug.force_long_running_query';
set sql_log_bin=1;
drop table test;
include/rpl_end.inc
115 changes: 115 additions & 0 deletions mysql-test/t/sql_bin_log0.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
source include/master-slave.inc;
source include/have_binlog_format_row.inc;
source include/have_debug_sync.inc;

--disable_warnings

####################################################
### Tests no throttling with sql_log_bin = 0
####################################################

### Setup
connection master;

create table test(a int, b int, c int) engine=innodb;

--echo Set CPU limit for milliseconds to 1
set @@GLOBAL.write_cpu_limit_milliseconds=1;

--echo connect to master
connection master;

--echo setting dbug.force_long_running_query which will
--echo make the query long running after processing number
--echo of rows determined by write_time_check_batch
set @@global.debug= '+d,dbug.force_long_running_query';

--echo Set the batch size for checking CPU time to 3
set @@GLOBAL.write_time_check_batch=3;

####################################################
### Test 1: Query throttling with sql_log_bin = 1
####################################################

--echo Test 1.1: Long running query to force throttling level=NOTE

set @@GLOBAL.write_control_level=NOTE;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
--echo this query raises warning
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);

show warnings;

--echo Test 1.2: Long running query to force throttling level=WARN

set @@GLOBAL.write_control_level=WARN;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
--echo this query raises warning
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);

show warnings;

--echo Test 1.3: Long running query to force throttling level=ERROR

set @@GLOBAL.write_control_level=ERROR;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
--echo this query raises error
--error ER_WARN_WRITE_EXCEEDED_CPU_LIMIT_MILLISECONDS
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);

show errors;

####################################################
### Test 1: No query throttling with sql_log_bin = 0
####################################################

--echo Set sql_log_bin to 0
set sql_log_bin=0;

--echo Test 2.1: Repeat query with sql_log_bin = 0 level=NOTE

set @@GLOBAL.write_control_level=NOTE;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
--echo this query should not raise warning
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);

show warnings;

--echo Test 2.2: Repeat query with sql_log_bin = 0 level=WARN

set @@GLOBAL.write_control_level=WARN;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
--echo this query should not raise warning
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);

show warnings;

--echo Test 2.3: Repeat query with sql_log_bin = 0 level=ERROR

set @@GLOBAL.write_control_level=ERROR;
insert into test values(1, 1, 1);
insert into test values(2, 2, 2), (3, 3, 3);
--echo this query should not raise error
insert into test values(4, 4, 4), (5, 5, 5), (6, 6, 6);

show errors;


### Clean Up
--echo Finished tests begining cleanup
connection master;

set @@GLOBAL.write_control_level=OFF;
set @@GLOBAL.write_cpu_limit_milliseconds=0;
set @@GLOBAL.write_time_check_batch=0;
set @@global.debug= '-d,dbug.force_long_running_query';
set sql_log_bin=1;
drop table test;

--source include/rpl_end.inc
--enable_warnings
4 changes: 3 additions & 1 deletion sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3808,8 +3808,10 @@ bool THD::dml_execution_cpu_limit_exceeded() {
* - write_cpu_limit_milliseconds is set to 0 or
* - write_time_check_batch is set to 0
*/

if (write_control_level == CONTROL_LEVEL_OFF ||
write_cpu_limit_milliseconds == 0 || write_time_check_batch == 0) {
write_cpu_limit_milliseconds == 0 || write_time_check_batch == 0 ||
variables.sql_log_bin == 0) {
return false;
}

Expand Down

0 comments on commit 040b87a

Please sign in to comment.