Skip to content

Commit

Permalink
Backported wsrep-recover test from 10.4.
Browse files Browse the repository at this point in the history
Backported wsrep-recover test from 10.4 to test the wsrep recovery
after database shutdown or crash. Renamed the test to wsrep-recover-v25
to avoid conflicts with existing test in 10.4 and to provide coverage
for wsrep-API v25 compatible behavior.

The test case in 10.2 is simpler because out of order prepare
step cannot happen, the commit order critical section is grabbed
before prepare phase.

Test is not recorded since it does not produce expected result.
  • Loading branch information
temeo committed Jan 25, 2019
1 parent fab531a commit ce28fa5
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
41 changes: 41 additions & 0 deletions mysql-test/suite/wsrep/t/wsrep-recover-step.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Macro to run wsrep recovery step. This is adapted from
# suite/galera/include/galera_wsrep_recover.inc, with additional
# option to pass binlog argument to recovery command. The macro
# returns recovered position split in uuid and seqno parts.
#
# Arguments:
#
# wsrep_recover_binlog_opt - Binlog options to recovery command
#
# Return:
#
# wsrep_recover_start_position_uuid - UUID corresponding to recovered position
# wsrep_recover_start_position_seqno - seqno corresponding to recovered position
#

--exec $MYSQLD --defaults-group-suffix=.1 --defaults-file=$MYSQLTEST_VARDIR/my.cnf --log-error=$MYSQL_TMP_DIR/galera_wsrep_recover.log --innodb --wsrep-recover $wsrep_recover_binlog_opt --core-file > $MYSQL_TMP_DIR/galera_wsrep_recover.log 2>&1

--perl
use strict;
my $wsrep_start_position = `grep 'WSREP: Recovered position:' $ENV{MYSQL_TMP_DIR}/galera_wsrep_recover.log | sed 's/.*WSREP\:\ Recovered\ position://' | sed 's/^[ \t]*//'`;
chomp($wsrep_start_position);
die if $wsrep_start_position eq '';
open(FILE, ">", "$ENV{MYSQL_TMP_DIR}/galera_wsrep_start_position.inc") or die;
my ($uuid, $seqno) = split /:/, $wsrep_start_position;
print FILE "--let \$wsrep_recover_start_position_uuid = $uuid\n";
print FILE "--let \$wsrep_recover_start_position_seqno = $seqno\n";
close FILE;
EOF

--source $MYSQL_TMP_DIR/galera_wsrep_start_position.inc

if ($wsrep_recover_start_position_uuid == '') {
--die "Could not obtain start_position_uuid."
}

if ($wsrep_recover_start_position_seqno == '') {
--die "Could not obtain start_position_seqno."
}

--remove_file $MYSQL_TMP_DIR/galera_wsrep_start_position.inc
7 changes: 7 additions & 0 deletions mysql-test/suite/wsrep/t/wsrep-recover-v25.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
!include ../my.cnf

[mysqld.1]
wsrep-on=ON
wsrep-cluster-address=gcomm://
wsrep-provider=@ENV.WSREP_PROVIDER
binlog-format=ROW
4 changes: 4 additions & 0 deletions mysql-test/suite/wsrep/t/wsrep-recover-v25.combinations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[binlogon]
log-bin

[binlogoff]
119 changes: 119 additions & 0 deletions mysql-test/suite/wsrep/t/wsrep-recover-v25.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#
# Verify that the wsrep XID gets updated in InnoDB rollback segment
# properly and can be recovered with --wsrep-recover
#
# The test runs the following scenarios:
#
# 1) The server is started but no SQL is run
# 2) DDL is executed
# 3) INSERT is executed
# 4) Two INSERTs are executed so that the first one in order will be
# blocked after certification and the second one before entering
# commit order critical section.
# 5) Two DMLs are executed so that the prepare step is run out of order.
# Both transactions are blocked before commit order critical section.
#
# After each scenario server is killed and the recovered position
# is validated.
#

--source include/have_wsrep.inc
--source include/have_innodb.inc
--source include/have_wsrep_provider.inc
--source include/have_debug_sync.inc

#
# Binlog option for recovery run. This must be set in the test because
# combinations file causes log-bin option to be set from command line,
# not via my.cnf.
#
--let $log_bin = `SELECT @@log_bin`
if ($log_bin) {
--let $wsrep_recover_binlog_opt = --log-bin
}

#
# Scenario 1
# The expected recovered seqno is 1 corresponding to initial cluster
# configuration change.
#
--source include/kill_mysqld.inc
--source wsrep-recover-step.inc
--echo Expect seqno 0
--echo $wsrep_recover_start_position_seqno

--let $restart_parameters = --wsrep-start-position=$wsrep_recover_start_position_uuid:$wsrep_recover_start_position_seqno
--source include/start_mysqld.inc
--source include/wait_wsrep_ready.inc

#
# Senario 2
# The expected recovered seqno is 1 corresponding to CREATE TABLE
#

CREATE TABLE t1 (f1 INT PRIMARY KEY) ENGINE=InnoDB;
--source include/kill_mysqld.inc
--source wsrep-recover-step.inc
--echo Expect seqno 1
--echo $wsrep_recover_start_position_seqno

--let $restart_parameters = --wsrep-start-position=$wsrep_recover_start_position_uuid:$wsrep_recover_start_position_seqno
--source include/start_mysqld.inc
--source include/wait_wsrep_ready.inc

#
# Scenario 3
# The expected recovered seqno is 2 corresponding to CREATE TABLE and INSERT.
#
# The expected wsrep_last_committed after the server is restarted is 2.
#

INSERT INTO t1 VALUES (5);
--source include/kill_mysqld.inc
--source wsrep-recover-step.inc
--echo Expect seqno 2
--echo $wsrep_recover_start_position_seqno
--let $restart_parameters = --wsrep-start-position=$wsrep_recover_start_position_uuid:$wsrep_recover_start_position_seqno
--source include/start_mysqld.inc
--source include/wait_wsrep_ready.inc

SELECT VARIABLE_VALUE `expect 2` FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_last_committed';

#
# Scenario 4
#
# The INSERT gets prepared but not committed.
#
# If binlog is off, the expected outcome is that the INSERT gets committed
# since it is already committed in the cluster. If binlog is on, the INSERT
# should be rolled back during recovery phase since it has not yet
# been logged into binlog.
#
--connect con1, localhost, root
SET DEBUG_SYNC = "ha_commit_trans_after_prepare SIGNAL after_prepare_reached WAIT_FOR continue";
--send INSERT INTO t1 VALUES (7)

--connection default
SET DEBUG_SYNC = "now WAIT_FOR after_prepare_reached";
--source include/kill_mysqld.inc
--source wsrep-recover-step.inc
if ($log_bin) {
--echo Expect seqno 2
}
if (!$log_bin) {
--echo Expect seqno 3
}
--echo $wsrep_recover_start_position_seqno
--let $restart_parameters = --wsrep-start-position=$wsrep_recover_start_position_uuid:$wsrep_recover_start_position_seqno
--source include/start_mysqld.inc
--source include/wait_wsrep_ready.inc

if ($log_bin) {
--echo Expect 5
}
if (!$log_bin) {
--echo Expect 5 7
}
SELECT * FROM t1;

DROP TABLE t1;

0 comments on commit ce28fa5

Please sign in to comment.