Skip to content

Commit

Permalink
Adding option to enable global commit ordering on secondaries
Browse files Browse the repository at this point in the history
Summary:
Extending the variable mts_dependency_order_commits to allow
three values NONE, DB and GLOBAL. When the variabale it set to GLOBAL we
order commits even across databases.

Reviewed By: bhatvinay

Differential Revision: D23366447

fbshipit-source-id: dad1c58e504
  • Loading branch information
abhinav04sharma authored and facebook-github-bot committed Oct 6, 2020
1 parent 86919ca commit 79e3b75
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 22 deletions.
11 changes: 5 additions & 6 deletions mysql-test/r/mysqld--help-notwin-profiling.result
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,9 @@ The following options may be given as the first argument:
Max number of keys in a transaction after which it will
be executed in isolation. This limits the amount of
metadata we'll need to maintain.
--mts-dependency-order-commits
Commit trxs in the same order as the master (per
database)
(Defaults to on; use --skip-mts-dependency-order-commits to disable.)
--mts-dependency-order-commits[=name]
Commit trxs in the same order as the master (per database
or globally)
--mts-dependency-refill-threshold[=#]
Capacity in percentage at which to start refilling the
dependency buffer
Expand Down Expand Up @@ -2523,7 +2522,7 @@ min-examined-row-limit 0
minimum-hlc-ns 0
mts-dependency-cond-wait-timeout 5000
mts-dependency-max-keys 100000
mts-dependency-order-commits TRUE
mts-dependency-order-commits DB
mts-dependency-refill-threshold 60
mts-dependency-replication NONE
mts-dependency-size 1000
Expand Down Expand Up @@ -2606,7 +2605,7 @@ performance-schema-max-rwlock-instances -1
performance-schema-max-socket-classes 10
performance-schema-max-socket-instances -1
performance-schema-max-stage-classes 150
performance-schema-max-statement-classes 188
performance-schema-max-statement-classes 191
performance-schema-max-table-handles -1
performance-schema-max-table-instances -1
performance-schema-max-thread-classes 50
Expand Down
11 changes: 5 additions & 6 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,9 @@ The following options may be given as the first argument:
Max number of keys in a transaction after which it will
be executed in isolation. This limits the amount of
metadata we'll need to maintain.
--mts-dependency-order-commits
Commit trxs in the same order as the master (per
database)
(Defaults to on; use --skip-mts-dependency-order-commits to disable.)
--mts-dependency-order-commits[=name]
Commit trxs in the same order as the master (per database
or globally)
--mts-dependency-refill-threshold[=#]
Capacity in percentage at which to start refilling the
dependency buffer
Expand Down Expand Up @@ -2521,7 +2520,7 @@ min-examined-row-limit 0
minimum-hlc-ns 0
mts-dependency-cond-wait-timeout 5000
mts-dependency-max-keys 100000
mts-dependency-order-commits TRUE
mts-dependency-order-commits DB
mts-dependency-refill-threshold 60
mts-dependency-replication NONE
mts-dependency-size 1000
Expand Down Expand Up @@ -2604,7 +2603,7 @@ performance-schema-max-rwlock-instances -1
performance-schema-max-socket-classes 10
performance-schema-max-socket-instances -1
performance-schema-max-stage-classes 150
performance-schema-max-statement-classes 188
performance-schema-max-statement-classes 191
performance-schema-max-table-handles -1
performance-schema-max-table-instances -1
performance-schema-max-thread-classes 50
Expand Down
41 changes: 41 additions & 0 deletions mysql-test/suite/rpl_mts/r/rpl_mts_dependency_order_commits.result
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ stop slave;
set @save.slave_parallel_workers= @@global.slave_parallel_workers;
set @@global.slave_parallel_workers= 8;
start slave;
select @@global.mts_dependency_order_commits;
@@global.mts_dependency_order_commits
DB
set @save.mts_dependency_order_commits= @@global.mts_dependency_order_commits;
create database d1;
create database d2;
create table d1.t1(a int primary key) engine=innodb;
Expand Down Expand Up @@ -46,7 +50,44 @@ select * from d2.t1;
a
1
10
stop slave;
set @@global.mts_dependency_order_commits = GLOBAL;
start slave;
delete from d1.t1;
delete from d1.t2;
delete from d2.t1;
insert into d1.t1 values(1);
begin;
update d1.t1 set a = 2 where a = 1;
update d1.t1 set a = 3 where a = 1;
insert into d2.t1 values(1);
begin;
insert into d1.t1 values(10);
insert into d2.t1 values(10);
commit;
"d1.t1 should contain a single row with value 1"
select * from d1.t1;
a
1
"d2.t1 should also be empty"
select * from d2.t1;
a
rollback;
"Final states"
select * from d1.t1;
a
3
10
select * from d1.t2;
a
select * from d2.t1;
a
1
10
stop slave;
set @@global.slave_parallel_workers= @save.slave_parallel_workers;
set @@global.mts_dependency_order_commits= @save.mts_dependency_order_commits;
start slave;
drop database d1;
drop database d2;
include/rpl_end.inc
65 changes: 64 additions & 1 deletion mysql-test/suite/rpl_mts/t/rpl_mts_dependency_order_commits.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Tests if mts_dependency_order_commits= TRUE master's commit order is honored
# on the slave (per database)
# on the slave

source include/have_innodb.inc;
source include/have_mts_dependency_replication.inc;
Expand All @@ -11,6 +11,10 @@ set @save.slave_parallel_workers= @@global.slave_parallel_workers;
set @@global.slave_parallel_workers= 8;
start slave;

# Case 1: Per DB commit ordering (default behavior)
select @@global.mts_dependency_order_commits;
set @save.mts_dependency_order_commits= @@global.mts_dependency_order_commits;

connection master;
create database d1;
create database d2;
Expand Down Expand Up @@ -70,8 +74,67 @@ select * from d1.t1;
select * from d1.t2;
select * from d2.t1;


# Case 2: Global commit ordering
connection slave;
stop slave;
set @@global.mts_dependency_order_commits = GLOBAL;
start slave;
connection master;
delete from d1.t1;
delete from d1.t2;
delete from d2.t1;
insert into d1.t1 values(1);
sync_slave_with_master;

connection slave;
# create a blocking trx on the slave
begin;
update d1.t1 set a = 2 where a = 1;

connection master;
update d1.t1 set a = 3 where a = 1; # this will be blocked due to engine lock
insert into d2.t1 values(1); # this will be blocked because we're ordering globally
begin;
insert into d1.t1 values(10);
insert into d2.t1 values(10);
commit; # this will wait for all workers to finish (to execute in isolation)


connection slave1;
# Wait for 2nd trx above to block on commit order
let $wait_condition= SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE STATE LIKE "%Waiting for preceding transaction to commit%";
let $wait_timeout= 120;
source include/wait_condition.inc;

# Wait for 3rd trx to wait for workers to finish
let $wait_condition= SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE STATE LIKE "%Waiting for dependency workers to finish%";
let $wait_timeout= 120;
source include/wait_condition.inc;

echo "d1.t1 should contain a single row with value 1";
select * from d1.t1;
echo "d2.t1 should also be empty";
select * from d2.t1;

connection slave;
rollback; # rollback the conflicting trx

connection master;
sync_slave_with_master;
echo "Final states";
select * from d1.t1;
select * from d1.t2;
select * from d2.t1;

# cleanup
connection slave;
stop slave;
set @@global.slave_parallel_workers= @save.slave_parallel_workers;
set @@global.mts_dependency_order_commits= @save.mts_dependency_order_commits;
start slave;
connection master;
drop database d1;
drop database d2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ variable_name
set @@global.mts_dependency_order_commits= false;
select @@global.mts_dependency_order_commits;
@@global.mts_dependency_order_commits
0
NONE
set @@global.mts_dependency_order_commits= 1.1;
ERROR 42000: Incorrect argument type to variable 'mts_dependency_order_commits'
set @@global.mts_dependency_order_commits= "foo";
Expand All @@ -17,5 +17,5 @@ set @@global.mts_dependency_order_commits= false;
set @@global.mts_dependency_order_commits= true;
select @@global.mts_dependency_order_commits as "truncated to the maximum";
truncated to the maximum
1
DB
set @@global.mts_dependency_order_commits= @save.mts_dependency_order_commits;
4 changes: 3 additions & 1 deletion sql/dependency_slave_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ Dependency_slave_worker::get_begin_event(Commit_order_manager *co_mngr)
if (ret && co_mngr != NULL)
{
DBUG_ASSERT(c_rli->mts_dependency_order_commits);
set_current_db(ret->get_db());
// case: if we need to order commits by DB we set current DB
if (c_rli->mts_dependency_order_commits == DEP_RPL_ORDER_DB)
set_current_db(ret->get_db());
co_mngr->register_trx(this);
}

Expand Down
2 changes: 1 addition & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ ulong opt_mts_dependency_replication;
ulonglong opt_mts_dependency_size;
double opt_mts_dependency_refill_threshold;
ulonglong opt_mts_dependency_max_keys;
my_bool opt_mts_dependency_order_commits;
ulong opt_mts_dependency_order_commits;
ulonglong opt_mts_dependency_cond_wait_timeout;
my_bool opt_mts_dynamic_rebalance;
double opt_mts_imbalance_threshold;
Expand Down
2 changes: 1 addition & 1 deletion sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ extern ulong opt_mts_dependency_replication;
extern ulonglong opt_mts_dependency_size;
extern double opt_mts_dependency_refill_threshold;
extern ulonglong opt_mts_dependency_max_keys;
extern my_bool opt_mts_dependency_order_commits;
extern ulong opt_mts_dependency_order_commits;
extern ulonglong opt_mts_dependency_cond_wait_timeout;
extern my_bool opt_mts_dynamic_rebalance;
extern double opt_mts_imbalance_threshold;
Expand Down
2 changes: 1 addition & 1 deletion sql/rpl_rli.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ class Relay_log_info : public Rpl_info
ulonglong mts_dependency_size= 0;
double mts_dependency_refill_threshold= 0;
ulonglong mts_dependency_max_keys= 0;
my_bool mts_dependency_order_commits= TRUE;
ulong mts_dependency_order_commits= 0;
ulonglong mts_dependency_cond_wait_timeout= 0;

std::deque<std::shared_ptr<Log_event_wrapper>> dep_queue;
Expand Down
6 changes: 6 additions & 0 deletions sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ enum enum_mts_dependency_replication {
DEP_RPL_STATEMENT,
};

enum enum_mts_dependency_order_commits {
DEP_RPL_ORDER_NONE,
DEP_RPL_ORDER_DB,
DEP_RPL_ORDER_GLOBAL,
};

enum enum_slave_use_idempotent_for_recovery {
SLAVE_USE_IDEMPOTENT_FOR_RECOVERY_NO,
SLAVE_USE_IDEMPOTENT_FOR_RECOVERY_YES};
Expand Down
7 changes: 4 additions & 3 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5543,6 +5543,7 @@ static Sys_var_double Sys_mts_imbalance_threshold(
CMD_LINE(OPT_ARG), VALID_RANGE(0, 100), DEFAULT(90));

static const char *dep_rpl_type_names[]= { "NONE", "TBL", "STMT", NullS };
static const char *commit_order_type_names[]= { "NONE", "DB", "GLOBAL", NullS };

static Sys_var_enum Sys_mts_dependency_replication(
"mts_dependency_replication",
Expand Down Expand Up @@ -5572,11 +5573,11 @@ static Sys_var_ulonglong Sys_mts_dependency_max_keys(
GLOBAL_VAR(opt_mts_dependency_max_keys), CMD_LINE(OPT_ARG),
VALID_RANGE(0, ULONGLONG_MAX), DEFAULT(100000), BLOCK_SIZE(1));

static Sys_var_mybool Sys_mts_dependency_order_commits(
static Sys_var_enum Sys_mts_dependency_order_commits(
"mts_dependency_order_commits",
"Commit trxs in the same order as the master (per database)",
"Commit trxs in the same order as the master (per database or globally)",
GLOBAL_VAR(opt_mts_dependency_order_commits),
CMD_LINE(OPT_ARG), DEFAULT(TRUE));
CMD_LINE(OPT_ARG), commit_order_type_names, DEFAULT(DEP_RPL_ORDER_DB));

static Sys_var_ulonglong Sys_mts_dependency_cond_wait_timeout(
"mts_dependency_cond_wait_timeout",
Expand Down

0 comments on commit 79e3b75

Please sign in to comment.