Skip to content

Commit 5846968

Browse files
abhinav04sharmaFacebook Github Bot
authored andcommitted
Supporting dynamic scheduling in MTS
Summary: Statically assigning shards to slave workers can cause imbalance if a few shards are hotter than others. We should be able to check the imbalance among slave workers and dynamically reassign shards. Closes #398 Reviewed By: santoshbanda Differential Revision: D4134877 Pulled By: abhinav04sharma fbshipit-source-id: 0700fcd
1 parent 68a7711 commit 5846968

21 files changed

+535
-6
lines changed

mysql-test/r/information_schema-big.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ USER_PRIVILEGES GRANTEE
6161
USER_STATISTICS USER_NAME
6262
VIEWS TABLE_SCHEMA
6363
AUTHINFO ID
64+
SLAVE_DB_LOAD DB
6465
SELECT t.table_name, c1.column_name
6566
FROM information_schema.tables t
6667
INNER JOIN
@@ -119,3 +120,4 @@ USER_PRIVILEGES GRANTEE
119120
USER_STATISTICS USER_NAME
120121
VIEWS TABLE_SCHEMA
121122
AUTHINFO ID
123+
SLAVE_DB_LOAD DB

mysql-test/r/information_schema.result

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ USER_PRIVILEGES
9393
USER_STATISTICS
9494
VIEWS
9595
AUTHINFO
96+
SLAVE_DB_LOAD
9697
columns_priv
9798
db
9899
event
@@ -927,7 +928,7 @@ table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest')
927928
AND table_name not like 'ndb%' AND table_name not like 'innodb_%' AND table_name not like 'rocksdb_%'
928929
GROUP BY TABLE_SCHEMA;
929930
table_schema count(*)
930-
information_schema 40
931+
information_schema 41
931932
mysql 26
932933
create table t1 (i int, j int);
933934
create trigger trg1 before insert on t1 for each row
@@ -1395,6 +1396,7 @@ SCHEMATA information_schema.SCHEMATA 1
13951396
SCHEMA_PRIVILEGES information_schema.SCHEMA_PRIVILEGES 1
13961397
SESSION_STATUS information_schema.SESSION_STATUS 1
13971398
SESSION_VARIABLES information_schema.SESSION_VARIABLES 1
1399+
SLAVE_DB_LOAD information_schema.SLAVE_DB_LOAD 1
13981400
STATISTICS information_schema.STATISTICS 1
13991401
TABLES information_schema.TABLES 1
14001402
TABLESPACES information_schema.TABLESPACES 1

mysql-test/r/information_schema_db.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ USER_PRIVILEGES
4545
USER_STATISTICS
4646
VIEWS
4747
AUTHINFO
48+
SLAVE_DB_LOAD
4849
show tables from INFORMATION_SCHEMA like 'T%';
4950
Tables_in_information_schema (T%)
5051
TRANSACTION_LIST

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,13 @@ The following options may be given as the first argument:
579579
--min-examined-row-limit=#
580580
Don't write queries to slow log that examine fewer rows
581581
than that
582+
--mts-dynamic-rebalance
583+
Shuffle DB's within workers periodically for load
584+
balancing
585+
--mts-imbalance-threshold[=#]
586+
Threshold to trigger worker thread rebalancing. This
587+
parameter denotes the percent load on the most loaded
588+
worker.
582589
--multi-range-count=#
583590
Number of key ranges to request at once. This variable
584591
has no effect, and is deprecated. It will be removed in a
@@ -1773,6 +1780,8 @@ memlock FALSE
17731780
metadata-locks-cache-size 1024
17741781
metadata-locks-hash-instances 256
17751782
min-examined-row-limit 0
1783+
mts-dynamic-rebalance FALSE
1784+
mts-imbalance-threshold 90
17761785
multi-range-count 256
17771786
myisam-block-size 1024
17781787
myisam-data-pointer-size 6

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,13 @@ The following options may be given as the first argument:
579579
--min-examined-row-limit=#
580580
Don't write queries to slow log that examine fewer rows
581581
than that
582+
--mts-dynamic-rebalance
583+
Shuffle DB's within workers periodically for load
584+
balancing
585+
--mts-imbalance-threshold[=#]
586+
Threshold to trigger worker thread rebalancing. This
587+
parameter denotes the percent load on the most loaded
588+
worker.
582589
--multi-range-count=#
583590
Number of key ranges to request at once. This variable
584591
has no effect, and is deprecated. It will be removed in a
@@ -1771,6 +1778,8 @@ memlock FALSE
17711778
metadata-locks-cache-size 1024
17721779
metadata-locks-hash-instances 256
17731780
min-examined-row-limit 0
1781+
mts-dynamic-rebalance FALSE
1782+
mts-imbalance-threshold 90
17741783
multi-range-count 256
17751784
myisam-block-size 1024
17761785
myisam-data-pointer-size 6

mysql-test/r/mysqlshow.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ DROP TABLE t1, t2;
143143
| SCHEMA_PRIVILEGES |
144144
| SESSION_STATUS |
145145
| SESSION_VARIABLES |
146+
| SLAVE_DB_LOAD |
146147
| STATISTICS |
147148
| TABLES |
148149
| TABLESPACES |
@@ -223,6 +224,7 @@ DROP TABLE t1, t2;
223224
| SCHEMA_PRIVILEGES |
224225
| SESSION_STATUS |
225226
| SESSION_VARIABLES |
227+
| SLAVE_DB_LOAD |
226228
| STATISTICS |
227229
| TABLES |
228230
| TABLESPACES |

mysql-test/suite/funcs_1/r/is_columns_is.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ def information_schema SESSION_STATUS VARIABLE_NAME 1 NO varchar 64 192 NULL NU
278278
def information_schema SESSION_STATUS VARIABLE_VALUE 2 NULL YES varchar 1024 3072 NULL NULL NULL utf8 utf8_general_ci varchar(1024) select
279279
def information_schema SESSION_VARIABLES VARIABLE_NAME 1 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select
280280
def information_schema SESSION_VARIABLES VARIABLE_VALUE 2 NULL YES varchar 1024 3072 NULL NULL NULL utf8 utf8_general_ci varchar(1024) select
281+
def information_schema SLAVE_DB_LOAD DB 1 NO varchar 192 576 NULL NULL NULL utf8 utf8_general_ci varchar(192) select
282+
def information_schema SLAVE_DB_LOAD DB_LOAD 3 0 NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select
283+
def information_schema SLAVE_DB_LOAD WORKER 2 0 NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select
281284
def information_schema STATISTICS CARDINALITY 10 NULL YES bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
282285
def information_schema STATISTICS COLLATION 9 NULL YES varchar 1 3 NULL NULL NULL utf8 utf8_general_ci varchar(1) select
283286
def information_schema STATISTICS COLUMN_NAME 8 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select
@@ -874,6 +877,9 @@ NULL information_schema ROUTINES LAST_ALTERED datetime NULL NULL NULL NULL datet
874877
3.0000 information_schema SESSION_STATUS VARIABLE_VALUE varchar 1024 3072 utf8 utf8_general_ci varchar(1024)
875878
3.0000 information_schema SESSION_VARIABLES VARIABLE_NAME varchar 64 192 utf8 utf8_general_ci varchar(64)
876879
3.0000 information_schema SESSION_VARIABLES VARIABLE_VALUE varchar 1024 3072 utf8 utf8_general_ci varchar(1024)
880+
3.0000 information_schema SLAVE_DB_LOAD DB varchar 192 576 utf8 utf8_general_ci varchar(192)
881+
NULL information_schema SLAVE_DB_LOAD WORKER bigint NULL NULL NULL NULL bigint(21) unsigned
882+
NULL information_schema SLAVE_DB_LOAD DB_LOAD bigint NULL NULL NULL NULL bigint(21) unsigned
877883
3.0000 information_schema STATISTICS TABLE_CATALOG varchar 512 1536 utf8 utf8_general_ci varchar(512)
878884
3.0000 information_schema STATISTICS TABLE_SCHEMA varchar 64 192 utf8 utf8_general_ci varchar(64)
879885
3.0000 information_schema STATISTICS TABLE_NAME varchar 64 192 utf8 utf8_general_ci varchar(64)

mysql-test/suite/funcs_1/r/is_tables_is.result

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,29 @@ user_comment
636636
Separator -----------------------------------------------------
637637
TABLE_CATALOG def
638638
TABLE_SCHEMA information_schema
639+
TABLE_NAME SLAVE_DB_LOAD
640+
TABLE_TYPE SYSTEM VIEW
641+
ENGINE MEMORY
642+
VERSION 10
643+
ROW_FORMAT Fixed
644+
TABLE_ROWS #TBLR#
645+
AVG_ROW_LENGTH #ARL#
646+
DATA_LENGTH #DL#
647+
MAX_DATA_LENGTH #MDL#
648+
INDEX_LENGTH #IL#
649+
DATA_FREE #DF#
650+
AUTO_INCREMENT NULL
651+
CREATE_TIME #CRT#
652+
UPDATE_TIME #UT#
653+
CHECK_TIME #CT#
654+
TABLE_COLLATION utf8_general_ci
655+
CHECKSUM NULL
656+
CREATE_OPTIONS #CO#
657+
TABLE_COMMENT #TC#
658+
user_comment
659+
Separator -----------------------------------------------------
660+
TABLE_CATALOG def
661+
TABLE_SCHEMA information_schema
639662
TABLE_NAME STATISTICS
640663
TABLE_TYPE SYSTEM VIEW
641664
ENGINE MEMORY
@@ -1550,6 +1573,29 @@ user_comment
15501573
Separator -----------------------------------------------------
15511574
TABLE_CATALOG def
15521575
TABLE_SCHEMA information_schema
1576+
TABLE_NAME SLAVE_DB_LOAD
1577+
TABLE_TYPE SYSTEM VIEW
1578+
ENGINE MEMORY
1579+
VERSION 10
1580+
ROW_FORMAT Fixed
1581+
TABLE_ROWS #TBLR#
1582+
AVG_ROW_LENGTH #ARL#
1583+
DATA_LENGTH #DL#
1584+
MAX_DATA_LENGTH #MDL#
1585+
INDEX_LENGTH #IL#
1586+
DATA_FREE #DF#
1587+
AUTO_INCREMENT NULL
1588+
CREATE_TIME #CRT#
1589+
UPDATE_TIME #UT#
1590+
CHECK_TIME #CT#
1591+
TABLE_COLLATION utf8_general_ci
1592+
CHECKSUM NULL
1593+
CREATE_OPTIONS #CO#
1594+
TABLE_COMMENT #TC#
1595+
user_comment
1596+
Separator -----------------------------------------------------
1597+
TABLE_CATALOG def
1598+
TABLE_SCHEMA information_schema
15531599
TABLE_NAME STATISTICS
15541600
TABLE_TYPE SYSTEM VIEW
15551601
ENGINE MEMORY
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
include/rpl_restart_server.inc [server_number=2]
7+
set global mts_dynamic_rebalance=TRUE;
8+
set global slave_parallel_workers=2;
9+
set global debug="+d,skip_checkpoint_load_reset";
10+
start slave;
11+
select * from information_schema.slave_db_load;
12+
DB WORKER DB_LOAD
13+
create table t1 (a int);
14+
insert into t1 values(1);
15+
insert into t1 values(1);
16+
insert into t1 values(1);
17+
insert into t1 values(1);
18+
insert into t1 values(1);
19+
select * from information_schema.slave_db_load;
20+
DB WORKER DB_LOAD
21+
test 1 6
22+
stop slave;
23+
set global mts_dynamic_rebalance=0;
24+
set global slave_parallel_workers=0;
25+
set global debug="-d,skip_checkpoint_load_reset";
26+
start slave;
27+
drop table t1;
28+
include/rpl_end.inc
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This test verifies the functionality of slave_db_load table.
2+
3+
source include/master-slave.inc;
4+
source include/have_debug.inc;
5+
6+
let rpl_server_number=2;
7+
source include/rpl_restart_server.inc;
8+
9+
connection slave;
10+
let $old_mts_dynamic_rebalance= `select @@global.mts_dynamic_rebalance`;
11+
let $old_slave_parallel_workers= `select @@global.slave_parallel_workers`;
12+
set global mts_dynamic_rebalance=TRUE;
13+
set global slave_parallel_workers=2;
14+
set global debug="+d,skip_checkpoint_load_reset";
15+
start slave;
16+
17+
# Load should be empty
18+
select * from information_schema.slave_db_load;
19+
20+
connection master;
21+
create table t1 (a int);
22+
let $num_inserts=5;
23+
while ($num_inserts)
24+
{
25+
insert into t1 values(1);
26+
dec $num_inserts;
27+
}
28+
29+
sync_slave_with_master;
30+
31+
connection slave;
32+
# Load of test should be 6 (1 create and 5 inserts)
33+
select * from information_schema.slave_db_load;
34+
35+
# restore varaibles
36+
stop slave;
37+
eval set global mts_dynamic_rebalance=$old_mts_dynamic_rebalance;
38+
eval set global slave_parallel_workers=$old_slave_parallel_workers;
39+
set global debug="-d,skip_checkpoint_load_reset";
40+
start slave;
41+
42+
connection master;
43+
drop table t1;
44+
sync_slave_with_master;
45+
46+
source include/rpl_end.inc;

0 commit comments

Comments
 (0)