Skip to content

Commit 65501b5

Browse files
committed
Disable unique checks when replica is lagging
Summary: temporarily disables unique check in replica when lag exceeds configured threshold Test Plan: rocksdb_rpl.rpl_no_unique_check_on_lag, rocksdb_rpl.rpl_no_unique_check_on_lag_mts Reviewers: yoshinorim, tengli, santoshb Reviewed By: santoshb Subscribers: vasilep, webscalesql-eng Differential Revision: https://reviews.facebook.net/D58935
1 parent 7ea8c95 commit 65501b5

26 files changed

+608
-4
lines changed

mysql-test/r/mysqld--help-notwin-profiling.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,13 @@ The following options may be given as the first argument:
14701470
--transaction-read-only
14711471
Default transaction access mode. True if transactions are
14721472
read-only.
1473+
--unique-check-lag-reset-threshold=#
1474+
Stop enabling skip_unique_check when lag drops below this
1475+
threshold.
1476+
--unique-check-lag-threshold=#
1477+
Automatically enable skip_unique_check when lag exceeds
1478+
this threshold (0 [default] to disable, only affects
1479+
RocksDB).
14731480
--updatable-views-with-limit=name
14741481
YES = Don't issue an error message (warning only) if a
14751482
VIEW without presence of a key of the underlying table is
@@ -1954,6 +1961,8 @@ transaction-alloc-block-size 8192
19541961
transaction-isolation REPEATABLE-READ
19551962
transaction-prealloc-size 4096
19561963
transaction-read-only FALSE
1964+
unique-check-lag-reset-threshold 2
1965+
unique-check-lag-threshold 0
19571966
updatable-views-with-limit YES
19581967
use-db-uuid FALSE
19591968
use-fbson-input-format FALSE

mysql-test/r/mysqld--help-notwin.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,13 @@ The following options may be given as the first argument:
14681468
--transaction-read-only
14691469
Default transaction access mode. True if transactions are
14701470
read-only.
1471+
--unique-check-lag-reset-threshold=#
1472+
Stop enabling skip_unique_check when lag drops below this
1473+
threshold.
1474+
--unique-check-lag-threshold=#
1475+
Automatically enable skip_unique_check when lag exceeds
1476+
this threshold (0 [default] to disable, only affects
1477+
RocksDB).
14711478
--updatable-views-with-limit=name
14721479
YES = Don't issue an error message (warning only) if a
14731480
VIEW without presence of a key of the underlying table is
@@ -1951,6 +1958,8 @@ transaction-alloc-block-size 8192
19511958
transaction-isolation REPEATABLE-READ
19521959
transaction-prealloc-size 4096
19531960
transaction-read-only FALSE
1961+
unique-check-lag-reset-threshold 2
1962+
unique-check-lag-threshold 0
19541963
updatable-views-with-limit YES
19551964
use-db-uuid FALSE
19561965
use-fbson-input-format FALSE
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--source include/master-slave.inc
2+
--source include/not_embedded.inc
3+
4+
call mtr.add_suppression("Slave SQL: Could not execute Write_rows event on table test.t1");
5+
call mtr.add_suppression(".*Worker.*failed executing transaction");
6+
call mtr.add_suppression(".*The slave coordinator and worker threads are stopped");
7+
8+
--disable_warnings
9+
drop table if exists t1;
10+
--enable_warnings
11+
12+
connection master;
13+
CREATE TABLE t1 (id int primary key, value int) engine=RocksDB;
14+
sync_slave_with_master;
15+
--let $rsbm = query_get_value(select @@global.reset_seconds_behind_master, @@global.reset_seconds_behind_master, 1)
16+
set global reset_seconds_behind_master=1;
17+
18+
connection slave;
19+
INSERT INTO t1 VALUES(1, 0);
20+
INSERT INTO t1 VALUES(2, 0);
21+
INSERT INTO t1 VALUES(3, 0);
22+
23+
set global reset_seconds_behind_master=0;
24+
25+
connection master;
26+
INSERT INTO t1 VALUES(1, 1);
27+
28+
connection slave;
29+
--let $slave_sql_errno= 1062
30+
--let $not_switch_connection= 0
31+
--source include/wait_for_slave_sql_error_and_skip.inc
32+
--source include/stop_slave_io.inc
33+
34+
connection master;
35+
insert into t1 values (4,0);
36+
--sleep 11
37+
38+
connection slave;
39+
--source include/start_slave_io.inc
40+
41+
connection master;
42+
sync_slave_with_master;
43+
44+
connection master;
45+
INSERT INTO t1 VALUES(2, 1);
46+
sync_slave_with_master;
47+
48+
set global reset_seconds_behind_master=1;
49+
50+
connection master;
51+
insert into t1 values (5,0);
52+
--sleep 1
53+
sync_slave_with_master;
54+
55+
connection master;
56+
INSERT INTO t1 VALUES(3, 1);
57+
58+
connection slave;
59+
--let $slave_sql_errno= 1062
60+
--let $not_switch_connection= 0
61+
--source include/wait_for_slave_sql_error_and_skip.inc
62+
63+
--echo #
64+
--echo # Cleanup
65+
--echo #
66+
67+
connection master;
68+
set global rocksdb_skip_unique_check = 0;
69+
DROP TABLE t1;
70+
eval set global reset_seconds_behind_master=$rsbm;
71+
--source include/rpl_end.inc
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Ensure skip_unique_check is set when lag exceeds lag_threshold
3+
#
4+
include/master-slave.inc
5+
Warnings:
6+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
7+
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.
8+
[connection master]
9+
call mtr.add_suppression("Slave SQL: Could not execute Write_rows event on table test.t1");
10+
call mtr.add_suppression(".*Worker.*failed executing transaction");
11+
call mtr.add_suppression(".*The slave coordinator and worker threads are stopped");
12+
drop table if exists t1;
13+
CREATE TABLE t1 (id int primary key, value int) engine=RocksDB;
14+
set global reset_seconds_behind_master=1;
15+
INSERT INTO t1 VALUES(1, 0);
16+
INSERT INTO t1 VALUES(2, 0);
17+
INSERT INTO t1 VALUES(3, 0);
18+
set global reset_seconds_behind_master=0;
19+
INSERT INTO t1 VALUES(1, 1);
20+
include/wait_for_slave_sql_error_and_skip.inc [errno=1062]
21+
include/stop_slave_io.inc
22+
insert into t1 values (4,0);
23+
include/start_slave_io.inc
24+
INSERT INTO t1 VALUES(2, 1);
25+
set global reset_seconds_behind_master=1;
26+
insert into t1 values (5,0);
27+
INSERT INTO t1 VALUES(3, 1);
28+
include/wait_for_slave_sql_error_and_skip.inc [errno=1062]
29+
#
30+
# Cleanup
31+
#
32+
set global rocksdb_skip_unique_check = 0;
33+
DROP TABLE t1;
34+
set global reset_seconds_behind_master=1;
35+
include/rpl_end.inc
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
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.
5+
[connection master]
6+
call mtr.add_suppression("Slave SQL: Could not execute Write_rows event on table test.t1");
7+
call mtr.add_suppression(".*Worker.*failed executing transaction");
8+
call mtr.add_suppression(".*The slave coordinator and worker threads are stopped");
9+
drop table if exists t1;
10+
CREATE TABLE t1 (id int primary key, value int) engine=RocksDB;
11+
set global reset_seconds_behind_master=1;
12+
INSERT INTO t1 VALUES(1, 0);
13+
INSERT INTO t1 VALUES(2, 0);
14+
INSERT INTO t1 VALUES(3, 0);
15+
set global reset_seconds_behind_master=0;
16+
INSERT INTO t1 VALUES(1, 1);
17+
include/wait_for_slave_sql_error_and_skip.inc [errno=1062]
18+
include/stop_slave_io.inc
19+
insert into t1 values (4,0);
20+
include/start_slave_io.inc
21+
INSERT INTO t1 VALUES(2, 1);
22+
set global reset_seconds_behind_master=1;
23+
insert into t1 values (5,0);
24+
INSERT INTO t1 VALUES(3, 1);
25+
include/wait_for_slave_sql_error_and_skip.inc [errno=1062]
26+
#
27+
# Cleanup
28+
#
29+
set global rocksdb_skip_unique_check = 0;
30+
DROP TABLE t1;
31+
set global reset_seconds_behind_master=1;
32+
include/rpl_end.inc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--unique-check-lag-threshold=5
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--echo #
2+
--echo # Ensure skip_unique_check is set when lag exceeds lag_threshold
3+
--echo #
4+
5+
--source ../include/rpl_no_unique_check_on_lag.inc
6+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--unique-check-lag-threshold=5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--source ../include/rpl_no_unique_check_on_lag.inc
2+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
SET @start_value = @@global.unique_check_lag_reset_threshold;
2+
SELECT @start_value;
3+
@start_value
4+
2
5+
SET @@global.unique_check_lag_reset_threshold = DEFAULT;
6+
SELECT @@global.unique_check_lag_reset_threshold = 2;
7+
@@global.unique_check_lag_reset_threshold = 2
8+
1
9+
SET @@global.unique_check_lag_reset_threshold = 42;
10+
SELECT @@global.unique_check_lag_reset_threshold;
11+
@@global.unique_check_lag_reset_threshold
12+
42
13+
SET @@global.unique_check_lag_reset_threshold = 0;
14+
Warnings:
15+
Warning 1292 Truncated incorrect unique_check_lag_reset_threshold value: '0'
16+
SELECT @@global.unique_check_lag_reset_threshold;
17+
@@global.unique_check_lag_reset_threshold
18+
1
19+
SET @@global.unique_check_lag_reset_threshold = ON;
20+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
21+
SET @@global.unique_check_lag_reset_threshold = TRUEF;
22+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
23+
SET @@global.unique_check_lag_reset_threshold = TRUE_F;
24+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
25+
SET @@global.unique_check_lag_reset_threshold = FALSE0;
26+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
27+
SET @@global.unique_check_lag_reset_threshold = OON;
28+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
29+
SET @@global.unique_check_lag_reset_threshold = ONN;
30+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
31+
SET @@global.unique_check_lag_reset_threshold = OOFF;
32+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
33+
SET @@global.unique_check_lag_reset_threshold = 0FF;
34+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
35+
SET @@global.unique_check_lag_reset_threshold = ' ';
36+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
37+
SET @@global.unique_check_lag_reset_threshold = " ";
38+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
39+
SET @@global.unique_check_lag_reset_threshold = '';
40+
ERROR 42000: Incorrect argument type to variable 'unique_check_lag_reset_threshold'
41+
SET @@session.unique_check_lag_reset_threshold = 0;
42+
ERROR HY000: Variable 'unique_check_lag_reset_threshold' is a GLOBAL variable and should be set with SET GLOBAL
43+
SELECT @@session.unique_check_lag_reset_threshold;
44+
ERROR HY000: Variable 'unique_check_lag_reset_threshold' is a GLOBAL variable
45+
SELECT *
46+
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
47+
WHERE VARIABLE_NAME='unique_check_lag_reset_threshold';
48+
VARIABLE_NAME VARIABLE_VALUE
49+
UNIQUE_CHECK_LAG_RESET_THRESHOLD 1
50+
SET @@global.unique_check_lag_reset_threshold = 1;
51+
SELECT @@unique_check_lag_reset_threshold = @@global.reset_seconds_behind_master;
52+
@@unique_check_lag_reset_threshold = @@global.reset_seconds_behind_master
53+
1
54+
SET unique_check_lag_reset_threshold = 1;
55+
ERROR HY000: Variable 'unique_check_lag_reset_threshold' is a GLOBAL variable and should be set with SET GLOBAL
56+
SET local.unique_check_lag_reset_threshold = 0;
57+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unique_check_lag_reset_threshold = 0' at line 1
58+
SELECT local.unique_check_lag_reset_threshold;
59+
ERROR 42S02: Unknown table 'local' in field list
60+
SET global.unique_check_lag_reset_threshold = 1;
61+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unique_check_lag_reset_threshold = 1' at line 1
62+
SELECT global.unique_check_lag_reset_threshold;
63+
ERROR 42S02: Unknown table 'global' in field list
64+
SELECT unique_check_lag_reset_threshold = @@session.reset_seconds_behind_master;
65+
ERROR 42S22: Unknown column 'unique_check_lag_reset_threshold' in 'field list'
66+
SET @@global.unique_check_lag_reset_threshold = @start_value;
67+
SELECT @@global.unique_check_lag_reset_threshold;
68+
@@global.unique_check_lag_reset_threshold
69+
2

0 commit comments

Comments
 (0)