-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to shutdown master if semi-sync is being switched off while th…
…ere are active un-acked trxns Summary: Semi-sync master can be switched off manually or because of a timeout while waiting for an ack. This change introduces a new variable rpl_semi_sync_master_crash_if_active_trxs which when set to true will cause the master to shutdown (after printing an error msg) if semi-sync is being switched off while there are active un-acked transactions. This prevents any un-acked trx from committing on the master. Reviewed By: hermanlee Differential Revision: D5841339 fbshipit-source-id: c378441
- Loading branch information
1 parent
3e4b33b
commit 2d47615
Showing
9 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
mysql-test/suite/rpl/r/rpl_semi_sync_master_crash_if_active_trxs.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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] | ||
call mtr.add_suppression("Timeout waiting for reply of binlog*"); | ||
call mtr.add_suppression("Force shutdown: Semi-sync master is being switched off while there are active un-acked transactions"); | ||
create table t1(a int) engine=innodb; | ||
include/stop_slave.inc | ||
SET GLOBAL DEBUG='+d,dont_send_semi_sync_reply'; | ||
include/start_slave.inc | ||
insert into t1 values(1); | ||
ERROR HY000: Lost connection to MySQL server during query | ||
SET GLOBAL DEBUG='-d,dont_send_semi_sync_reply'; | ||
# Restart the master server | ||
include/rpl_start_server.inc [server_number=1] | ||
include/stop_slave.inc | ||
SET GLOBAL DEBUG='+d,dont_send_semi_sync_reply'; | ||
include/start_slave.inc | ||
set @@global.rpl_semi_sync_master_timeout= 1000000; | ||
insert into t1 values(2); | ||
set @@global.rpl_semi_sync_master_enabled= OFF; | ||
ERROR HY000: Lost connection to MySQL server during query | ||
ERROR HY000: Lost connection to MySQL server during query | ||
SET GLOBAL DEBUG='-d,dont_send_semi_sync_reply'; | ||
# Restart the master server | ||
include/rpl_start_server.inc [server_number=1] | ||
"Table at the master" | ||
select * from t1; | ||
a | ||
1 | ||
2 | ||
"Table at the slave" | ||
select * from t1; | ||
a | ||
1 | ||
2 | ||
set @@global.rpl_semi_sync_master_enabled= OFF; | ||
set @@global.rpl_semi_sync_master_enabled= ON; | ||
drop table t1; | ||
include/rpl_end.inc |
7 changes: 7 additions & 0 deletions
7
mysql-test/suite/rpl/t/rpl_semi_sync_master_crash_if_active_trxs.cnf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
!include ../my.cnf | ||
[mysqld.1] | ||
rpl_semi_sync_master_enabled=1 | ||
rpl_semi_sync_master_timeout=1000 # 1 second | ||
rpl_semi_sync_master_crash_if_active_trxs=1 | ||
[mysqld.2] | ||
rpl_semi_sync_slave_enabled=1 |
115 changes: 115 additions & 0 deletions
115
mysql-test/suite/rpl/t/rpl_semi_sync_master_crash_if_active_trxs.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
source include/master-slave.inc; | ||
source include/have_debug.inc; | ||
|
||
|
||
call mtr.add_suppression("Timeout waiting for reply of binlog*"); | ||
call mtr.add_suppression("Force shutdown: Semi-sync master is being switched off while there are active un-acked transactions"); | ||
|
||
connection master; | ||
create table t1(a int) engine=innodb; | ||
sync_slave_with_master; | ||
|
||
# Disable ack on slave | ||
connection slave; | ||
source include/stop_slave.inc; | ||
SET GLOBAL DEBUG='+d,dont_send_semi_sync_reply'; | ||
source include/start_slave.inc; | ||
|
||
## | ||
## Ack timeout when there are active un-acked trxs should shutdown the master | ||
## | ||
connection master; | ||
enable_reconnect; | ||
exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; | ||
# The master will die while executing this stmt because slave will not ack it | ||
error 2013; | ||
insert into t1 values(1); | ||
|
||
# Wait for master to die | ||
source include/wait_until_disconnected.inc; | ||
|
||
# Resume normal slave operations i.e start acking | ||
connection slave; | ||
SET GLOBAL DEBUG='-d,dont_send_semi_sync_reply'; | ||
|
||
# Restart master | ||
echo # Restart the master server; | ||
let $rpl_server_number= 1; | ||
source include/rpl_start_server.inc; | ||
disable_reconnect; | ||
|
||
connection master; | ||
sync_slave_with_master; | ||
|
||
## | ||
## Turning off semi-sync when there are active un-acked trxs should shutdown the | ||
## master | ||
## | ||
|
||
# Disable ack on the slave | ||
connection slave; | ||
source include/stop_slave.inc; | ||
SET GLOBAL DEBUG='+d,dont_send_semi_sync_reply'; | ||
source include/start_slave.inc; | ||
|
||
connection master; | ||
# Set timeout to a large value so that we have a chance to switch semi-sync off | ||
# manually | ||
set @@global.rpl_semi_sync_master_timeout= 1000000; | ||
send insert into t1 values(2); # this stmt will hang | ||
|
||
# Wait till the insert is processed on the slave | ||
connection slave; | ||
let $wait_condition= SELECT count(*) = 1 from t1 where a = 2; | ||
source include/wait_condition.inc; | ||
|
||
connection master1; | ||
enable_reconnect; | ||
exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; | ||
error 2013; | ||
set @@global.rpl_semi_sync_master_enabled= OFF; # master will shutdown | ||
|
||
# Wait for master to die | ||
source include/wait_until_disconnected.inc; | ||
|
||
connection master; | ||
error 2013; | ||
reap; | ||
|
||
# Resume normal slave operations i.e start acking | ||
connection slave; | ||
SET GLOBAL DEBUG='-d,dont_send_semi_sync_reply'; | ||
|
||
# Restart master | ||
echo # Restart the master server; | ||
let $rpl_server_number= 1; | ||
source include/rpl_start_server.inc; | ||
disable_reconnect; | ||
|
||
connection master; | ||
sync_slave_with_master; | ||
|
||
# Will contain 2 rows because master recovery rolls trxs forward | ||
echo "Table at the master"; | ||
connection master; | ||
select * from t1; | ||
|
||
# Will contain 2 rows because slaves received all trxs | ||
echo "Table at the slave"; | ||
connection slave; | ||
select * from t1; | ||
|
||
## | ||
## Turning off semi-sync when there are no active un-acked trxs should succeed | ||
## | ||
connection master; | ||
set @@global.rpl_semi_sync_master_enabled= OFF; # should not fail | ||
set @@global.rpl_semi_sync_master_enabled= ON; | ||
|
||
# Cleanup | ||
connection master; | ||
drop table t1; | ||
sync_slave_with_master; | ||
|
||
|
||
source include/rpl_end.inc; |
21 changes: 21 additions & 0 deletions
21
mysql-test/suite/sys_vars/r/rpl_semi_sync_master_crash_if_active_trxs_basic.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
set @save.rpl_semi_sync_master_crash_if_active_trxs= @@global.rpl_semi_sync_master_crash_if_active_trxs; | ||
select @@session.rpl_semi_sync_master_crash_if_active_trxs; | ||
ERROR HY000: Variable 'rpl_semi_sync_master_crash_if_active_trxs' is a GLOBAL variable | ||
select variable_name from information_schema.global_variables where variable_name='$var'; | ||
variable_name | ||
select variable_name from information_schema.session_variables where variable_name='$var'; | ||
variable_name | ||
set @@global.rpl_semi_sync_master_crash_if_active_trxs= false; | ||
select @@global.rpl_semi_sync_master_crash_if_active_trxs; | ||
@@global.rpl_semi_sync_master_crash_if_active_trxs | ||
0 | ||
set @@global.rpl_semi_sync_master_crash_if_active_trxs= 1.1; | ||
ERROR 42000: Incorrect argument type to variable 'rpl_semi_sync_master_crash_if_active_trxs' | ||
set @@global.rpl_semi_sync_master_crash_if_active_trxs= "foo"; | ||
ERROR 42000: Variable 'rpl_semi_sync_master_crash_if_active_trxs' can't be set to the value of 'foo' | ||
set @@global.rpl_semi_sync_master_crash_if_active_trxs= false; | ||
set @@global.rpl_semi_sync_master_crash_if_active_trxs= true; | ||
select @@global.rpl_semi_sync_master_crash_if_active_trxs as "truncated to the maximum"; | ||
truncated to the maximum | ||
1 | ||
set @@global.rpl_semi_sync_master_crash_if_active_trxs= @save.rpl_semi_sync_master_crash_if_active_trxs; |
38 changes: 38 additions & 0 deletions
38
mysql-test/suite/sys_vars/t/rpl_semi_sync_master_crash_if_active_trxs_basic.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--source include/not_embedded.inc | ||
|
||
let $var= rpl_semi_sync_master_crash_if_active_trxs; | ||
eval set @save.$var= @@global.$var; | ||
|
||
# | ||
# exists as global only | ||
# | ||
--error ER_INCORRECT_GLOBAL_LOCAL_VAR | ||
eval select @@session.$var; | ||
|
||
select variable_name from information_schema.global_variables where variable_name='$var'; | ||
select variable_name from information_schema.session_variables where variable_name='$var'; | ||
|
||
# | ||
# show that it's writable | ||
# | ||
let $value= false; | ||
eval set @@global.$var= $value; | ||
eval select @@global.$var; | ||
|
||
# | ||
# incorrect value | ||
# | ||
--error ER_WRONG_TYPE_FOR_VAR | ||
eval set @@global.$var= 1.1; | ||
--error ER_WRONG_VALUE_FOR_VAR | ||
eval set @@global.$var= "foo"; | ||
|
||
# | ||
# min/max values | ||
# | ||
eval set @@global.$var= false; | ||
eval set @@global.$var= true; | ||
eval select @@global.$var as "truncated to the maximum"; | ||
|
||
# cleanup | ||
eval set @@global.$var= @save.$var; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters